Changeset 15861 for branches/2886_SymRegGrammarEnumeration
- Timestamp:
- 03/23/18 18:57:36 (7 years ago)
- Location:
- branches/2886_SymRegGrammarEnumeration
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/RSquaredEvaluator.cs
r15860 r15861 19 19 private readonly ISymbolicDataAnalysisExpressionTreeInterpreter expressionTreeLinearInterpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter(); 20 20 21 public bool OptimizeConstants { get; set; } 22 21 23 public RSquaredEvaluator() { } 22 24 23 protected RSquaredEvaluator(RSquaredEvaluator original, Cloner cloner) { } 25 protected RSquaredEvaluator(RSquaredEvaluator original, Cloner cloner) { 26 this.OptimizeConstants = original.OptimizeConstants; 27 } 24 28 25 29 public override IDeepCloneable Clone(Cloner cloner) { … … 72 76 // TODO: Restarts 73 77 74 double r2 = SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(expressionTreeLinearInterpreter, 75 tree, 76 problemData, 77 problemData.TrainingIndices, 78 applyLinearScaling: false, 79 maxIterations: 50, 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 } 78 double r2; 89 79 90 80 SymbolicRegressionModel model = new SymbolicRegressionModel( 91 problemData.TargetVariable,92 tree,93 expressionTreeLinearInterpreter);81 problemData.TargetVariable, 82 tree, 83 expressionTreeLinearInterpreter); 94 84 95 //var target = problemData.TargetVariableTrainingValues; 96 //var estVals = model.GetEstimatedValues(problemData.Dataset, problemData.TrainingIndices); 97 //OnlineCalculatorError error; 98 //double r2 = OnlinePearsonsRCalculator.Calculate(target, estVals, out error); 99 //if (error != OnlineCalculatorError.None) r2 = 0.0; 85 if (OptimizeConstants) { 86 r2 = SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(expressionTreeLinearInterpreter, 87 tree, 88 problemData, 89 problemData.TrainingIndices, 90 applyLinearScaling: false, 91 maxIterations: 50, 92 updateVariableWeights: true, 93 updateConstantsInTree: true); 94 95 foreach (var symbolicExpressionTreeNode in tree.IterateNodesPostfix()) { 96 ConstantTreeNode constTreeNode = symbolicExpressionTreeNode as ConstantTreeNode; 97 if (constTreeNode != null && constTreeNode.Value.IsAlmost(0.0)) { 98 constTreeNode.Value = 0.0; 99 } 100 } 101 102 103 } else { 104 var target = problemData.TargetVariableTrainingValues; 105 var estVals = model.GetEstimatedValues(problemData.Dataset, problemData.TrainingIndices); 106 OnlineCalculatorError error; 107 r2 = OnlinePearsonsRCalculator.Calculate(target, estVals, out error); 108 if (error != OnlineCalculatorError.None) r2 = 0.0; 109 } 100 110 101 111 var bestR2Result = (DoubleValue)algorithm.Results[BestTrainingQualityResultName].Value; -
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs
r15851 r15861 165 165 } 166 166 167 public int GetComplexity(SymbolString s) { 168 int c = 0; 169 int length = s.Count(); 170 for (int i = 0; i < length; i++) { 171 if (s[i] is NonterminalSymbol || s[i] is VariableTerminalSymbol) c++; 172 } 173 return c; 174 } 175 167 176 #region Parse to SymbolicExpressionTree 168 177 -
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/GrammarEnumerationAlgorithm.cs
r15860 r15861 2 2 using System.Collections.Generic; 3 3 using System.Linq; 4 using System.Security.Cryptography; 4 5 using System.Threading; 5 6 using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration.GrammarEnumeration; … … 30 31 31 32 33 private readonly string OptimizeConstantsParameterName = "Optimize Constants"; 32 34 private readonly string SearchDataStructureParameterName = "Search Data Structure"; 33 35 private readonly string MaxComplexityParameterName = "Max. Complexity"; … … 35 37 36 38 public override bool SupportsPause { get { return false; } } 39 40 protected IValueParameter<BoolValue> OptimizeConstantsParameter { 41 get { return (IValueParameter<BoolValue>)Parameters[OptimizeConstantsParameterName]; } 42 } 43 44 public bool OptimizeConstants { 45 get { return OptimizeConstantsParameter.Value.Value; } 46 set { OptimizeConstantsParameter.Value.Value = value; } 47 } 37 48 38 49 protected IValueParameter<IntValue> MaxComplexityParameter { … … 97 108 }; 98 109 110 Parameters.Add(new ValueParameter<BoolValue>(OptimizeConstantsParameterName, "Run constant optimization in sentence evaluation.", new BoolValue(true))); 99 111 Parameters.Add(new ValueParameter<IntValue>(MaxComplexityParameterName, "The maximum number of variable symbols in a sentence.", new IntValue(5))); 100 112 Parameters.Add(new ValueParameter<IntValue>(GuiUpdateIntervalParameterName, "Number of generated sentences, until GUI is refreshed.", new IntValue(100000))); … … 124 136 #region init 125 137 InitResults(); 138 139 Analyzers.OfType<RSquaredEvaluator>().First().OptimizeConstants = OptimizeConstants; 126 140 127 141 ArchivedPhrases = new HashSet<int>(); -
branches/2886_SymRegGrammarEnumeration/Test/GrammarEnumerationTest.cs
r15860 r15861 60 60 public void NoConstants_Nguyen1() { 61 61 // x³ + x² + x 62 alg.OptimizeConstants = false; 62 63 alg.MaxComplexity = 6; 63 64 alg.Problem.ProblemData = new NguyenFunctionOne(Seed).GenerateRegressionData(); … … 117 118 public void NoConstants_Nguyen6() { 118 119 // sin(x) + sin(x + x²) 120 alg.OptimizeConstants = false; 119 121 alg.MaxComplexity = 4; 120 122 alg.Problem.ProblemData = new NguyenFunctionSix(Seed).GenerateRegressionData(); … … 147 149 [TestProperty("Goal", "structure search")] 148 150 public void NoConstants_Nguyen9() { 149 // sin(x) + sin(y²) 151 // sin(x) + sin(y²) 152 alg.OptimizeConstants = false; 150 153 alg.MaxComplexity = 3; 151 154 alg.Problem.ProblemData = new NguyenFunctionNine(Seed).GenerateRegressionData(); … … 190 193 [TestProperty("Goal", "structure search")] 191 194 public void NoConstants_Inverse() { 192 // x / (log(x)*x + x) 195 // x / (log(x)*x + x) 196 alg.OptimizeConstants = false; 193 197 alg.MaxComplexity = 4; 194 198
Note: See TracChangeset
for help on using the changeset viewer.