Changeset 15993 for branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis
- Timestamp:
- 07/11/18 10:34:21 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/RSquaredEvaluator.cs
r15985 r15993 2 2 using System.Diagnostics; 3 3 using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration.GrammarEnumeration; 4 using HeuristicLab.Analysis; 4 5 using HeuristicLab.Common; 5 6 using HeuristicLab.Core; … … 20 21 public static readonly string BestTrainingSolutionResultName = "Best solution (Training)"; 21 22 public static readonly string BestComplexityResultName = "Best solution complexity"; 23 public static readonly string BestSolutions = "Best solutions"; 22 24 23 25 private static readonly ISymbolicDataAnalysisExpressionTreeInterpreter expressionTreeLinearInterpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter(); 24 25 public bool OptimizeConstants { get; set; }26 26 27 27 public RSquaredEvaluator() { } … … 31 31 32 32 protected RSquaredEvaluator(RSquaredEvaluator original, Cloner cloner) : base(original, cloner) { 33 this.OptimizeConstants = original.OptimizeConstants;34 33 } 35 34 … … 52 51 private void AlgorithmOnDistinctSentenceGenerated(object sender, PhraseAddedEventArgs phraseAddedEventArgs) { 53 52 GrammarEnumerationAlgorithm algorithm = (GrammarEnumerationAlgorithm)sender; 54 EvaluateSentence(algorithm, phraseAddedEventArgs.NewPhrase );53 EvaluateSentence(algorithm, phraseAddedEventArgs.NewPhrase, algorithm.OptimizeConstants); 55 54 } 56 55 … … 70 69 } 71 70 72 private void EvaluateSentence(GrammarEnumerationAlgorithm algorithm, SymbolString symbolString ) {71 private void EvaluateSentence(GrammarEnumerationAlgorithm algorithm, SymbolString symbolString, bool optimizeConstants) { 73 72 var results = algorithm.Results; 74 73 var grammar = algorithm.Grammar; … … 78 77 Debug.Assert(SymbolicRegressionConstantOptimizationEvaluator.CanOptimizeConstants(tree)); 79 78 80 double r2 = Evaluate(problemData, tree, OptimizeConstants);79 double r2 = Evaluate(problemData, tree, optimizeConstants); 81 80 double bestR2 = results.ContainsKey(BestTrainingQualityResultName) ? GetValue<double>(results[BestTrainingQualityResultName].Value) : 0.0; 82 81 if (r2 < bestR2) … … 90 89 results.AddOrUpdateResult(BestComplexityResultName, new IntValue(complexity)); 91 90 algorithm.BestTrainingSentence = symbolString; 91 92 // record best sentence quality & length 93 DataTable dt; 94 if (!results.ContainsKey(BestSolutions)) { 95 var names = new[] { "Quality", "Relative Length", "Complexity", "Timestamp" }; 96 dt = new DataTable(); 97 foreach (var name in names) { 98 dt.Rows.Add(new DataRow(name) { VisualProperties = { StartIndexZero = true } }); 99 } 100 results.AddOrUpdateResult(BestSolutions, dt); 101 } 102 dt = (DataTable)results[BestSolutions].Value; 103 dt.Rows["Quality"].Values.Add(r2); 104 dt.Rows["Relative Length"].Values.Add((double)symbolString.Count() / algorithm.MaxSentenceLength); 105 dt.Rows["Complexity"].Values.Add(complexity); 106 dt.Rows["Timestamp"].Values.Add(algorithm.ExecutionTime.TotalMilliseconds / 1000d); 92 107 } 93 108 }
Note: See TracChangeset
for help on using the changeset viewer.