Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4464 for branches/DataAnalysis


Ignore:
Timestamp:
09/21/10 14:51:47 (14 years ago)
Author:
gkronber
Message:

Fixed bugs in views for manual simplification of symbolic models. #1142

Location:
branches/DataAnalysis
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis.Views/3.3/InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs

    r4463 r4464  
    105105        horizon = Content.Horizon;
    106106        IEnumerable<int> rows = Enumerable.Range(samplesStart, samplesEnd - samplesStart);
    107         SymbolicExpressionTree tree = (SymbolicExpressionTree)simplifiedExpressionTree.Clone();
    108         SymbolicTimeSeriesPrognosisScaledNormalizedMseEvaluator.CalculateScalingParameters(tree,
     107        SymbolicTimeSeriesPrognosisScaledNormalizedMseEvaluator.CalculateScalingParameters(simplifiedExpressionTree,
    109108          Content.ProblemData, interpreter,
    110109          conditionVariableName, rows,
    111110          out beta, out alpha);
    112111
    113         quality = SymbolicTimeSeriesPrognosisScaledNormalizedMseEvaluator.Evaluate(tree, Content.ProblemData, interpreter,
     112        quality = SymbolicTimeSeriesPrognosisScaledNormalizedMseEvaluator.Evaluate(simplifiedExpressionTree, Content.ProblemData, interpreter,
    114113          conditionVariableName, rows, horizon,
    115114          lowerEstimationLimit, upperEstimationLimit,
    116115          beta, alpha);
    117116
    118         //double originalQuality = SymbolicTimeSeriesPrognosisScaledNormalizedMseEvaluator.Evaluate(
    119 
    120         //  .Calculate(
    121         //    Content.Model.Interpreter, new SymbolicExpressionTree(root), Content.LowerEstimationLimit, Content.UpperEstimationLimit,
    122         //    Content.ProblemData.Dataset, Content.ProblemData.TargetVariable.Value,
    123         //    Enumerable.Range(samplesStart, samplesEnd - samplesStart));
    124 
    125117        this.CalculateReplacementNodes();
    126118
    127         this.CalculateNodeImpacts(tree, tree.Root, quality);
     119        this.CalculateNodeImpacts(simplifiedExpressionTree, simplifiedExpressionTree.Root, quality);
     120        // show only interesing part
    128121        this.treeChart.Tree = new SymbolicExpressionTree(simplifiedExpressionTree.Root.SubTrees[0]);
    129122        this.PaintNodeImpacts();
     
    138131      SymbolicExpressionTree tree = new SymbolicExpressionTree(root);
    139132      foreach (SymbolicExpressionTreeNode node in this.simplifiedExpressionTree.IterateNodesPrefix()) {
    140         if (!(node.Symbol is StartSymbol)) {
     133        if (!(node.Symbol is StartSymbol || node.Symbol is ProgramRootSymbol)) {
    141134          while (start.SubTrees.Count > 0) start.RemoveSubTree(0);
    142135          start.AddSubTree(node);
     
    150143    private void CalculateNodeImpacts(SymbolicExpressionTree tree, SymbolicExpressionTreeNode currentTreeNode, double originalQuality) {
    151144      foreach (SymbolicExpressionTreeNode childNode in currentTreeNode.SubTrees.ToList()) {
    152         if (!(childNode.Symbol is StartSymbol)) {
     145        if (!(childNode.Symbol is StartSymbol || childNode.Symbol is ProgramRootSymbol)) {
    153146          SwitchNode(currentTreeNode, childNode, replacementNodes[childNode]);
    154147          int samplesStart = Content.ProblemData.TrainingSamplesStart.Value;
     
    157150          double[] beta;
    158151          int horizon = Content.Horizon;
    159           IEnumerable<int> rows = Enumerable.Range(samplesStart, samplesEnd - samplesStart);
    160           //SymbolicExpressionTree tree = new SymbolicExpressionTree(root);
     152          IEnumerable<int> rows = Enumerable.Range(samplesStart, samplesEnd - samplesStart);         
    161153          SymbolicTimeSeriesPrognosisScaledNormalizedMseEvaluator.CalculateScalingParameters(tree,
    162154            Content.ProblemData, interpreter,
     
    201193          SymbolicExpressionTreeNode subTree = treeNode.SubTrees[i];
    202194          if (subTree == visualTreeNode.SymbolicExpressionTreeNode) {
    203             treeNode.RemoveSubTree(i);
    204             if (replacementNodes.ContainsKey(subTree))
     195            if (replacementNodes.ContainsKey(subTree)) {
     196              treeNode.RemoveSubTree(i);
    205197              treeNode.InsertSubTree(i, replacementNodes[subTree]);
    206             else if (subTree is ConstantTreeNode && replacementNodes.ContainsValue((ConstantTreeNode)subTree))
     198            } else if (subTree is ConstantTreeNode && replacementNodes.ContainsValue((ConstantTreeNode)subTree)) {
     199              treeNode.RemoveSubTree(i);
    207200              treeNode.InsertSubTree(i, replacementNodes.Where(v => v.Value == subTree).Single().Key);
    208             else if (!(subTree is ConstantTreeNode))
    209               throw new InvalidOperationException("Could not find replacement value.");
     201            }
     202            // if no replacement value is known do nothing
    210203          }
    211204        }
    212205      }
     206      // show only interesting part
    213207      this.treeChart.Tree = new SymbolicExpressionTree(simplifiedExpressionTree.Root.SubTrees[0]);
    214208
     
    249243        if (treeNode is ConstantTreeNode && replacementNodes.ContainsValue((ConstantTreeNode)treeNode))
    250244          this.treeChart.GetVisualSymbolicExpressionTreeNode(treeNode).LineColor = Color.DarkOrange;
    251         else
    252           this.treeChart.GetVisualSymbolicExpressionTreeNode(treeNode).LineColor = Color.Black;
     245        else {
     246          VisualSymbolicExpressionTreeNode visNode = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode);
     247          if (visNode != null)
     248            visNode.LineColor = Color.Black;
     249        }
    253250      }
    254251    }
  • branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Views/3.3/Symbolic/InteractiveSymbolicRegressionSolutionSimplifierView.cs

    r4462 r4464  
    8585        int samplesStart = Content.ProblemData.TrainingSamplesStart.Value;
    8686        int samplesEnd = Content.ProblemData.TrainingSamplesEnd.Value;
    87         SymbolicExpressionTree tree = (SymbolicExpressionTree)simplifiedExpressionTree.Clone();
    8887        double originalTrainingMeanSquaredError = SymbolicRegressionMeanSquaredErrorEvaluator.Calculate(
    89             Content.Model.Interpreter, tree, Content.LowerEstimationLimit, Content.UpperEstimationLimit,
     88            Content.Model.Interpreter, simplifiedExpressionTree, Content.LowerEstimationLimit, Content.UpperEstimationLimit,
    9089            Content.ProblemData.Dataset, Content.ProblemData.TargetVariable.Value,
    9190            Enumerable.Range(samplesStart, samplesEnd - samplesStart));
     
    9392        this.CalculateReplacementNodes();
    9493
    95         this.CalculateNodeImpacts(tree, tree.Root.SubTrees[0], originalTrainingMeanSquaredError);
     94        this.CalculateNodeImpacts(simplifiedExpressionTree, simplifiedExpressionTree.Root.SubTrees[0], originalTrainingMeanSquaredError);
     95        // show only interesting part of solution
    9696        this.treeChart.Tree = new SymbolicExpressionTree(simplifiedExpressionTree.Root.SubTrees[0].SubTrees[0]);
    9797        this.PaintNodeImpacts();
     
    168168        }
    169169      }
     170
     171      // show only interesting part of solution
    170172      this.treeChart.Tree = new SymbolicExpressionTree(simplifiedExpressionTree.Root.SubTrees[0].SubTrees[0]);
    171173
     
    206208        if (treeNode is ConstantTreeNode && replacementNodes.ContainsValue((ConstantTreeNode)treeNode))
    207209          this.treeChart.GetVisualSymbolicExpressionTreeNode(treeNode).LineColor = Color.DarkOrange;
    208         else
    209           this.treeChart.GetVisualSymbolicExpressionTreeNode(treeNode).LineColor = Color.Black;
     210        else {
     211          VisualSymbolicExpressionTreeNode visNode = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode);
     212          if (visNode != null)
     213            visNode.LineColor = Color.Black;
     214        }
    210215      }
    211216    }
Note: See TracChangeset for help on using the changeset viewer.