Changeset 5275 for branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Analyzers/RegressionSolutionAnalyzer.cs
- Timestamp:
- 01/11/11 15:03:46 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Analyzers/RegressionSolutionAnalyzer.cs
r4308 r5275 21 21 22 22 using System.Collections.Generic; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Data; … … 28 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 30 using HeuristicLab.Problems.DataAnalysis.Evaluators; 30 using HeuristicLab.Analysis;31 31 32 32 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers { … … 90 90 #endregion 91 91 92 93 [StorableConstructor] 94 protected RegressionSolutionAnalyzer(bool deserializing) : base(deserializing) { } 95 protected RegressionSolutionAnalyzer(RegressionSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { } 92 96 public RegressionSolutionAnalyzer() 93 97 : base() { … … 102 106 103 107 [StorableHook(HookType.AfterDeserialization)] 104 private void Initialize() {108 private void AfterDeserialization() { 105 109 // backwards compatibility 106 110 if (!Parameters.ContainsKey(GenerationsParameterName)) { … … 119 123 } 120 124 121 public static void UpdateBestSolutionResults(DataAnalysisSolution bestSolution, DataAnalysisProblemData problemData, ResultCollection results, IntValue CurrentGeneration) { 122 var solution = bestSolution; 125 public static void UpdateBestSolutionResults(DataAnalysisSolution solution, DataAnalysisProblemData problemData, ResultCollection results, IntValue generation) { 123 126 #region update R2,MSE, Rel Error 124 IEnumerable<double> trainingValues = problemData.Dataset.GetEnumeratedVariableValues( 125 problemData.TargetVariable.Value, 126 problemData.TrainingSamplesStart.Value, 127 problemData.TrainingSamplesEnd.Value); 128 IEnumerable<double> testValues = problemData.Dataset.GetEnumeratedVariableValues( 129 problemData.TargetVariable.Value, 130 problemData.TestSamplesStart.Value, 131 problemData.TestSamplesEnd.Value); 127 IEnumerable<double> trainingValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable.Value, problemData.TrainingIndizes); 128 IEnumerable<double> testValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable.Value, problemData.TestIndizes); 132 129 OnlineMeanSquaredErrorEvaluator mseEvaluator = new OnlineMeanSquaredErrorEvaluator(); 133 130 OnlineMeanAbsolutePercentageErrorEvaluator relErrorEvaluator = new OnlineMeanAbsolutePercentageErrorEvaluator(); 134 131 OnlinePearsonsRSquaredEvaluator r2Evaluator = new OnlinePearsonsRSquaredEvaluator(); 132 135 133 #region training 136 134 var originalEnumerator = trainingValues.GetEnumerator(); … … 145 143 double trainingRelError = relErrorEvaluator.MeanAbsolutePercentageError; 146 144 #endregion 145 147 146 mseEvaluator.Reset(); 148 147 relErrorEvaluator.Reset(); 149 148 r2Evaluator.Reset(); 149 150 150 #region test 151 151 originalEnumerator = testValues.GetEnumerator(); … … 160 160 double testRelError = relErrorEvaluator.MeanAbsolutePercentageError; 161 161 #endregion 162 162 163 if (results.ContainsKey(BestSolutionResultName)) { 163 164 results[BestSolutionResultName].Value = solution; … … 168 169 results[BestSolutionTrainingRelativeError].Value = new DoubleValue(trainingRelError); 169 170 results[BestSolutionTestRelativeError].Value = new DoubleValue(testRelError); 170 if (CurrentGeneration != null) // this check is needed because linear regression solutions do not have a generations parameter 171 results[BestSolutionGeneration].Value = new IntValue(CurrentGeneration.Value); 172 var solutionQualityTable = (DataTable)results["Best solution quality table"].Value; 173 solutionQualityTable.Rows["Training R²"].Values.Add(trainingR2); 174 solutionQualityTable.Rows["Training MSE"].Values.Add(trainingMse); 175 solutionQualityTable.Rows["Test R²"].Values.Add(testR2); 176 solutionQualityTable.Rows["Test MSE"].Values.Add(testMse); 171 if (generation != null) // this check is needed because linear regression solutions do not have a generations parameter 172 results[BestSolutionGeneration].Value = new IntValue(generation.Value); 177 173 } else { 178 174 results.Add(new Result(BestSolutionResultName, solution)); … … 183 179 results.Add(new Result(BestSolutionTrainingRelativeError, new DoubleValue(trainingRelError))); 184 180 results.Add(new Result(BestSolutionTestRelativeError, new DoubleValue(testRelError))); 185 if (CurrentGeneration != null) 186 results.Add(new Result(BestSolutionGeneration, new IntValue(CurrentGeneration.Value))); 187 var solutionQualityTable = new DataTable("Best solution quality table"); 188 solutionQualityTable.Rows.Add(new DataRow("Training R²")); 189 solutionQualityTable.Rows.Add(new DataRow("Training MSE")); 190 solutionQualityTable.Rows.Add(new DataRow("Test R²")); 191 solutionQualityTable.Rows.Add(new DataRow("Test MSE")); 192 solutionQualityTable.Rows["Training R²"].Values.Add(trainingR2); 193 solutionQualityTable.Rows["Training MSE"].Values.Add(trainingMse); 194 solutionQualityTable.Rows["Test R²"].Values.Add(testR2); 195 solutionQualityTable.Rows["Test MSE"].Values.Add(testMse); 196 results.Add(new Result("Best solution quality table", solutionQualityTable)); 181 if (generation != null) 182 results.Add(new Result(BestSolutionGeneration, new IntValue(generation.Value))); 197 183 } 198 184 #endregion
Note: See TracChangeset
for help on using the changeset viewer.