Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/PredictorPersister.cs @ 2482

Last change on this file since 2482 was 2482, checked in by mkommend, 14 years ago

added predictor persistor (ticket #800)

File size: 2.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7using HeuristicLab.DataAnalysis;
8
9namespace 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}
Note: See TracBrowser for help on using the repository browser.