Changeset 15859 for branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration
- Timestamp:
- 03/23/18 15:41:02 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/RSquaredEvaluator.cs
r15824 r15859 1 1 using System; 2 using System.Diagnostics; 2 3 using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration.GrammarEnumeration; 3 4 using HeuristicLab.Common; … … 63 64 64 65 private void EvaluateSentence(GrammarEnumerationAlgorithm algorithm, SymbolString symbolString) { 66 var problemData = algorithm.Problem.ProblemData; 67 65 68 SymbolicExpressionTree tree = algorithm.Grammar.ParseSymbolicExpressionTree(symbolString); 69 Debug.Assert(SymbolicRegressionConstantOptimizationEvaluator.CanOptimizeConstants(tree)); 66 70 67 var problemData = algorithm.Problem.ProblemData; 71 // TODO: Initialize constant values randomly 72 // TODO: Restarts 73 74 double r2 = SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(expressionTreeLinearInterpreter, 75 tree, 76 problemData, 77 problemData.TrainingIndices, 78 applyLinearScaling: false, 79 maxIterations: 200, 80 updateVariableWeights: true, 81 updateConstantsInTree: true); 82 83 foreach (var symbolicExpressionTreeNode in tree.IterateNodesPostfix()) { 84 ConstantTreeNode constTreeNode = symbolicExpressionTreeNode as ConstantTreeNode; 85 if (constTreeNode != null && constTreeNode.Value.IsAlmost(0.0)) { 86 constTreeNode.Value = 0.0; 87 } 88 } 89 68 90 SymbolicRegressionModel model = new SymbolicRegressionModel( 69 91 problemData.TargetVariable, … … 71 93 expressionTreeLinearInterpreter); 72 94 73 var target = problemData.TargetVariableTrainingValues;74 var estVals = model.GetEstimatedValues(problemData.Dataset, problemData.TrainingIndices);75 OnlineCalculatorError error;76 varr2 = OnlinePearsonsRCalculator.Calculate(target, estVals, out error);77 if (error != OnlineCalculatorError.None) r2 = 0.0;95 //var target = problemData.TargetVariableTrainingValues; 96 //var estVals = model.GetEstimatedValues(problemData.Dataset, problemData.TrainingIndices); 97 //OnlineCalculatorError error; 98 //r2 = OnlinePearsonsRCalculator.Calculate(target, estVals, out error); 99 //if (error != OnlineCalculatorError.None) r2 = 0.0; 78 100 79 101 var bestR2Result = (DoubleValue)algorithm.Results[BestTrainingQualityResultName].Value; 80 if (r2 > bestR2Result.Value) { 102 bool better = r2 > bestR2Result.Value; 103 bool equallyGood = r2.IsAlmost(bestR2Result.Value); 104 bool shorter = algorithm.BestTrainingSentence != null && symbolString.Count() < algorithm.BestTrainingSentence.Count(); 105 if (better || (equallyGood && shorter)) { 81 106 bestR2Result.Value = r2; 82 107 algorithm.Results.AddOrUpdateResult(BestTrainingModelResultName, model);
Note: See TracChangeset
for help on using the changeset viewer.