Changeset 16053
- Timestamp:
- 08/06/18 16:54:14 (6 years ago)
- Location:
- branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration
- Files:
-
- 2 added
- 1 deleted
- 10 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/IGrammarEnumerationAnalyzer.cs
r15821 r16053 1 using HeuristicLab.Core; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using HeuristicLab.Core; 2 23 3 24 namespace HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration { 4 25 public interface IGrammarEnumerationAnalyzer : IItem { 5 void Register(GrammarEnumerationAlgorithm g);26 void Register(GrammarEnumerationAlgorithm algorithm); 6 27 void Deregister(GrammarEnumerationAlgorithm algorithm); 7 28 } -
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/SearchGraphVisualizer.cs
r16026 r16053 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Diagnostics; 3 24 using System.IO; 4 using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration.GrammarEnumeration;5 25 using HeuristicLab.Common; 6 26 using HeuristicLab.Core; -
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/SentenceLogger.cs
r16026 r16053 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Diagnostics; 3 24 using System.IO; -
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs
r16026 r16053 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections.Generic; 3 24 using System.Diagnostics; 4 25 using System.Linq; 5 using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration.GrammarEnumeration;6 26 using HeuristicLab.Common; 7 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 234 254 } 235 255 236 // returns the maximum achievable sentence length below the maximum complexity 256 /// <summary> 257 /// returns the maximum achievable sentence length below the maximum complexity 258 /// TODO: figure out a way to calculate this accurately 259 /// </summary> 260 /// <param name="maxComplexity"></param> 261 /// <returns>Maximum sentence length according to the grammar and the maximum complexity</returns> 237 262 public int GetMaxSentenceLength(int maxComplexity) { 238 263 SymbolList s = new SymbolList(StartSymbol); … … 253 278 } 254 279 255 public double EvaluatePhrase(SymbolList s, IRegressionProblemData problemData, bool optimizeConstants, int iterations ) {280 public double EvaluatePhrase(SymbolList s, IRegressionProblemData problemData, bool optimizeConstants, int iterations, bool applyLinearScaling) { 256 281 SymbolicExpressionTree tree = ParseSymbolicExpressionTree(s); 257 282 258 return RSquaredEvaluator.Evaluate(problemData, tree, optimizeConstants, iterations );283 return RSquaredEvaluator.Evaluate(problemData, tree, optimizeConstants, iterations, applyLinearScaling); 259 284 } 260 285 -
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/GrammarEnumerationAlgorithm.cs
r16026 r16053 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections.Generic; 3 24 using System.Linq; 4 25 using System.Threading; 5 using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration.GrammarEnumeration;6 26 using HeuristicLab.Collections; 7 27 using HeuristicLab.Common; … … 31 51 private readonly string ExpansionsPerSecondName = "Expansions per second"; 32 52 33 private readonly string OptimizeConstantsParameterName = "Optimize Constants";34 private readonly string ConstantOptimizationIterationsParameterName = "Constant Optimization Iterations"; 53 private readonly string EvaluatorParameterName = "Evaluator"; 54 35 55 private readonly string ErrorWeightParameterName = "Error Weight"; 36 56 private readonly string SearchDataStructureParameterName = "Search Data Structure"; … … 47 67 public override bool SupportsPause { get { return true; } } 48 68 49 protected IFixedValueParameter<BoolValue> OptimizeConstantsParameter { 50 get { return (IFixedValueParameter<BoolValue>)Parameters[OptimizeConstantsParameterName]; } 51 } 52 53 public bool OptimizeConstants { 54 get { return OptimizeConstantsParameter.Value.Value; } 55 set { OptimizeConstantsParameter.Value.Value = value; } 56 } 57 58 public int ConstantOptimizationIterations { 59 get { return ConstantOptimizationIterationsParameter.Value.Value; } 60 set { ConstantOptimizationIterationsParameter.Value.Value = value; } 61 } 62 63 public IFixedValueParameter<IntValue> ConstantOptimizationIterationsParameter { 64 get { return (IFixedValueParameter<IntValue>)Parameters[ConstantOptimizationIterationsParameterName]; } 69 public IFixedValueParameter<RSquaredEvaluator> EvaluatorParameter { 70 get { return (IFixedValueParameter<RSquaredEvaluator>)Parameters[EvaluatorParameterName]; } 71 } 72 73 public RSquaredEvaluator Evaluator { 74 get { return EvaluatorParameter.Value; } 65 75 } 66 76 … … 102 112 public int SearchDataStructureSize { 103 113 get { return SearchDataStructureSizeParameter.Value.Value; } 114 set { SearchDataStructureSizeParameter.Value.Value = value; } 104 115 } 105 116 … … 189 200 190 201 public GrammarEnumerationAlgorithm() { 191 Parameters.Add(new FixedValueParameter<BoolValue>(OptimizeConstantsParameterName, "Run constant optimization in sentence evaluation.", new BoolValue(false)));192 202 Parameters.Add(new FixedValueParameter<DoubleValue>(ErrorWeightParameterName, "Defines, how much weight is put on a phrase's r² value when priorizing phrases during search.", new DoubleValue(0.8))); 193 203 Parameters.Add(new FixedValueParameter<IntValue>(MaxComplexityParameterName, "The maximum number of variable symbols in a sentence.", new IntValue(12))); … … 195 205 Parameters.Add(new FixedValueParameter<IntValue>(SearchDataStructureSizeParameterName, "The size of the search data structure.", new IntValue((int)1e5))); 196 206 Parameters.Add(new FixedValueParameter<EnumValue<StorageType>>(SearchDataStructureParameterName, new EnumValue<StorageType>(StorageType.SortedSet))); 197 Parameters.Add(new FixedValueParameter< IntValue>(ConstantOptimizationIterationsParameterName, new IntValue(10)));207 Parameters.Add(new FixedValueParameter<RSquaredEvaluator>(EvaluatorParameterName, new RSquaredEvaluator())); 198 208 199 209 SearchDataStructureParameter.Value.ValueChanged += (o, e) => Prepare(); … … 203 213 new SearchGraphVisualizer(), 204 214 new SentenceLogger(), 205 new RSquaredEvaluator()215 new BestSolutionAnalyzer() 206 216 }; 207 217 … … 215 225 Analyzers.SetItemCheckedState(analyzer, false); 216 226 } 217 Analyzers.SetItemCheckedState(Analyzers.First(analyzer => analyzer is RSquaredEvaluator), true);227 Analyzers.SetItemCheckedState(Analyzers.First(analyzer => analyzer is BestSolutionAnalyzer), true); 218 228 219 229 var grammarSymbols = Enum.GetValues(typeof(GrammarRule)) … … 275 285 MaxSentenceLength = Grammar.GetMaxSentenceLength(MaxComplexity); 276 286 var errorWeight = ErrorWeight; 277 var optimizeConstants = OptimizeConstants; // cache value to avoid parameter lookup 278 var iterations = ConstantOptimizationIterations; 287 var evaluator = EvaluatorParameter.Value; 288 var problemData = Problem.ProblemData; 289 279 290 // main search loop 280 291 while (OpenPhrases.Count > 0) { … … 317 328 318 329 // Is the best solution found? (only if RSquaredEvaluator is activated) 319 if (Results.ContainsKey(RSquaredEvaluator.BestTrainingQualityResultName)) {320 double r2 = ((DoubleValue)Results[RSquaredEvaluator.BestTrainingQualityResultName].Value).Value;321 if (r2.IsAlmost(1.0)) {322 UpdateView(force: true);323 return;324 }325 }330 //if (Results.ContainsKey(RSquaredEvaluator.BestTrainingQualityResultName)) { 331 // double r2 = ((DoubleValue)Results[RSquaredEvaluator.BestTrainingQualityResultName].Value).Value; 332 // if (r2.IsAlmost(1.0)) { 333 // UpdateView(force: true); 334 // return; 335 // } 336 //} 326 337 327 338 if (!DistinctSentencesComplexity.ContainsKey(phraseHash) || DistinctSentencesComplexity[phraseHash] > newPhraseComplexity) { … … 334 345 335 346 } else if (!OpenPhrases.Contains(phraseHash) && !ArchivedPhrases.Contains(phraseHash)) { 336 337 bool isCompleteSentence = IsCompleteSentence(newPhrase); 338 double r2 = isCompleteSentence ? Grammar.EvaluatePhrase(newPhrase, Problem.ProblemData, optimizeConstants, iterations) : fetchedSearchNode.R2; 347 double r2 = IsCompleteSentence(newPhrase) ? evaluator.Evaluate(problemData, Grammar, newPhrase) : fetchedSearchNode.R2; 339 348 double phrasePriority = GetPriority(newPhrase, r2); 340 349 … … 389 398 var model = new SymbolicRegressionModel(Problem.ProblemData.TargetVariable, tree, interpreter); 390 399 400 var iterations = EvaluatorParameter.Value.ConstantOptimizationIterations; 401 var applyLinearScaling = EvaluatorParameter.Value.ApplyLinearScaling; 402 391 403 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants( 392 404 interpreter, … … 394 406 Problem.ProblemData, 395 407 Problem.ProblemData.TrainingIndices, 396 applyLinearScaling: true,397 maxIterations: ConstantOptimizationIterations,408 applyLinearScaling: applyLinearScaling, 409 maxIterations: iterations, 398 410 updateVariableWeights: false, 399 411 updateConstantsInTree: true); -
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/LruCache.cs
r15981 r16053 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections; 3 24 using System.Collections.Generic; … … 6 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 7 28 8 namespace HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration .GrammarEnumeration{29 namespace HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration { 9 30 /// <summary> 10 31 /// A least-recently-used cache stored like a dictionary. -
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/RSquaredEvaluator.cs
r16052 r16053 1 using System; 2 using System.Diagnostics; 3 using HeuristicLab.Analysis; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 4 22 using HeuristicLab.Common; 5 23 using HeuristicLab.Core; 6 24 using HeuristicLab.Data; 7 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 using HeuristicLab.Parameters; 8 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 9 28 using HeuristicLab.Problems.DataAnalysis; … … 14 33 [Item("RSquaredEvaluator", "")] 15 34 [StorableClass] 16 public class RSquaredEvaluator : Item, IGrammarEnumerationAnalyzer { 17 public static readonly string BestTrainingQualityResultName = "Best R² (Training)"; 18 public static readonly string BestTestQualityResultName = "Best R² (Test)"; 19 public static readonly string BestTrainingModelResultName = "Best model (Training)"; 20 public static readonly string BestTrainingSolutionResultName = "Best solution (Training)"; 21 public static readonly string BestComplexityResultName = "Best solution complexity"; 22 public static readonly string BestSolutions = "Best solutions"; 35 public class RSquaredEvaluator : ParameterizedNamedItem, IGrammarEnumerationEvaluator { 36 private readonly string OptimizeConstantsParameterName = "Optimize Constants"; 37 private readonly string ApplyLinearScalingParameterName = "Apply Linear Scaling"; 38 private readonly string ConstantOptimizationIterationsParameterName = "Constant Optimization Iterations"; 39 40 #region parameter properties 41 public IFixedValueParameter<BoolValue> OptimizeConstantsParameter { 42 get { return (IFixedValueParameter<BoolValue>)Parameters[OptimizeConstantsParameterName]; } 43 } 44 45 public IFixedValueParameter<BoolValue> ApplyLinearScalingParameter { 46 get { return (IFixedValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } 47 } 48 49 public IFixedValueParameter<IntValue> ConstantOptimizationIterationsParameter { 50 get { return (IFixedValueParameter<IntValue>)Parameters[ConstantOptimizationIterationsParameterName]; } 51 } 52 53 public bool OptimizeConstants { 54 get { return OptimizeConstantsParameter.Value.Value; } 55 set { OptimizeConstantsParameter.Value.Value = value; } 56 } 57 58 public bool ApplyLinearScaling { 59 get { return ApplyLinearScalingParameter.Value.Value; } 60 set { ApplyLinearScalingParameter.Value.Value = value; } 61 } 62 63 public int ConstantOptimizationIterations { 64 get { return ConstantOptimizationIterationsParameter.Value.Value; } 65 set { ConstantOptimizationIterationsParameter.Value.Value = value; } 66 } 67 #endregion 23 68 24 69 private static readonly ISymbolicDataAnalysisExpressionTreeInterpreter expressionTreeLinearInterpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter(); 25 70 26 public RSquaredEvaluator() { } 71 public RSquaredEvaluator() { 72 Parameters.Add(new FixedValueParameter<BoolValue>(OptimizeConstantsParameterName, "Run constant optimization in sentence evaluation.", new BoolValue(false))); 73 Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Apply linear scaling on the tree model during evaluation.", new BoolValue(false))); 74 Parameters.Add(new FixedValueParameter<IntValue>(ConstantOptimizationIterationsParameterName, new IntValue(10))); 75 } 27 76 28 77 [StorableConstructor] … … 36 85 } 37 86 38 public void Register(GrammarEnumerationAlgorithm algorithm) { 39 algorithm.Started += OnStarted; 40 algorithm.Stopped += OnStopped; 41 algorithm.DistinctSentenceGenerated += AlgorithmOnDistinctSentenceGenerated; 87 public double Evaluate(IRegressionProblemData problemData, Grammar grammar, SymbolList sentence) { 88 var tree = grammar.ParseSymbolicExpressionTree(sentence); 89 return Evaluate(problemData, tree, OptimizeConstants, ConstantOptimizationIterations, ApplyLinearScaling); 42 90 } 43 91 44 public void Deregister(GrammarEnumerationAlgorithm algorithm) { 45 algorithm.Started -= OnStarted; 46 algorithm.Stopped -= OnStopped; 47 algorithm.DistinctSentenceGenerated -= AlgorithmOnDistinctSentenceGenerated; 92 public double Evaluate(IRegressionProblemData problemData, ISymbolicExpressionTree tree) { 93 return Evaluate(problemData, tree, OptimizeConstants, ConstantOptimizationIterations, ApplyLinearScaling); 48 94 } 49 95 50 private void AlgorithmOnDistinctSentenceGenerated(object sender, PhraseAddedEventArgs phraseAddedEventArgs) { 51 GrammarEnumerationAlgorithm algorithm = (GrammarEnumerationAlgorithm)sender; 52 EvaluateSentence(algorithm, phraseAddedEventArgs.NewPhrase, algorithm.OptimizeConstants, algorithm.ConstantOptimizationIterations); 53 } 54 55 private void OnStarted(object sender, EventArgs eventArgs) { 56 GrammarEnumerationAlgorithm algorithm = (GrammarEnumerationAlgorithm)sender; 57 58 algorithm.BestTrainingSentence = null; 59 } 60 61 private void OnStopped(object sender, EventArgs eventArgs) { } 62 63 private T GetValue<T>(IItem value) where T : struct { 64 var v = value as ValueTypeValue<T>; 65 if (v == null) 66 throw new ArgumentException(string.Format("Item is not of type {0}", typeof(ValueTypeValue<T>))); 67 return v.Value; 68 } 69 70 private void EvaluateSentence(GrammarEnumerationAlgorithm algorithm, SymbolList sentence, bool optimizeConstants, int maxIterations) { 71 var results = algorithm.Results; 72 var grammar = algorithm.Grammar; 73 var problemData = algorithm.Problem.ProblemData; 74 75 SymbolicExpressionTree tree = algorithm.Grammar.ParseSymbolicExpressionTree(sentence); 76 Debug.Assert(SymbolicRegressionConstantOptimizationEvaluator.CanOptimizeConstants(tree)); 77 78 double r2 = Evaluate(problemData, tree, optimizeConstants, maxIterations); 79 double bestR2 = results.ContainsKey(BestTrainingQualityResultName) ? GetValue<double>(results[BestTrainingQualityResultName].Value) : 0.0; 80 if (r2 < bestR2) 81 return; 82 83 var bestComplexity = results.ContainsKey(BestComplexityResultName) ? GetValue<int>(results[BestComplexityResultName].Value) : int.MaxValue; 84 var complexity = sentence.Complexity; 85 86 if (algorithm.BestTrainingSentence == null || r2 > bestR2 || (r2.IsAlmost(bestR2) && complexity < bestComplexity)) { 87 algorithm.BestTrainingSentence = sentence; 88 89 var model = new SymbolicRegressionModel(problemData.TargetVariable, tree, expressionTreeLinearInterpreter); 90 model.Scale(problemData); 91 var bestSolution = model.CreateRegressionSolution(problemData); 92 93 results.AddOrUpdateResult(BestTrainingQualityResultName, new DoubleValue(bestSolution.TrainingRSquared)); 94 results.AddOrUpdateResult(BestTestQualityResultName, new DoubleValue(bestSolution.TestRSquared)); 95 results.AddOrUpdateResult(BestTrainingModelResultName, bestSolution.Model); 96 results.AddOrUpdateResult(BestTrainingSolutionResultName, bestSolution); 97 results.AddOrUpdateResult(BestComplexityResultName, new IntValue(complexity)); 98 99 // record best sentence quality & length 100 DataTable dt; 101 if (!results.ContainsKey(BestSolutions)) { 102 var names = new[] { "Quality", "Relative Length", "Complexity", "Timestamp" }; 103 dt = new DataTable(); 104 foreach (var name in names) { 105 dt.Rows.Add(new DataRow(name) { VisualProperties = { StartIndexZero = true } }); 106 } 107 results.AddOrUpdateResult(BestSolutions, dt); 108 } 109 dt = (DataTable)results[BestSolutions].Value; 110 dt.Rows["Quality"].Values.Add(r2); 111 dt.Rows["Relative Length"].Values.Add((double)sentence.Count); 112 dt.Rows["Complexity"].Values.Add(complexity); 113 dt.Rows["Timestamp"].Values.Add(algorithm.ExecutionTime.TotalMilliseconds / 1000d); 114 } 115 } 116 117 public static double Evaluate(IRegressionProblemData problemData, SymbolicExpressionTree tree, bool optimizeConstants = true, int maxIterations = 10) { 96 public static double Evaluate(IRegressionProblemData problemData, ISymbolicExpressionTree tree, bool optimizeConstants = true, int maxIterations = 10, bool applyLinearScaling = false) { 118 97 double r2; 119 98 … … 125 104 problemData, 126 105 problemData.TrainingIndices, 127 applyLinearScaling: true,106 applyLinearScaling: applyLinearScaling, 128 107 maxIterations: maxIterations, 129 108 updateVariableWeights: false, … … 143 122 problemData, 144 123 problemData.TrainingIndices, 145 applyLinearScaling: true);124 applyLinearScaling: applyLinearScaling); 146 125 } 147 126 return double.IsNaN(r2) ? 0.0 : r2; -
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/SearchDataStructure.cs
r16026 r16053 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections; 3 24 using System.Collections.Generic; … … 6 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 7 28 8 namespace HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration .GrammarEnumeration{29 namespace HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration { 9 30 [StorableClass] 10 31 public class SearchNode : DeepCloneable { -
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Symbol.cs
r16026 r16053 1 using System; 2 using System.Collections; 3 using System.Collections.Generic; 4 using System.Diagnostics; 5 using System.Linq; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 6 23 using HeuristicLab.Common; 7 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 103 120 } 104 121 105 122 106 123 } -
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Hashing/Hasher.cs
r16026 r16053 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections.Generic; 3 24 using System.Diagnostics; … … 6 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 7 28 8 namespace HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration .GrammarEnumeration{29 namespace HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration { 9 30 [StorableClass] 10 31 public abstract class Hasher<THashType> : DeepCloneable { -
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration.csproj
r16026 r16053 116 116 </ItemGroup> 117 117 <ItemGroup> 118 <Compile Include="Analysis\BestSolutionAnalyzer.cs" /> 118 119 <Compile Include="Analysis\IGrammarEnumerationAnalyzer.cs" /> 119 <Compile Include="Analysis\RSquaredEvaluator.cs" /> 120 <Compile Include="Analysis\IGrammarEnumerationEvaluator.cs" /> 121 <Compile Include="GrammarEnumeration\RSquaredEvaluator.cs" /> 120 122 <Compile Include="Analysis\SentenceLogger.cs" /> 121 123 <Compile Include="Analysis\SearchGraphVisualizer.cs" />
Note: See TracChangeset
for help on using the changeset viewer.