Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Modeling/3.2/AnalyzerModel.cs @ 2396

Last change on this file since 2396 was 2371, checked in by mkommend, 15 years ago

added code for persisting of ModelType into the database (ticket #756)

File size: 4.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Text;
25using HeuristicLab.Core;
26using HeuristicLab.DataAnalysis;
27using HeuristicLab.Data;
28
29namespace HeuristicLab.Modeling {
30  public class AnalyzerModel : IAnalyzerModel {
31    public AnalyzerModel() { } // for persistence
32
33    #region IAnalyzerModel Members
34
35    private Dataset dataset;
36    public Dataset Dataset {
37      get { return dataset; }
38      set { dataset = value; }
39    }
40
41    private string targetVariable;
42    public string TargetVariable {
43      get { return targetVariable; }
44      set { targetVariable = value; }
45    }
46
47    public ModelType Type { get; set; }
48
49    private List<string> inputVariables = new List<string>();
50    public IEnumerable<string> InputVariables {
51      get { return inputVariables; }
52    }
53
54    public int TrainingSamplesStart { get; set; }
55    public int TrainingSamplesEnd { get; set; }
56    public int ValidationSamplesStart { get; set; }
57    public int ValidationSamplesEnd { get; set; }
58    public int TestSamplesStart { get; set; }
59    public int TestSamplesEnd { get; set; }
60
61    public void AddInputVariable(string variableName) {
62      if (!inputVariables.Contains(variableName))
63        inputVariables.Add(variableName);
64    }
65
66    private Dictionary<ModelingResult, double> results = new Dictionary<ModelingResult, double>();
67    public IEnumerable<KeyValuePair<ModelingResult, double>> Results {
68      get { return results; }
69    }
70
71    public void ExtractResult(IScope scope, ModelingResult result) {
72      SetResult(result, scope.GetVariableValue<DoubleData>(result.ToString(), false).Data);
73    }
74
75
76    public void SetResult(ModelingResult result, double value) {
77      results.Add(result, value);
78    }
79
80    public double GetResult(ModelingResult result) {
81      return results[result];
82    }
83
84    private Dictionary<string, double> metadata = new Dictionary<string, double>();
85    public IEnumerable<KeyValuePair<string, double>> MetaData {
86      get { return metadata; }
87    }
88
89    public void SetMetaData(string name, double value) {
90      metadata.Add(name, value);
91    }
92
93    public double GetMetaData(string name) {
94      return metadata[name];
95    }
96
97    private Dictionary<string, Dictionary<ModelingResult, double>> variableResults = new Dictionary<string, Dictionary<ModelingResult, double>>();
98    public double GetVariableResult(ModelingResult result, string variableName) {
99      if (variableResults.ContainsKey(variableName)) {
100        if (variableResults[variableName].ContainsKey(result)) {
101          return variableResults[variableName][result];
102        } else throw new ArgumentException("No value for modeling result: " + result + ".");
103      } else throw new ArgumentException("No variable result for variable " + variableName + ".");
104    }
105
106    public void SetVariableResult(ModelingResult result, string variableName, double value) {
107      if (!variableResults.ContainsKey(variableName)) {
108        variableResults.Add(variableName, new Dictionary<ModelingResult, double>());
109      }
110      variableResults[variableName][result] = value;
111    }
112
113    public IEnumerable<KeyValuePair<ModelingResult, double>> GetVariableResults(string variableName) {
114      return variableResults[variableName];
115    }
116
117    public IPredictor Predictor { get; set; }
118
119    #endregion
120
121  }
122}
Note: See TracBrowser for help on using the repository browser.