Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/20/10 15:49:22 (14 years ago)
Author:
gkronber
Message:

Implemented views for DataAnalysisProblems and DataAnalysisSolutions. #938 (Data types and operators for regression problems)

Location:
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/ProbabilisticTreeCreator.cs

    r3376 r3442  
    5656      SymbolicExpressionTree tree = new SymbolicExpressionTree();
    5757      var rootNode = grammar.StartSymbol.CreateTreeNode();
     58      if (rootNode.HasLocalParameters) rootNode.ResetLocalParameters(random);
    5859      rootNode.Grammar = grammar;
    5960      tree.Root = PTC2(random, rootNode, maxTreeSize, maxTreeHeight, maxFunctionDefinitions, maxFunctionArguments);
     
    111112        var dummy = new SymbolicExpressionTreeNode();
    112113        root.AddSubTree(dummy);
    113         // dummy.Grammar = (ISymbolicExpressionGrammar)dummy.Grammar.Clone();
    114114        extensionPoints.Add(new TreeExtensionPoint { Parent = root, ChildIndex = i, ExtensionPointDepth = 2 });
    115115      }
     
    132132          Symbol selectedSymbol = SelectRandomSymbol(random, allowedSymbols);
    133133          SymbolicExpressionTreeNode newTree = selectedSymbol.CreateTreeNode();
     134          if (newTree.HasLocalParameters) newTree.ResetLocalParameters(random);
    134135          parent.RemoveSubTree(argumentIndex);
    135136          parent.InsertSubTree(argumentIndex, newTree);
     
    145146            var dummy = new SymbolicExpressionTreeNode();
    146147            newTree.AddSubTree(dummy);
    147             //if (IsTopLevelBranch(root, dummy))
    148             //  dummy.Grammar = (ISymbolicExpressionGrammar)dummy.Grammar.Clone();
    149148            extensionPoints.Add(new TreeExtensionPoint { Parent = newTree, ChildIndex = i, ExtensionPointDepth = extensionDepth + 1 });
    150149          }
     
    172171      var selectedSymbol = SelectRandomSymbol(random, possibleSymbols);
    173172      var tree = selectedSymbol.CreateTreeNode();
     173      if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
    174174      parent.RemoveSubTree(argumentIndex);
    175175      parent.InsertSubTree(argumentIndex, tree);
     
    179179        var dummy = new SymbolicExpressionTreeNode();
    180180        tree.AddSubTree(dummy);
    181         // dummy.Grammar = (ISymbolicExpressionGrammar)dummy.Grammar.Clone();
    182181        // replace the just inserted dummy by recursive application
    183182        ReplaceWithMinimalTree(random, root, tree, i, maxFunctionDefinitions, maxFunctionArguments);
     
    229228
    230229    private static bool IsTopLevelBranch(SymbolicExpressionTreeNode root, SymbolicExpressionTreeNode branch) {
    231       //return root.SubTrees.IndexOf(branch) > -1;
    232230      return branch is SymbolicExpressionTreeTopLevelNode;
    233231    }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTree.cs

    r3431 r3442  
    6565    public SymbolicExpressionTree(SymbolicExpressionTreeNode root)
    6666      : base() {
     67      this.Root = root;
    6768    }
    6869
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeCompiler.cs

    r3409 r3442  
    4646      entryPoint.Clear();
    4747      // compile main body
    48       code.AddRange(Compile(tree.Root.SubTrees[0]));
     48      code.AddRange(Compile(tree.Root.SubTrees[0].SubTrees[0]));
    4949      // compile branches
    5050      var functionBranches = from node in tree.IterateNodesPrefix()
     
    5353      foreach (DefunTreeNode branch in functionBranches) {
    5454        entryPoint[branch.FunctionName] = (short)code.Count;
    55         code.AddRange(Compile(branch));
     55        code.AddRange(Compile(branch.SubTrees[0]));
    5656      }
     57      // address of all functions is fixed now
     58      // iterate through code again and fill in the jump locations
     59      for (int i = 0; i < code.Count; i++) {
     60        Instruction instr = code[i];
     61        if (instr.symbol == CodeSymbol.Call) {
     62          var invokeNode = (InvokeFunctionTreeNode)instr.dynamicNode;
     63          instr.iArg0 = entryPoint[invokeNode.Symbol.FunctionName];
     64          instr.dynamicNode = null;
     65          code[i] = instr;
     66        }
     67      }
     68
    5769      return code.ToArray();
    5870    }
     
    6577        if (codeSymbol.ContainsKey(node.Symbol.GetType())) {
    6678          instr.symbol = codeSymbol[node.Symbol.GetType()];
    67           if (instr.symbol == CodeSymbol.Call) {
    68             var invokeNode = (InvokeFunctionTreeNode)node;
    69             instr.iArg0 = entryPoint[invokeNode.Symbol.FunctionName];
    70           } else if (instr.symbol == CodeSymbol.Arg) {
     79          if (instr.symbol == CodeSymbol.Arg) {
    7180            var argNode = (ArgumentTreeNode)node;
    7281            instr.iArg0 = (short)argNode.Symbol.ArgumentIndex;
     82          } else if (instr.symbol == CodeSymbol.Call) {
     83            instr.dynamicNode = node; // save node for fixup of jump addresses in second iteration
    7384          }
    7485        } else {
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeCreator.cs

    r3376 r3442  
    6565      SymbolicExpressionTreeParameter.ActualValue = Create(Random, SymbolicExpressionGrammar,
    6666        MaxTreeSize, MaxTreeHeight, MaxFunctionDefinitions, MaxFunctionArguments);
    67 
    68       foreach (var node in SymbolicExpressionTreeParameter.ActualValue.IterateNodesPostfix()) {
    69         node.ResetLocalParameters(RandomParameter.ActualValue);
    70       }
    7167      return null;
    7268    }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeNode.cs

    r3376 r3442  
    145145    #endregion
    146146
    147 
     147    public override string ToString() {
     148      return Symbol.Name;
     149    }
    148150
    149151  }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/DefunTreeNode.cs

    r3376 r3442  
    5353      return new DefunTreeNode(this);
    5454    }
     55
     56    public override string ToString() {
     57      return FunctionName;
     58    }
    5559  }
    5660}
Note: See TracChangeset for help on using the changeset viewer.