Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/16/18 15:19:58 (7 years ago)
Author:
lkammere
Message:

#2886: Changes in search heuristic for solving Poly-10 problem. Adapt tree evaluation to cover non-terminal symbols.

Location:
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs

    r15883 r15907  
    176176
    177177    public double EvaluatePhrase(SymbolString s, IRegressionProblemData problemData, bool optimizeConstants) {
    178       // Create sentences without Expression symbols.
    179       Symbol[] sEval = new Symbol[s.Count()];
    180 
    181       for (int i = 0; i < sEval.Length; i++) {
    182         Symbol currSym = s[i];
    183         if (currSym is NonterminalSymbol && currSym != Expr)
    184           return 0.0;
    185 
    186         if (currSym == Expr) {
    187           sEval[i] = Const;
    188         } else {
    189           sEval[i] = currSym;
    190         }
    191       }
    192 
    193       SymbolicExpressionTree tree = ParseSymbolicExpressionTree(new SymbolString(sEval));
     178      SymbolicExpressionTree tree = ParseSymbolicExpressionTree(s);
     179
    194180      double r2 = RSquaredEvaluator.Evaluate(problemData, tree, optimizeConstants);
    195181
     
    208194    public SymbolicExpressionTree ParseSymbolicExpressionTree(SymbolString sentence) {
    209195      Debug.Assert(sentence.Any(), "Trying to evaluate empty sentence!");
    210       Debug.Assert(sentence.All(s => s is TerminalSymbol), "Trying to evaluate symbol sequence with nonterminalsymbols!");
    211196
    212197      var rootNode = rootSy.CreateTreeNode();
     
    214199      rootNode.AddSubtree(startNode);
    215200
    216       Stack<TerminalSymbol> parseStack = new Stack<TerminalSymbol>(sentence.OfType<TerminalSymbol>());
     201      Stack<Symbol> parseStack = new Stack<Symbol>(sentence);
    217202      startNode.AddSubtree(ParseSymbolicExpressionTree(parseStack));
    218203
     
    220205    }
    221206
    222     public ISymbolicExpressionTreeNode ParseSymbolicExpressionTree(Stack<TerminalSymbol> parseStack) {
    223       TerminalSymbol currentSymbol = parseStack.Pop();
     207    public ISymbolicExpressionTreeNode ParseSymbolicExpressionTree(Stack<Symbol> parseStack) {
     208      Symbol currentSymbol = parseStack.Pop();
    224209
    225210      ISymbolicExpressionTreeNode parsedSubTree = null;
     
    273258        varNode.VariableName = currentSymbol.StringRepresentation;
    274259        parsedSubTree = varNode;
     260
     261      } else if (currentSymbol is NonterminalSymbol) {
     262        ConstantTreeNode constNode = (ConstantTreeNode)constSy.CreateTreeNode();
     263        constNode.Value = 0.0;
     264        parsedSubTree = constNode;
    275265      }
    276266
  • branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/GrammarEnumerationAlgorithm.cs

    r15883 r15907  
    186186
    187187              // Is the best solution found? (only if RSquaredEvaluator is activated)
    188               if (Results.ContainsKey(RSquaredEvaluator.BestTrainingQualityResultName) && ((DoubleValue)Results[RSquaredEvaluator.BestTrainingQualityResultName].Value).Value == 1.0) {
    189                 UpdateView(force: true);
    190                 return;
     188              if (Results.ContainsKey(RSquaredEvaluator.BestTrainingQualityResultName)) {
     189                double r2 = ((DoubleValue)Results[RSquaredEvaluator.BestTrainingQualityResultName].Value).Value;
     190                if (r2.IsAlmost(1.0)) {
     191                  UpdateView(force: true);
     192                  return;
     193                }
    191194              }
    192195
     
    210213
    211214    protected double GetPriority(SymbolString phrase) {
    212       return 1.0 - Grammar.EvaluatePhrase(phrase, Problem.ProblemData, OptimizeConstants);
     215      double complexity = (double)Grammar.GetComplexity(phrase);
     216
     217      double length = phrase.Count();
     218      double relLength = (length - 2) / (MaxComplexity * 7);
     219      double r2 = Grammar.EvaluatePhrase(phrase, Problem.ProblemData, OptimizeConstants);
     220      double error = 1.0 - r2;
     221
     222      double variables = 0;
     223      for (int i = 0; i < phrase.Count(); i++) {
     224        if (phrase[i] is VariableTerminalSymbol) variables++;
     225      }
     226
     227      double variableRatio = 1.0 - variables / complexity;
     228
     229      return 1.5*relLength + error;
    213230    }
    214231
  • branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/SearchDataStructure.cs

    r15883 r15907  
    4848
    4949    private void InitPriorityQueue() {
    50       PriorityQueue<double, int> queue = new PriorityQueue<double, int>(double.MaxValue, double.MinValue, (int)Math.Pow(2.0, 20.0) / 4);
     50      int capacity = 10000000;
     51      PriorityQueue<double, int> queue = new PriorityQueue<double, int>(double.MaxValue, double.MinValue, capacity);
    5152      storeInternal = (hash, prio) => queue.Insert(prio, hash);
    5253      fetchInternal = () => {
Note: See TracChangeset for help on using the changeset viewer.