[2285] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Text;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.DataAnalysis;
|
---|
[2370] | 27 | using HeuristicLab.Data;
|
---|
[2285] | 28 |
|
---|
| 29 | namespace HeuristicLab.Modeling {
|
---|
| 30 | public class AnalyzerModel : IAnalyzerModel {
|
---|
| 31 | public AnalyzerModel() { } // for persistence
|
---|
| 32 |
|
---|
[2371] | 33 | #region IAnalyzerModel Members
|
---|
[2285] | 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 |
|
---|
[2369] | 47 | public ModelType Type { get; set; }
|
---|
| 48 |
|
---|
[2285] | 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 |
|
---|
[2370] | 66 | private Dictionary<ModelingResult, double> results = new Dictionary<ModelingResult, double>();
|
---|
| 67 | public IEnumerable<KeyValuePair<ModelingResult, double>> Results {
|
---|
[2344] | 68 | get { return results; }
|
---|
[2285] | 69 | }
|
---|
| 70 |
|
---|
[2370] | 71 | public void ExtractResult(IScope scope, ModelingResult result) {
|
---|
| 72 | SetResult(result, scope.GetVariableValue<DoubleData>(result.ToString(), false).Data);
|
---|
[2285] | 73 | }
|
---|
| 74 |
|
---|
[2370] | 75 |
|
---|
| 76 | public void SetResult(ModelingResult result, double value) {
|
---|
| 77 | results.Add(result, value);
|
---|
[2285] | 78 | }
|
---|
| 79 |
|
---|
[2370] | 80 | public double GetResult(ModelingResult result) {
|
---|
| 81 | return results[result];
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[2355] | 84 | private Dictionary<string, double> metadata = new Dictionary<string, double>();
|
---|
| 85 | public IEnumerable<KeyValuePair<string, double>> MetaData {
|
---|
[2344] | 86 | get { return metadata; }
|
---|
[2285] | 87 | }
|
---|
| 88 |
|
---|
[2355] | 89 | public void SetMetaData(string name, double value) {
|
---|
[2344] | 90 | metadata.Add(name, value);
|
---|
[2285] | 91 | }
|
---|
| 92 |
|
---|
[2355] | 93 | public double GetMetaData(string name) {
|
---|
[2344] | 94 | return metadata[name];
|
---|
[2285] | 95 | }
|
---|
| 96 |
|
---|
[2370] | 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 + ".");
|
---|
[2285] | 104 | }
|
---|
| 105 |
|
---|
[2370] | 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;
|
---|
[2285] | 111 | }
|
---|
| 112 |
|
---|
[2370] | 113 | public IEnumerable<KeyValuePair<ModelingResult, double>> GetVariableResults(string variableName) {
|
---|
[2421] | 114 | if (variableResults.ContainsKey(variableName))
|
---|
| 115 | return variableResults[variableName];
|
---|
| 116 | else return new KeyValuePair<ModelingResult, double>[] { };
|
---|
[2370] | 117 | }
|
---|
| 118 |
|
---|
[2285] | 119 | public IPredictor Predictor { get; set; }
|
---|
| 120 |
|
---|
| 121 | #endregion
|
---|
| 122 |
|
---|
| 123 | }
|
---|
| 124 | }
|
---|