Changeset 16026 for branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis
- Timestamp:
- 07/27/18 19:28:18 (6 years ago)
- Location:
- branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/RSquaredEvaluator.cs
r15994 r16026 1 1 using System; 2 2 using System.Diagnostics; 3 using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration.GrammarEnumeration;4 3 using HeuristicLab.Analysis; 5 4 using HeuristicLab.Common; … … 51 50 private void AlgorithmOnDistinctSentenceGenerated(object sender, PhraseAddedEventArgs phraseAddedEventArgs) { 52 51 GrammarEnumerationAlgorithm algorithm = (GrammarEnumerationAlgorithm)sender; 53 EvaluateSentence(algorithm, phraseAddedEventArgs.NewPhrase, algorithm.OptimizeConstants );52 EvaluateSentence(algorithm, phraseAddedEventArgs.NewPhrase, algorithm.OptimizeConstants, algorithm.ConstantOptimizationIterations); 54 53 } 55 54 … … 69 68 } 70 69 71 private void EvaluateSentence(GrammarEnumerationAlgorithm algorithm, Symbol String symbolString, bool optimizeConstants) {70 private void EvaluateSentence(GrammarEnumerationAlgorithm algorithm, SymbolList sentence, bool optimizeConstants, int maxIterations) { 72 71 var results = algorithm.Results; 73 72 var grammar = algorithm.Grammar; 74 73 var problemData = algorithm.Problem.ProblemData; 75 74 76 SymbolicExpressionTree tree = algorithm.Grammar.ParseSymbolicExpressionTree(s ymbolString);75 SymbolicExpressionTree tree = algorithm.Grammar.ParseSymbolicExpressionTree(sentence); 77 76 Debug.Assert(SymbolicRegressionConstantOptimizationEvaluator.CanOptimizeConstants(tree)); 78 77 79 double r2 = Evaluate(problemData, tree, optimizeConstants );78 double r2 = Evaluate(problemData, tree, optimizeConstants, maxIterations); 80 79 double bestR2 = results.ContainsKey(BestTrainingQualityResultName) ? GetValue<double>(results[BestTrainingQualityResultName].Value) : 0.0; 81 80 if (r2 < bestR2) … … 83 82 84 83 var bestComplexity = results.ContainsKey(BestComplexityResultName) ? GetValue<int>(results[BestComplexityResultName].Value) : int.MaxValue; 85 var complexity = grammar.GetComplexity(symbolString);84 var complexity = sentence.Complexity; 86 85 87 86 if (algorithm.BestTrainingSentence == null || r2 > bestR2 || (r2.IsAlmost(bestR2) && complexity < bestComplexity)) { 88 algorithm.BestTrainingSentence = s ymbolString;87 algorithm.BestTrainingSentence = sentence; 89 88 90 89 var model = new SymbolicRegressionModel(problemData.TargetVariable, tree, expressionTreeLinearInterpreter); … … 110 109 dt = (DataTable)results[BestSolutions].Value; 111 110 dt.Rows["Quality"].Values.Add(r2); 112 dt.Rows["Relative Length"].Values.Add((double)s ymbolString.Count() / algorithm.MaxSentenceLength);111 dt.Rows["Relative Length"].Values.Add((double)sentence.Count); 113 112 dt.Rows["Complexity"].Values.Add(complexity); 114 113 dt.Rows["Timestamp"].Values.Add(algorithm.ExecutionTime.TotalMilliseconds / 1000d); … … 116 115 } 117 116 118 public static double Evaluate(IRegressionProblemData problemData, SymbolicExpressionTree tree, bool optimizeConstants = true ) {117 public static double Evaluate(IRegressionProblemData problemData, SymbolicExpressionTree tree, bool optimizeConstants = true, int maxIterations = 10) { 119 118 double r2; 120 119 … … 127 126 problemData.TrainingIndices, 128 127 applyLinearScaling: true, 129 maxIterations: 10,128 maxIterations: maxIterations, 130 129 updateVariableWeights: false, 131 130 updateConstantsInTree: true); -
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/SearchGraphVisualizer.cs
r15949 r16026 55 55 try { 56 56 var alg = (GrammarEnumerationAlgorithm)sender; 57 var phrase0 = new Symbol String(new[] { alg.Grammar.StartSymbol });57 var phrase0 = new SymbolList(new[] { alg.Grammar.StartSymbol }); 58 58 var phrase0Hash = alg.Grammar.Hasher.CalcHashCode(phrase0); 59 59 -
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/SentenceLogger.cs
r15982 r16026 89 89 distinctSentencesFileTrace.WriteLine(ToCsvLine( 90 90 ((uint)phraseAddedEventArgs.NewHash).ToString("D10"), 91 phraseAddedEventArgs.NewPhrase.Count ().ToString("D3"),91 phraseAddedEventArgs.NewPhrase.Count.ToString("D3"), 92 92 //phraseAddedEventArgs.NewPhrase.ToString(), 93 93 ((GrammarEnumerationAlgorithm)sender).Grammar.ToInfixString(phraseAddedEventArgs.NewPhrase))); … … 99 99 allSentencesFileTrace.WriteLine(ToCsvLine( 100 100 ((uint)phraseAddedEventArgs.NewHash).ToString("D10"), 101 phraseAddedEventArgs.NewPhrase.Count ().ToString("D3"),101 phraseAddedEventArgs.NewPhrase.Count.ToString("D3"), 102 102 //phraseAddedEventArgs.NewPhrase.ToString(), 103 103 ((GrammarEnumerationAlgorithm)sender).Grammar.ToInfixString(phraseAddedEventArgs.NewPhrase)));
Note: See TracChangeset
for help on using the changeset viewer.