Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4462 for branches


Ignore:
Timestamp:
09/21/10 14:18:06 (14 years ago)
Author:
gkronber
Message:

Changed symbolic simplifier to work for multi-variate models and return a symbolic expression tree that can be directly evaluated. #1142

Location:
branches/DataAnalysis
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Views/3.3/Symbolic/InteractiveSymbolicRegressionSolutionSimplifierView.cs

    r4068 r4462  
    8383        SymbolicSimplifier simplifier = new SymbolicSimplifier();
    8484        simplifiedExpressionTree = simplifier.Simplify(Content.Model.SymbolicExpressionTree);
    85         SymbolicExpressionTreeNode root = new ProgramRootSymbol().CreateTreeNode();
    86         SymbolicExpressionTreeNode start = new StartSymbol().CreateTreeNode();
    87         root.AddSubTree(start);
    88         start.AddSubTree(simplifiedExpressionTree.Root);
    8985        int samplesStart = Content.ProblemData.TrainingSamplesStart.Value;
    9086        int samplesEnd = Content.ProblemData.TrainingSamplesEnd.Value;
     87        SymbolicExpressionTree tree = (SymbolicExpressionTree)simplifiedExpressionTree.Clone();
    9188        double originalTrainingMeanSquaredError = SymbolicRegressionMeanSquaredErrorEvaluator.Calculate(
    92             Content.Model.Interpreter, new SymbolicExpressionTree(root), Content.LowerEstimationLimit, Content.UpperEstimationLimit,
     89            Content.Model.Interpreter, tree, Content.LowerEstimationLimit, Content.UpperEstimationLimit,
    9390            Content.ProblemData.Dataset, Content.ProblemData.TargetVariable.Value,
    9491            Enumerable.Range(samplesStart, samplesEnd - samplesStart));
     
    9693        this.CalculateReplacementNodes();
    9794
    98         this.CalculateNodeImpacts(new SymbolicExpressionTree(root), start, originalTrainingMeanSquaredError);
    99         this.treeChart.Tree = simplifiedExpressionTree;
     95        this.CalculateNodeImpacts(tree, tree.Root.SubTrees[0], originalTrainingMeanSquaredError);
     96        this.treeChart.Tree = new SymbolicExpressionTree(simplifiedExpressionTree.Root.SubTrees[0].SubTrees[0]);
    10097        this.PaintNodeImpacts();
    10198      }
     
    110107      SymbolicExpressionTree tree = new SymbolicExpressionTree(root);
    111108      foreach (SymbolicExpressionTreeNode node in this.simplifiedExpressionTree.IterateNodesPrefix()) {
    112         while (start.SubTrees.Count > 0) start.RemoveSubTree(0);
    113         start.AddSubTree(node);
    114         double constantTreeNodeValue = interpreter.GetSymbolicExpressionTreeValues(tree, Content.ProblemData.Dataset, trainingSamples).Median();
    115         ConstantTreeNode constantTreeNode = MakeConstantTreeNode(constantTreeNodeValue);
    116         replacementNodes[node] = constantTreeNode;
     109        if (!(node.Symbol is ProgramRootSymbol || node.Symbol is StartSymbol)) {
     110          while (start.SubTrees.Count > 0) start.RemoveSubTree(0);
     111          start.AddSubTree(node);
     112          double constantTreeNodeValue = interpreter.GetSymbolicExpressionTreeValues(tree, Content.ProblemData.Dataset, trainingSamples).Median();
     113          ConstantTreeNode constantTreeNode = MakeConstantTreeNode(constantTreeNodeValue);
     114          replacementNodes[node] = constantTreeNode;
     115        }
    117116      }
    118117    }
     
    169168        }
    170169      }
    171       this.treeChart.Tree = simplifiedExpressionTree;
    172 
    173       SymbolicExpressionTreeNode root = new ProgramRootSymbol().CreateTreeNode();
    174       SymbolicExpressionTreeNode start = new StartSymbol().CreateTreeNode();
    175       root.AddSubTree(start);
    176       SymbolicExpressionTree tree = new SymbolicExpressionTree(root);
    177       start.AddSubTree(simplifiedExpressionTree.Root);
     170      this.treeChart.Tree = new SymbolicExpressionTree(simplifiedExpressionTree.Root.SubTrees[0].SubTrees[0]);
     171
     172      SymbolicExpressionTree tree = (SymbolicExpressionTree)simplifiedExpressionTree.Clone();
    178173
    179174      this.Content.ModelChanged -= new EventHandler(Content_ModelChanged);
     
    189184      double min = impacts.Min();
    190185      foreach (SymbolicExpressionTreeNode treeNode in simplifiedExpressionTree.IterateNodesPostfix()) {
    191         if (!(treeNode is ConstantTreeNode)) {
     186        if (!(treeNode is ConstantTreeNode) && nodeImpacts.ContainsKey(treeNode)) {
    192187          double impact = this.nodeImpacts[treeNode];
    193188          double replacementValue = this.replacementNodes[treeNode].Value;
  • branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SymbolicSimplifier.cs

    r4389 r4462  
    4444      // macro expand (initially no argument trees)
    4545      var macroExpandedTree = MacroExpand(clone, clone.SubTrees[0], new List<SymbolicExpressionTreeNode>());
    46       return new SymbolicExpressionTree(GetSimplifiedTree(macroExpandedTree));
     46      SymbolicExpressionTreeNode rootNode = (new ProgramRootSymbol()).CreateTreeNode();
     47      rootNode.AddSubTree(GetSimplifiedTree(macroExpandedTree));
     48      return new SymbolicExpressionTree(rootNode);
    4749    }
    4850
     
    6365        // return the correct argument sub-tree (already macro-expanded)
    6466        return (SymbolicExpressionTreeNode)argumentTrees[argSym.ArgumentIndex].Clone();
    65       } else if (node.Symbol is StartSymbol) {
    66         return MacroExpand(root, subtrees[0], argumentTrees);
    6767      } else {
    6868        // recursive application
Note: See TracChangeset for help on using the changeset viewer.