Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Classification/3.3/Symbolic/Analyzer/TrainingBestSymbolicClassificationSolutionAnalyzer.cs @ 5273

Last change on this file since 5273 was 5273, checked in by gkronber, 13 years ago

Added calculation of R², MSE and rel. Error for training best classification solution. Fixed calculation of accuracy. Fixed namespace and name of TrainingBestSymbolicClassificationSolutionAnalyzer. #1369

File size: 25.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Analysis;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
29using HeuristicLab.Operators;
30using HeuristicLab.Optimization;
31using HeuristicLab.Parameters;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
33using HeuristicLab.Problems.DataAnalysis.Symbolic;
34using HeuristicLab.Problems.DataAnalysis.Evaluators;
35using HeuristicLab.Problems.DataAnalysis.Classification;
36using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic;
37using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers;
38
39namespace HeuristicLab.Problems.DataAnalysis.Classification.Symbolic.Analyzers {
40  /// <summary>
41  /// An operator that analyzes the training best scaled symbolic classification solution.
42  /// </summary>
43  [Item("TrainingBestSymbolicClassificationSolutionAnalyzer", "An operator that analyzes the training best scaled symbolic classification solution.")]
44  [StorableClass]
45  public sealed class TrainingBestSymbolicClassificationSolutionAnalyzer : SingleSuccessorOperator, ISymbolicClassificationAnalyzer {
46    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
47    private const string QualityParameterName = "Quality";
48    private const string MaximizationParameterName = "Maximization";
49    private const string CalculateSolutionComplexityParameterName = "CalculateSolutionComplexity";
50    private const string CalculateSolutionAccuracyParameterName = "CalculateSolutionAccuracy";
51    private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
52    private const string ProblemDataParameterName = "ClassificationProblemData";
53    private const string UpperEstimationLimitParameterName = "UpperEstimationLimit";
54    private const string LowerEstimationLimitParameterName = "LowerEstimationLimit";
55    private const string BestSolutionParameterName = "Best training solution";
56    private const string BestSolutionQualityParameterName = "Best training solution quality";
57    private const string BestSolutionLengthParameterName = "Best training solution length";
58    private const string BestSolutionHeightParameterName = "Best training solution height";
59    private const string BestSolutionVariablesParameterName = "Best training solution variables";
60    private const string BestSolutionTrainingRSquaredParameterName = "Best training solution R² (training)";
61    private const string BestSolutionTestRSquaredParameterName = "Best training solution R² (test)";
62    private const string BestSolutionTrainingMseParameterName = "Best training solution mean squared error (training)";
63    private const string BestSolutionTestMseParameterName = "Best training solution mean squared error (test)";
64    private const string BestSolutionTrainingRelativeErrorParameterName = "Best training solution relative error (training)";
65    private const string BestSolutionTestRelativeErrorParameterName = "Best training solution relative error (test)";
66    private const string BestSolutionAccuracyTrainingParameterName = "Best training solution accuracy (training)";
67    private const string BestSolutionAccuracyTestParameterName = "Best training solution accuracy (test)";
68    private const string ResultsParameterName = "Results";
69
70    #region parameter properties
71    public ScopeTreeLookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
72      get { return (ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
73    }
74    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
75      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
76    }
77    public ILookupParameter<BoolValue> MaximizationParameter {
78      get { return (ILookupParameter<BoolValue>)Parameters[MaximizationParameterName]; }
79    }
80    public IValueParameter<BoolValue> CalculateSolutionComplexityParameter {
81      get { return (IValueParameter<BoolValue>)Parameters[CalculateSolutionComplexityParameterName]; }
82    }
83    public IValueParameter<BoolValue> CalculateSolutionAccuracyParameter {
84      get { return (IValueParameter<BoolValue>)Parameters[CalculateSolutionAccuracyParameterName]; }
85    }
86    public IValueLookupParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter {
87      get { return (IValueLookupParameter<ISymbolicExpressionTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; }
88    }
89    public IValueLookupParameter<ClassificationProblemData> ProblemDataParameter {
90      get { return (IValueLookupParameter<ClassificationProblemData>)Parameters[ProblemDataParameterName]; }
91    }
92    public IValueLookupParameter<DoubleValue> UpperEstimationLimitParameter {
93      get { return (IValueLookupParameter<DoubleValue>)Parameters[UpperEstimationLimitParameterName]; }
94    }
95    public IValueLookupParameter<DoubleValue> LowerEstimationLimitParameter {
96      get { return (IValueLookupParameter<DoubleValue>)Parameters[LowerEstimationLimitParameterName]; }
97    }
98
99    public ILookupParameter<SymbolicClassificationSolution> BestSolutionParameter {
100      get { return (ILookupParameter<SymbolicClassificationSolution>)Parameters[BestSolutionParameterName]; }
101    }
102    public ILookupParameter<DoubleValue> BestSolutionQualityParameter {
103      get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionQualityParameterName]; }
104    }
105    public ILookupParameter<IntValue> BestSolutionLengthParameter {
106      get { return (ILookupParameter<IntValue>)Parameters[BestSolutionLengthParameterName]; }
107    }
108    public ILookupParameter<IntValue> BestSolutionHeightParameter {
109      get { return (ILookupParameter<IntValue>)Parameters[BestSolutionHeightParameterName]; }
110    }
111    public ILookupParameter<IntValue> BestSolutionVariablesParameter {
112      get { return (ILookupParameter<IntValue>)Parameters[BestSolutionVariablesParameterName]; }
113    }
114    public ILookupParameter<DoubleValue> BestSolutionTrainingRSquaredParameter {
115      get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionTrainingRSquaredParameterName]; }
116    }
117    public ILookupParameter<DoubleValue> BestSolutionTestRSquaredParameter {
118      get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionTestRSquaredParameterName]; }
119    }
120    public ILookupParameter<DoubleValue> BestSolutionTrainingMseParameter {
121      get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionTrainingMseParameterName]; }
122    }
123    public ILookupParameter<DoubleValue> BestSolutionTestMseParameter {
124      get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionTestMseParameterName]; }
125    }
126    public ILookupParameter<DoubleValue> BestSolutionTrainingRelativeErrorParameter {
127      get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionTrainingRelativeErrorParameterName]; }
128    }
129    public ILookupParameter<DoubleValue> BestSolutionTestRelativeErrorParameter {
130      get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionTestRelativeErrorParameterName]; }
131    }
132    public ILookupParameter<DoubleValue> BestSolutionTrainingAccuracyParameter {
133      get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionAccuracyTrainingParameterName]; }
134    }
135    public ILookupParameter<DoubleValue> BestSolutionTestAccuracyParameter {
136      get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionAccuracyTestParameterName]; }
137    }
138    public ILookupParameter<ResultCollection> ResultsParameter {
139      get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; }
140    }
141    #endregion
142    #region properties
143    public ItemArray<SymbolicExpressionTree> SymbolicExpressionTree {
144      get { return SymbolicExpressionTreeParameter.ActualValue; }
145    }
146    public ItemArray<DoubleValue> Quality {
147      get { return QualityParameter.ActualValue; }
148    }
149    public BoolValue Maximization {
150      get { return MaximizationParameter.ActualValue; }
151    }
152    public BoolValue CalculateSolutionComplexity {
153      get { return CalculateSolutionComplexityParameter.Value; }
154      set { CalculateSolutionComplexityParameter.Value = value; }
155    }
156    public BoolValue CalculateSolutionAccuracy {
157      get { return CalculateSolutionAccuracyParameter.Value; }
158      set { CalculateSolutionAccuracyParameter.Value = value; }
159    }
160    public ISymbolicExpressionTreeInterpreter SymbolicExpressionTreeInterpreter {
161      get { return SymbolicExpressionTreeInterpreterParameter.ActualValue; }
162    }
163    public ClassificationProblemData ProblemData {
164      get { return ProblemDataParameter.ActualValue; }
165    }
166    public DoubleValue UpperEstimationLimit {
167      get { return UpperEstimationLimitParameter.ActualValue; }
168    }
169    public DoubleValue LowerEstimationLimit {
170      get { return LowerEstimationLimitParameter.ActualValue; }
171    }
172    public ResultCollection Results {
173      get { return ResultsParameter.ActualValue; }
174    }
175    public SymbolicClassificationSolution BestSolution {
176      get { return BestSolutionParameter.ActualValue; }
177      set { BestSolutionParameter.ActualValue = value; }
178    }
179    public DoubleValue BestSolutionQuality {
180      get { return BestSolutionQualityParameter.ActualValue; }
181      set { BestSolutionQualityParameter.ActualValue = value; }
182    }
183    public IntValue BestSolutionLength {
184      get { return BestSolutionLengthParameter.ActualValue; }
185      set { BestSolutionLengthParameter.ActualValue = value; }
186    }
187    public IntValue BestSolutionHeight {
188      get { return BestSolutionHeightParameter.ActualValue; }
189      set { BestSolutionHeightParameter.ActualValue = value; }
190    }
191    public IntValue BestSolutionVariables {
192      get { return BestSolutionVariablesParameter.ActualValue; }
193      set { BestSolutionVariablesParameter.ActualValue = value; }
194    }
195    public DoubleValue BestSolutionTrainingRSquared {
196      get { return BestSolutionTrainingRSquaredParameter.ActualValue; }
197      set { BestSolutionTrainingRSquaredParameter.ActualValue = value; }
198    }
199    public DoubleValue BestSolutionTestRSquared {
200      get { return BestSolutionTestRSquaredParameter.ActualValue; }
201      set { BestSolutionTestRSquaredParameter.ActualValue = value; }
202    }
203    public DoubleValue BestSolutionTrainingMse {
204      get { return BestSolutionTrainingMseParameter.ActualValue; }
205      set { BestSolutionTrainingMseParameter.ActualValue = value; }
206    }
207    public DoubleValue BestSolutionTestMse {
208      get { return BestSolutionTestMseParameter.ActualValue; }
209      set { BestSolutionTestMseParameter.ActualValue = value; }
210    }
211    public DoubleValue BestSolutionTrainingRelativeError {
212      get { return BestSolutionTrainingRelativeErrorParameter.ActualValue; }
213      set { BestSolutionTrainingRelativeErrorParameter.ActualValue = value; }
214    }
215    public DoubleValue BestSolutionTestRelativeError {
216      get { return BestSolutionTestRelativeErrorParameter.ActualValue; }
217      set { BestSolutionTestRelativeErrorParameter.ActualValue = value; }
218    }
219    public DoubleValue BestSolutionTrainingAccuracy {
220      get { return BestSolutionTrainingAccuracyParameter.ActualValue; }
221      set { BestSolutionTrainingAccuracyParameter.ActualValue = value; }
222    }
223    public DoubleValue BestSolutionTestAccuracy {
224      get { return BestSolutionTestAccuracyParameter.ActualValue; }
225      set { BestSolutionTestAccuracyParameter.ActualValue = value; }
226    }
227    #endregion
228
229    [StorableConstructor]
230    private TrainingBestSymbolicClassificationSolutionAnalyzer(bool deserializing) : base(deserializing) { }
231    private TrainingBestSymbolicClassificationSolutionAnalyzer(TrainingBestSymbolicClassificationSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
232    public TrainingBestSymbolicClassificationSolutionAnalyzer()
233      : base() {
234      Parameters.Add(new LookupParameter<BoolValue>(MaximizationParameterName, "The direction of optimization."));
235      Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees to analyze."));
236      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(QualityParameterName, "The qualities of the symbolic expression trees to analyze."));
237      Parameters.Add(new ValueParameter<BoolValue>(CalculateSolutionComplexityParameterName, "Determines if the length and height of the training best solution should be calculated.", new BoolValue(true)));
238      Parameters.Add(new ValueParameter<BoolValue>(CalculateSolutionAccuracyParameterName, "Determines if the accuracy of the training best solution on the training and test set should be calculated.", new BoolValue(true)));
239      Parameters.Add(new ValueLookupParameter<ISymbolicExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, "The interpreter that should be used for the analysis of symbolic expression trees."));
240      Parameters.Add(new ValueLookupParameter<ClassificationProblemData>(ProblemDataParameterName, "The problem data for which the symbolic expression tree is a solution."));
241      Parameters.Add(new ValueLookupParameter<DoubleValue>(UpperEstimationLimitParameterName, "The upper estimation limit that was set for the evaluation of the symbolic expression trees."));
242      Parameters.Add(new ValueLookupParameter<DoubleValue>(LowerEstimationLimitParameterName, "The lower estimation limit that was set for the evaluation of the symbolic expression trees."));
243      Parameters.Add(new LookupParameter<SymbolicClassificationSolution>(BestSolutionParameterName, "The best symbolic classification solution."));
244      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionQualityParameterName, "The quality of the best symbolic classification solution."));
245      Parameters.Add(new LookupParameter<IntValue>(BestSolutionLengthParameterName, "The length of the best symbolic classification solution."));
246      Parameters.Add(new LookupParameter<IntValue>(BestSolutionHeightParameterName, "The height of the best symbolic classfication solution."));
247      Parameters.Add(new LookupParameter<IntValue>(BestSolutionVariablesParameterName, "The number of variables used by the best symbolic classification solution."));
248      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionTrainingRSquaredParameterName, "The R² value on the training set of the best symbolic classification solution."));
249      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionTestRSquaredParameterName, "The R² value on the test set of the best symbolic classification solution."));
250      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionTrainingMseParameterName, "The mean squared error on the training set of the best symbolic classification solution."));
251      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionTestMseParameterName, "The mean squared error value on the test set of the best symbolic classification solution."));
252      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionTrainingRelativeErrorParameterName, "The relative error on the training set of the best symbolic classification solution."));
253      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionTestRelativeErrorParameterName, "The relative error value on the test set of the best symbolic classification solution."));
254      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionAccuracyTrainingParameterName, "The accuracy on the training set of the best symbolic classification  solution."));
255      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionAccuracyTestParameterName, "The accuracy on the test set of the best symbolic classification  solution."));
256      Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The result collection where the best symbolic classification solution should be stored."));
257    }
258
259    public override IDeepCloneable Clone(Cloner cloner) {
260      return new TrainingBestSymbolicClassificationSolutionAnalyzer(this, cloner);
261    }
262
263    [StorableHook(HookType.AfterDeserialization)]
264    private void AfterDeserialization() { }
265
266    public override IOperation Apply() {
267      #region find best tree
268      double bestQuality = Maximization.Value ? double.NegativeInfinity : double.PositiveInfinity;
269      SymbolicExpressionTree bestTree = null;
270      SymbolicExpressionTree[] tree = SymbolicExpressionTree.ToArray();
271      double[] quality = Quality.Select(x => x.Value).ToArray();
272      for (int i = 0; i < tree.Length; i++) {
273        if ((Maximization.Value && quality[i] > bestQuality) ||
274            (!Maximization.Value && quality[i] < bestQuality)) {
275          bestQuality = quality[i];
276          bestTree = tree[i];
277        }
278      }
279      #endregion
280
281      #region update best solution
282      // if the best tree is better than the current best solution => update
283      bool newBest =
284        BestSolutionQuality == null ||
285        (Maximization.Value && bestQuality > BestSolutionQuality.Value) ||
286        (!Maximization.Value && bestQuality < BestSolutionQuality.Value);
287      if (newBest) {
288        double lowerEstimationLimit = LowerEstimationLimit.Value;
289        double upperEstimationLimit = UpperEstimationLimit.Value;
290        string targetVariable = ProblemData.TargetVariable.Value;
291
292        // calculate scaling parameters and only for the best tree using the full training set
293        double alpha, beta;
294        SymbolicRegressionScaledMeanSquaredErrorEvaluator.Calculate(SymbolicExpressionTreeInterpreter, bestTree,
295          lowerEstimationLimit, upperEstimationLimit,
296          ProblemData.Dataset, targetVariable,
297          ProblemData.TrainingIndizes, out beta, out alpha);
298
299        // scale tree for solution
300        var scaledTree = SymbolicRegressionSolutionLinearScaler.Scale(bestTree, alpha, beta);
301        var model = new SymbolicRegressionModel((ISymbolicExpressionTreeInterpreter)SymbolicExpressionTreeInterpreter.Clone(),
302          scaledTree);
303        var solution = new SymbolicClassificationSolution((ClassificationProblemData)ProblemData.Clone(), model, lowerEstimationLimit, upperEstimationLimit);
304        solution.Name = BestSolutionParameterName;
305        solution.Description = "Best solution on training partition found over the whole run.";
306
307        BestSolution = solution;
308        BestSolutionQuality = new DoubleValue(bestQuality);
309
310        if (CalculateSolutionComplexity.Value) {
311          BestSolutionLength = new IntValue(solution.Model.SymbolicExpressionTree.Size);
312          BestSolutionHeight = new IntValue(solution.Model.SymbolicExpressionTree.Height);
313          BestSolutionVariables = new IntValue(solution.Model.InputVariables.Count());
314          if (!Results.ContainsKey(BestSolutionLengthParameterName)) {
315            Results.Add(new Result(BestSolutionLengthParameterName, "Length of the best solution on the training set.", BestSolutionLength));
316            Results.Add(new Result(BestSolutionHeightParameterName, "Height of the best solution on the training set.", BestSolutionHeight));
317            Results.Add(new Result(BestSolutionVariablesParameterName, "Number of variables used by the best solution on the training set.", BestSolutionVariables));
318          } else {
319            Results[BestSolutionLengthParameterName].Value = BestSolutionLength;
320            Results[BestSolutionHeightParameterName].Value = BestSolutionHeight;
321            Results[BestSolutionVariablesParameterName].Value = BestSolutionVariables;
322          }
323        }
324
325        if (CalculateSolutionAccuracy.Value) {
326          #region update R2,MSE, Rel Error
327          IEnumerable<double> trainingValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable.Value, ProblemData.TrainingIndizes);
328          IEnumerable<double> testValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable.Value, ProblemData.TestIndizes);
329          OnlineAccuracyEvaluator accuracyEvaluator = new OnlineAccuracyEvaluator();
330          OnlineMeanSquaredErrorEvaluator mseEvaluator = new OnlineMeanSquaredErrorEvaluator();
331          OnlineMeanAbsolutePercentageErrorEvaluator relErrorEvaluator = new OnlineMeanAbsolutePercentageErrorEvaluator();
332          OnlinePearsonsRSquaredEvaluator r2Evaluator = new OnlinePearsonsRSquaredEvaluator();
333
334          #region training
335          var originalEnumerator = trainingValues.GetEnumerator();
336          var estimatedEnumerator = solution.EstimatedTrainingClassValues.GetEnumerator();
337          while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
338            accuracyEvaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
339            mseEvaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
340            r2Evaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
341            relErrorEvaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
342          }
343          double trainingAccuracy = accuracyEvaluator.Accuracy;
344          double trainingR2 = r2Evaluator.RSquared;
345          double trainingMse = mseEvaluator.MeanSquaredError;
346          double trainingRelError = relErrorEvaluator.MeanAbsolutePercentageError;
347          #endregion
348
349          accuracyEvaluator.Reset();
350          mseEvaluator.Reset();
351          relErrorEvaluator.Reset();
352          r2Evaluator.Reset();
353
354          #region test
355          originalEnumerator = testValues.GetEnumerator();
356          estimatedEnumerator = solution.EstimatedTestClassValues.GetEnumerator();
357          while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
358            accuracyEvaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
359            mseEvaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
360            r2Evaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
361            relErrorEvaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
362          }
363          double testAccuracy = accuracyEvaluator.Accuracy;
364          double testR2 = r2Evaluator.RSquared;
365          double testMse = mseEvaluator.MeanSquaredError;
366          double testRelError = relErrorEvaluator.MeanAbsolutePercentageError;
367          #endregion
368          BestSolutionTrainingAccuracy = new DoubleValue(trainingAccuracy);
369          BestSolutionTestAccuracy = new DoubleValue(testAccuracy);
370          BestSolutionTrainingRSquared = new DoubleValue(trainingR2);
371          BestSolutionTestRSquared = new DoubleValue(testR2);
372          BestSolutionTrainingMse = new DoubleValue(trainingMse);
373          BestSolutionTestMse = new DoubleValue(testMse);
374          BestSolutionTrainingRelativeError = new DoubleValue(trainingRelError);
375          BestSolutionTestRelativeError = new DoubleValue(testRelError);
376
377          if (!Results.ContainsKey(BestSolutionAccuracyTrainingParameterName)) {
378            Results.Add(new Result(BestSolutionTrainingRSquaredParameterName, BestSolutionTrainingRSquared));
379            Results.Add(new Result(BestSolutionTestRSquaredParameterName, BestSolutionTestRSquared));
380            Results.Add(new Result(BestSolutionTrainingMseParameterName, BestSolutionTrainingMse));
381            Results.Add(new Result(BestSolutionTestMseParameterName, BestSolutionTestMse));
382            Results.Add(new Result(BestSolutionTrainingRelativeErrorParameterName, BestSolutionTrainingRelativeError));
383            Results.Add(new Result(BestSolutionTestRelativeErrorParameterName, BestSolutionTestRelativeError));
384            Results.Add(new Result(BestSolutionAccuracyTrainingParameterName, BestSolutionTrainingAccuracy));
385            Results.Add(new Result(BestSolutionAccuracyTestParameterName, BestSolutionTestAccuracy));
386          } else {
387            Results[BestSolutionTrainingRSquaredParameterName].Value = BestSolutionTrainingRSquared;
388            Results[BestSolutionTestRSquaredParameterName].Value = BestSolutionTestRSquared;
389            Results[BestSolutionTrainingMseParameterName].Value = BestSolutionTrainingMse;
390            Results[BestSolutionTestMseParameterName].Value = BestSolutionTestMse;
391            Results[BestSolutionTrainingRelativeErrorParameterName].Value = BestSolutionTrainingRelativeError;
392            Results[BestSolutionTestRelativeErrorParameterName].Value = BestSolutionTestRelativeError;
393            Results[BestSolutionAccuracyTrainingParameterName].Value = BestSolutionTrainingAccuracy;
394            Results[BestSolutionAccuracyTestParameterName].Value = BestSolutionTestAccuracy;
395          }
396          #endregion
397        }
398
399        if (!Results.ContainsKey(BestSolutionQualityParameterName)) {
400          Results.Add(new Result(BestSolutionQualityParameterName, BestSolutionQuality));
401          Results.Add(new Result(BestSolutionParameterName, BestSolution));
402        } else {
403          Results[BestSolutionQualityParameterName].Value = BestSolutionQuality;
404          Results[BestSolutionParameterName].Value = BestSolution;
405        }
406      }
407      #endregion
408      return base.Apply();
409    }
410  }
411}
Note: See TracBrowser for help on using the repository browser.