Changeset 15883 for branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/RSquaredEvaluator.cs
- Timestamp:
- 04/04/18 16:23:55 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/RSquaredEvaluator.cs
r15861 r15883 13 13 namespace HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration { 14 14 public class RSquaredEvaluator : Item, IGrammarEnumerationAnalyzer { 15 p rivatereadonly string BestTrainingQualityResultName = "Best R² (Training)";16 p rivatereadonly string BestTrainingModelResultName = "Best model (Training)";17 p rivatereadonly string BestTrainingSolutionResultName = "Best solution (Training)";15 public static readonly string BestTrainingQualityResultName = "Best R² (Training)"; 16 public static readonly string BestTrainingModelResultName = "Best model (Training)"; 17 public static readonly string BestTrainingSolutionResultName = "Best solution (Training)"; 18 18 19 private readonly ISymbolicDataAnalysisExpressionTreeInterpreter expressionTreeLinearInterpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter();19 private static readonly ISymbolicDataAnalysisExpressionTreeInterpreter expressionTreeLinearInterpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter(); 20 20 21 21 public bool OptimizeConstants { get; set; } … … 73 73 Debug.Assert(SymbolicRegressionConstantOptimizationEvaluator.CanOptimizeConstants(tree)); 74 74 75 // TODO: Initialize constant values randomly 76 // TODO: Restarts 75 double r2 = Evaluate(problemData, tree, OptimizeConstants); 77 76 78 double r2; 77 var bestR2Result = (DoubleValue)algorithm.Results[BestTrainingQualityResultName].Value; 78 bool better = r2 > bestR2Result.Value; 79 bool equallyGood = r2.IsAlmost(bestR2Result.Value); 80 bool shorter = false; 79 81 80 SymbolicRegressionModel model = new SymbolicRegressionModel( 82 if (!better && equallyGood) { 83 shorter = algorithm.BestTrainingSentence != null && 84 algorithm.Grammar.GetComplexity(algorithm.BestTrainingSentence) > algorithm.Grammar.GetComplexity(symbolString); 85 } 86 if (better || (equallyGood && shorter)) { 87 bestR2Result.Value = r2; 88 89 SymbolicRegressionModel model = new SymbolicRegressionModel( 81 90 problemData.TargetVariable, 82 91 tree, 83 92 expressionTreeLinearInterpreter); 84 93 85 if (OptimizeConstants) { 94 algorithm.Results.AddOrUpdateResult(BestTrainingModelResultName, model); 95 96 algorithm.BestTrainingSentence = symbolString; 97 } 98 } 99 100 public static double Evaluate(IRegressionProblemData problemData, SymbolicExpressionTree tree, bool optimizeConstants = true) { 101 double r2; 102 103 // TODO: Initialize constant values randomly 104 // TODO: Restarts 105 if (optimizeConstants) { 86 106 r2 = SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(expressionTreeLinearInterpreter, 87 107 tree, … … 100 120 } 101 121 102 103 122 } else { 104 123 var target = problemData.TargetVariableTrainingValues; 124 125 SymbolicRegressionModel model = new SymbolicRegressionModel( 126 problemData.TargetVariable, 127 tree, 128 expressionTreeLinearInterpreter); 129 105 130 var estVals = model.GetEstimatedValues(problemData.Dataset, problemData.TrainingIndices); 106 131 OnlineCalculatorError error; … … 109 134 } 110 135 111 var bestR2Result = (DoubleValue)algorithm.Results[BestTrainingQualityResultName].Value; 112 bool better = r2 > bestR2Result.Value; 113 bool equallyGood = r2.IsAlmost(bestR2Result.Value); 114 bool shorter = false; 115 116 if (!better && equallyGood) { 117 shorter = algorithm.BestTrainingSentence != null && 118 algorithm.Grammar.GetComplexity(algorithm.BestTrainingSentence) > algorithm.Grammar.GetComplexity(symbolString); 119 } 120 if (better || (equallyGood && shorter)) { 121 bestR2Result.Value = r2; 122 algorithm.Results.AddOrUpdateResult(BestTrainingModelResultName, model); 123 124 algorithm.BestTrainingSentence = symbolString; 125 } 136 return r2; 126 137 } 127 138 }
Note: See TracChangeset
for help on using the changeset viewer.