- Timestamp:
- 01/08/11 15:36:17 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/TrainingBestScaledSymbolicRegressionSolutionAnalyzer.cs
r5253 r5259 32 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 33 33 using HeuristicLab.Problems.DataAnalysis.Symbolic; 34 using HeuristicLab.Problems.DataAnalysis.Evaluators; 34 35 35 36 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers { … … 44 45 private const string MaximizationParameterName = "Maximization"; 45 46 private const string CalculateSolutionComplexityParameterName = "CalculateSolutionComplexity"; 47 private const string CalculateSolutionAccuracyParameterName = "CalculateSolutionAccuracy"; 46 48 private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter"; 47 49 private const string ProblemDataParameterName = "DataAnalysisProblemData"; 48 50 private const string UpperEstimationLimitParameterName = "UpperEstimationLimit"; 49 51 private const string LowerEstimationLimitParameterName = "LowerEstimationLimit"; 50 private const string BestSolutionParameterName = "Best solution (training)"; 51 private const string BestSolutionQualityParameterName = "Best solution quality (training)"; 52 private const string BestSolutionLengthParameterName = "Best solution length (training)"; 53 private const string BestSolutionHeightParameterName = "Best solution height (training)"; 54 private const string BestSolutionVariablesParameterName = "Best solution variables (training)"; 52 private const string BestSolutionParameterName = "Best training solution"; 53 private const string BestSolutionQualityParameterName = "Best training solution quality"; 54 private const string BestSolutionLengthParameterName = "Best training solution length"; 55 private const string BestSolutionHeightParameterName = "Best training solution height"; 56 private const string BestSolutionVariablesParameterName = "Best training solution variables"; 57 private const string BestSolutionTrainingRSquaredParameterName = "Best training solution R² (training)"; 58 private const string BestSolutionTestRSquaredParameterName = "Best training solution R² (test)"; 59 private const string BestSolutionTrainingMseParameterName = "Best training solution mean squared error (training)"; 60 private const string BestSolutionTestMseParameterName = "Best training solution mean squared error (test)"; 61 private const string BestSolutionTrainingRelativeErrorParameterName = "Best training solution relative error (training)"; 62 private const string BestSolutionTestRelativeErrorParameterName = "Best training solution relative error (test)"; 55 63 private const string ResultsParameterName = "Results"; 56 64 … … 68 76 get { return (IValueParameter<BoolValue>)Parameters[CalculateSolutionComplexityParameterName]; } 69 77 } 78 public IValueParameter<BoolValue> CalculateSolutionAccuracyParameter { 79 get { return (IValueParameter<BoolValue>)Parameters[CalculateSolutionAccuracyParameterName]; } 80 } 70 81 public IValueLookupParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter { 71 82 get { return (IValueLookupParameter<ISymbolicExpressionTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; } … … 95 106 public ILookupParameter<IntValue> BestSolutionVariablesParameter { 96 107 get { return (ILookupParameter<IntValue>)Parameters[BestSolutionVariablesParameterName]; } 97 } 108 } 109 public ILookupParameter<DoubleValue> BestSolutionTrainingRSquaredParameter { 110 get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionTrainingRSquaredParameterName]; } 111 } 112 public ILookupParameter<DoubleValue> BestSolutionTestRSquaredParameter { 113 get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionTestRSquaredParameterName]; } 114 } 115 public ILookupParameter<DoubleValue> BestSolutionTrainingMseParameter { 116 get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionTrainingMseParameterName]; } 117 } 118 public ILookupParameter<DoubleValue> BestSolutionTestMseParameter { 119 get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionTestMseParameterName]; } 120 } 121 public ILookupParameter<DoubleValue> BestSolutionTrainingRelativeErrorParameter { 122 get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionTrainingRelativeErrorParameterName]; } 123 } 124 public ILookupParameter<DoubleValue> BestSolutionTestRelativeErrorParameter { 125 get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionTestRelativeErrorParameterName]; } 126 } 98 127 public ILookupParameter<ResultCollection> ResultsParameter { 99 128 get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; } … … 114 143 set { CalculateSolutionComplexityParameter.Value = value; } 115 144 } 145 public BoolValue CalculateSolutionAccuracy { 146 get { return CalculateSolutionAccuracyParameter.Value; } 147 set { CalculateSolutionAccuracyParameter.Value = value; } 148 } 116 149 public ISymbolicExpressionTreeInterpreter SymbolicExpressionTreeInterpreter { 117 150 get { return SymbolicExpressionTreeInterpreterParameter.ActualValue; } … … 149 182 set { BestSolutionVariablesParameter.ActualValue = value; } 150 183 } 151 184 public DoubleValue BestSolutionTrainingRSquared { 185 get { return BestSolutionTrainingRSquaredParameter.ActualValue; } 186 set { BestSolutionTrainingRSquaredParameter.ActualValue = value; } 187 } 188 public DoubleValue BestSolutionTestRSquared { 189 get { return BestSolutionTestRSquaredParameter.ActualValue; } 190 set { BestSolutionTestRSquaredParameter.ActualValue = value; } 191 } 192 public DoubleValue BestSolutionTrainingMse { 193 get { return BestSolutionTrainingMseParameter.ActualValue; } 194 set { BestSolutionTrainingMseParameter.ActualValue = value; } 195 } 196 public DoubleValue BestSolutionTestMse { 197 get { return BestSolutionTestMseParameter.ActualValue; } 198 set { BestSolutionTestMseParameter.ActualValue = value; } 199 } 200 public DoubleValue BestSolutionTrainingRelativeError { 201 get { return BestSolutionTrainingRelativeErrorParameter.ActualValue; } 202 set { BestSolutionTrainingRelativeErrorParameter.ActualValue = value; } 203 } 204 public DoubleValue BestSolutionTestRelativeError { 205 get { return BestSolutionTestRelativeErrorParameter.ActualValue; } 206 set { BestSolutionTestRelativeErrorParameter.ActualValue = value; } 207 } 152 208 #endregion 153 209 … … 161 217 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(QualityParameterName, "The qualities of the symbolic expression trees to analyze.")); 162 218 Parameters.Add(new ValueParameter<BoolValue>(CalculateSolutionComplexityParameterName, "Determines if the length and height of the training best solution should be calculated.", new BoolValue(false))); 219 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(false))); 163 220 Parameters.Add(new ValueLookupParameter<ISymbolicExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, "The interpreter that should be used for the analysis of symbolic expression trees.")); 164 221 Parameters.Add(new ValueLookupParameter<DataAnalysisProblemData>(ProblemDataParameterName, "The problem data for which the symbolic expression tree is a solution.")); … … 170 227 Parameters.Add(new LookupParameter<IntValue>(BestSolutionHeightParameterName, "The height of the best symbolic regression solution.")); 171 228 Parameters.Add(new LookupParameter<IntValue>(BestSolutionVariablesParameterName, "The number of variables used by the best symbolic regression solution.")); 229 Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionTrainingRSquaredParameterName, "The R² value on the training set of the best symbolic regression solution.")); 230 Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionTestRSquaredParameterName, "The R² value on the test set of the best symbolic regression solution.")); 231 Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionTrainingMseParameterName, "The mean squared error on the training set of the best symbolic regression solution.")); 232 Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionTestMseParameterName, "The mean squared error value on the test set of the best symbolic regression solution.")); 233 Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionTrainingRelativeErrorParameterName, "The relative error on the training set of the best symbolic regression solution.")); 234 Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionTestRelativeErrorParameterName, "The relative error value on the test set of the best symbolic regression solution.")); 172 235 Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The result collection where the best symbolic regression solution should be stored.")); 173 236 } … … 235 298 Results[BestSolutionLengthParameterName].Value = BestSolutionLength; 236 299 Results[BestSolutionHeightParameterName].Value = BestSolutionHeight; 237 Results[BestSolutionVariablesParameterName].Value = BestSolution Height;300 Results[BestSolutionVariablesParameterName].Value = BestSolutionVariables; 238 301 } 302 } 303 304 if (CalculateSolutionAccuracy.Value) { 305 #region update R2,MSE, Rel Error 306 IEnumerable<double> trainingValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable.Value, ProblemData.TrainingIndizes); 307 IEnumerable<double> testValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable.Value, ProblemData.TestIndizes); 308 OnlineMeanSquaredErrorEvaluator mseEvaluator = new OnlineMeanSquaredErrorEvaluator(); 309 OnlineMeanAbsolutePercentageErrorEvaluator relErrorEvaluator = new OnlineMeanAbsolutePercentageErrorEvaluator(); 310 OnlinePearsonsRSquaredEvaluator r2Evaluator = new OnlinePearsonsRSquaredEvaluator(); 311 312 #region training 313 var originalEnumerator = trainingValues.GetEnumerator(); 314 var estimatedEnumerator = solution.EstimatedTrainingValues.GetEnumerator(); 315 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) { 316 mseEvaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current); 317 r2Evaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current); 318 relErrorEvaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current); 319 } 320 double trainingR2 = r2Evaluator.RSquared; 321 double trainingMse = mseEvaluator.MeanSquaredError; 322 double trainingRelError = relErrorEvaluator.MeanAbsolutePercentageError; 323 #endregion 324 325 mseEvaluator.Reset(); 326 relErrorEvaluator.Reset(); 327 r2Evaluator.Reset(); 328 329 #region test 330 originalEnumerator = testValues.GetEnumerator(); 331 estimatedEnumerator = solution.EstimatedTestValues.GetEnumerator(); 332 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) { 333 mseEvaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current); 334 r2Evaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current); 335 relErrorEvaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current); 336 } 337 double testR2 = r2Evaluator.RSquared; 338 double testMse = mseEvaluator.MeanSquaredError; 339 double testRelError = relErrorEvaluator.MeanAbsolutePercentageError; 340 #endregion 341 BestSolutionTrainingRSquared = new DoubleValue(trainingR2); 342 BestSolutionTestRSquared = new DoubleValue(testR2); 343 BestSolutionTrainingMse = new DoubleValue(trainingMse); 344 BestSolutionTestMse = new DoubleValue(testMse); 345 BestSolutionTrainingRelativeError = new DoubleValue(trainingRelError); 346 BestSolutionTestRelativeError = new DoubleValue(testRelError); 347 348 if (!Results.ContainsKey(BestSolutionTrainingRSquaredParameterName)) { 349 Results.Add(new Result(BestSolutionTrainingRSquaredParameterName, BestSolutionTrainingRSquared)); 350 Results.Add(new Result(BestSolutionTestRSquaredParameterName, BestSolutionTestRSquared)); 351 Results.Add(new Result(BestSolutionTrainingMseParameterName, BestSolutionTrainingMse)); 352 Results.Add(new Result(BestSolutionTestMseParameterName, BestSolutionTestMse)); 353 Results.Add(new Result(BestSolutionTrainingRelativeErrorParameterName, BestSolutionTrainingRelativeError)); 354 Results.Add(new Result(BestSolutionTestRelativeErrorParameterName, BestSolutionTestRelativeError)); 355 } else { 356 Results[BestSolutionTrainingRSquaredParameterName].Value = BestSolutionTrainingRSquared; 357 Results[BestSolutionTestRSquaredParameterName].Value = BestSolutionTestRSquared; 358 Results[BestSolutionTrainingMseParameterName].Value = BestSolutionTrainingMse; 359 Results[BestSolutionTestMseParameterName].Value = BestSolutionTestMse; 360 Results[BestSolutionTrainingRelativeErrorParameterName].Value = BestSolutionTrainingRelativeError; 361 Results[BestSolutionTestRelativeErrorParameterName].Value = BestSolutionTestRelativeError; 362 } 363 #endregion 239 364 } 240 365 … … 244 369 } else { 245 370 Results[BestSolutionQualityParameterName].Value = BestSolutionQuality; 371 Results[BestSolutionParameterName].Value = BestSolution; 246 372 } 247 373 }
Note: See TracChangeset
for help on using the changeset viewer.