Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/27/18 19:28:18 (6 years ago)
Author:
bburlacu
Message:

#2886:

  • replace functionally-overlapping classes Production and SymbolString with a single class SymbolList
  • refactor methods from Grammar class as methods and properties of SymbolList
  • add parameter for the number of constant optimization iterations
  • refactor code
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  
    11using System;
    22using System.Diagnostics;
    3 using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration.GrammarEnumeration;
    43using HeuristicLab.Analysis;
    54using HeuristicLab.Common;
     
    5150    private void AlgorithmOnDistinctSentenceGenerated(object sender, PhraseAddedEventArgs phraseAddedEventArgs) {
    5251      GrammarEnumerationAlgorithm algorithm = (GrammarEnumerationAlgorithm)sender;
    53       EvaluateSentence(algorithm, phraseAddedEventArgs.NewPhrase, algorithm.OptimizeConstants);
     52      EvaluateSentence(algorithm, phraseAddedEventArgs.NewPhrase, algorithm.OptimizeConstants, algorithm.ConstantOptimizationIterations);
    5453    }
    5554
     
    6968    }
    7069
    71     private void EvaluateSentence(GrammarEnumerationAlgorithm algorithm, SymbolString symbolString, bool optimizeConstants) {
     70    private void EvaluateSentence(GrammarEnumerationAlgorithm algorithm, SymbolList sentence, bool optimizeConstants, int maxIterations) {
    7271      var results = algorithm.Results;
    7372      var grammar = algorithm.Grammar;
    7473      var problemData = algorithm.Problem.ProblemData;
    7574
    76       SymbolicExpressionTree tree = algorithm.Grammar.ParseSymbolicExpressionTree(symbolString);
     75      SymbolicExpressionTree tree = algorithm.Grammar.ParseSymbolicExpressionTree(sentence);
    7776      Debug.Assert(SymbolicRegressionConstantOptimizationEvaluator.CanOptimizeConstants(tree));
    7877
    79       double r2 = Evaluate(problemData, tree, optimizeConstants);
     78      double r2 = Evaluate(problemData, tree, optimizeConstants, maxIterations);
    8079      double bestR2 = results.ContainsKey(BestTrainingQualityResultName) ? GetValue<double>(results[BestTrainingQualityResultName].Value) : 0.0;
    8180      if (r2 < bestR2)
     
    8382
    8483      var bestComplexity = results.ContainsKey(BestComplexityResultName) ? GetValue<int>(results[BestComplexityResultName].Value) : int.MaxValue;
    85       var complexity = grammar.GetComplexity(symbolString);
     84      var complexity = sentence.Complexity;
    8685
    8786      if (algorithm.BestTrainingSentence == null || r2 > bestR2 || (r2.IsAlmost(bestR2) && complexity < bestComplexity)) {
    88         algorithm.BestTrainingSentence = symbolString;
     87        algorithm.BestTrainingSentence = sentence;
    8988
    9089        var model = new SymbolicRegressionModel(problemData.TargetVariable, tree, expressionTreeLinearInterpreter);
     
    110109        dt = (DataTable)results[BestSolutions].Value;
    111110        dt.Rows["Quality"].Values.Add(r2);
    112         dt.Rows["Relative Length"].Values.Add((double)symbolString.Count() / algorithm.MaxSentenceLength);
     111        dt.Rows["Relative Length"].Values.Add((double)sentence.Count);
    113112        dt.Rows["Complexity"].Values.Add(complexity);
    114113        dt.Rows["Timestamp"].Values.Add(algorithm.ExecutionTime.TotalMilliseconds / 1000d);
     
    116115    }
    117116
    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) {
    119118      double r2;
    120119
     
    127126          problemData.TrainingIndices,
    128127          applyLinearScaling: true,
    129           maxIterations: 10,
     128          maxIterations: maxIterations,
    130129          updateVariableWeights: false,
    131130          updateConstantsInTree: true);
  • branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/SearchGraphVisualizer.cs

    r15949 r16026  
    5555      try {
    5656        var alg = (GrammarEnumerationAlgorithm)sender;
    57         var phrase0 = new SymbolString(new[] { alg.Grammar.StartSymbol });
     57        var phrase0 = new SymbolList(new[] { alg.Grammar.StartSymbol });
    5858        var phrase0Hash = alg.Grammar.Hasher.CalcHashCode(phrase0);
    5959
  • branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/SentenceLogger.cs

    r15982 r16026  
    8989      distinctSentencesFileTrace.WriteLine(ToCsvLine(
    9090        ((uint)phraseAddedEventArgs.NewHash).ToString("D10"),
    91         phraseAddedEventArgs.NewPhrase.Count().ToString("D3"),
     91        phraseAddedEventArgs.NewPhrase.Count.ToString("D3"),
    9292        //phraseAddedEventArgs.NewPhrase.ToString(),
    9393        ((GrammarEnumerationAlgorithm)sender).Grammar.ToInfixString(phraseAddedEventArgs.NewPhrase)));
     
    9999      allSentencesFileTrace.WriteLine(ToCsvLine(
    100100        ((uint)phraseAddedEventArgs.NewHash).ToString("D10"),
    101         phraseAddedEventArgs.NewPhrase.Count().ToString("D3"),
     101        phraseAddedEventArgs.NewPhrase.Count.ToString("D3"),
    102102        //phraseAddedEventArgs.NewPhrase.ToString(),
    103103        ((GrammarEnumerationAlgorithm)sender).Grammar.ToInfixString(phraseAddedEventArgs.NewPhrase)));
Note: See TracChangeset for help on using the changeset viewer.