1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Data;
|
---|
7 | using HeuristicLab.DataAnalysis;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Modeling.Database.SQLServerCompact {
|
---|
10 | public class PredictorPersister : OperatorBase {
|
---|
11 |
|
---|
12 | public PredictorPersister()
|
---|
13 | : base() {
|
---|
14 | AddVariableInfo(new VariableInfo("DatabaseFile", "Database file", typeof(StringData), VariableKind.In));
|
---|
15 | AddVariableInfo(new VariableInfo("ModelType", "The ModelType", typeof(StringData), VariableKind.In));
|
---|
16 | AddVariableInfo(new VariableInfo("Dataset", "The input dataset", typeof(Dataset), VariableKind.In));
|
---|
17 | AddVariableInfo(new VariableInfo("AlgorithmName", "", typeof(StringData), VariableKind.In));
|
---|
18 | }
|
---|
19 |
|
---|
20 | public override string Description {
|
---|
21 | get { return "Saves a predictor to a given database"; }
|
---|
22 | }
|
---|
23 |
|
---|
24 | public override IOperation Apply(IScope scope) {
|
---|
25 | string database = GetVariableValue<StringData>("DatabaseFile", scope, true).Data;
|
---|
26 | Dataset ds = GetVariableValue<Dataset>("Dataset", scope, true);
|
---|
27 | string mt = GetVariableValue<StringData>("ModelType",scope,true).Data;
|
---|
28 | string algorithm = GetVariableValue<StringData>("AlgorithmName",scope,true).Data;
|
---|
29 |
|
---|
30 | ModelType modelType = ModelType.Regression;
|
---|
31 | if (Enum.IsDefined(typeof(ModelType), mt))
|
---|
32 | modelType = (ModelType)Enum.Parse(typeof(ModelType), mt);
|
---|
33 | else
|
---|
34 | throw new ArgumentException("Passed model type " + mt + " is not defined.\n Possible Values are: " +
|
---|
35 | string.Join(",",Enum.GetNames(typeof(ModelType))));
|
---|
36 |
|
---|
37 | DatabaseService db = new DatabaseService(database);
|
---|
38 | db.Connect();
|
---|
39 | if (db.GetDataset() == null)
|
---|
40 | db.PersistProblem(ds);
|
---|
41 |
|
---|
42 | IAnalyzerModel model = new AnalyzerModel();
|
---|
43 | DefaultModelAnalyzerOperators.PopulateAnalyzerModel(scope, model, modelType);
|
---|
44 |
|
---|
45 | db.Persist(model, algorithm, algorithm);
|
---|
46 | db.Disconnect();
|
---|
47 |
|
---|
48 | return null;
|
---|
49 | }
|
---|
50 | }
|
---|
51 | }
|
---|