Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5993


Ignore:
Timestamp:
04/08/11 21:41:53 (12 years ago)
Author:
gkronber
Message:

#1418 fixed issues in interactive simplifier views for regression and classification solutions regarding automatic folding of nodes without impact on the solution quality and problems with ADFs.

Location:
trunk/sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/InteractiveSymbolicDiscriminantFunctionClassificationSolutionSimplifierView.cs

    r5942 r5993  
    5959    protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree) {
    6060      Dictionary<ISymbolicExpressionTreeNode, double> replacementValues = new Dictionary<ISymbolicExpressionTreeNode, double>();
    61       foreach (ISymbolicExpressionTreeNode node in tree.IterateNodesPrefix()) {
    62         if (!(node.Symbol is ProgramRootSymbol || node.Symbol is StartSymbol)) {
    63           replacementValues[node] = CalculateReplacementValue(node);
    64         }
     61      foreach (ISymbolicExpressionTreeNode node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) {
     62        replacementValues[node] = CalculateReplacementValue(node, tree);
    6563      }
    6664      return replacementValues;
     
    9088      foreach (ISymbolicExpressionTreeNode node in nodes) {
    9189        var parent = node.Parent;
    92         constantNode.Value = CalculateReplacementValue(node);
     90        constantNode.Value = CalculateReplacementValue(node, tree);
    9391        ISymbolicExpressionTreeNode replacementNode = constantNode;
    9492        SwitchNode(parent, node, replacementNode);
     
    111109    }
    112110
    113     private double CalculateReplacementValue(ISymbolicExpressionTreeNode node) {
     111    private double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree) {
     112      // remove old ADFs
     113      while (tempTree.Root.SubtreesCount > 1) tempTree.Root.RemoveSubtree(1);
     114      // clone ADFs of source tree
     115      for (int i = 1; i < sourceTree.Root.SubtreesCount; i++) {
     116        tempTree.Root.AddSubtree((ISymbolicExpressionTreeNode)sourceTree.Root.GetSubtree(i).Clone());
     117      }
    114118      var start = tempTree.Root.GetSubtree(0);
    115119      while (start.SubtreesCount > 0) start.RemoveSubtree(0);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs

    r5942 r5993  
    6060    protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree) {
    6161      Dictionary<ISymbolicExpressionTreeNode, double> replacementValues = new Dictionary<ISymbolicExpressionTreeNode, double>();
    62       foreach (ISymbolicExpressionTreeNode node in tree.IterateNodesPrefix()) {
    63         if (!(node.Symbol is ProgramRootSymbol || node.Symbol is StartSymbol)) {
    64           replacementValues[node] = CalculateReplacementValue(node);
    65         }
     62      foreach (ISymbolicExpressionTreeNode node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) {
     63        replacementValues[node] = CalculateReplacementValue(node, tree);
    6664      }
    6765      return replacementValues;
     
    8482      foreach (ISymbolicExpressionTreeNode node in nodes) {
    8583        var parent = node.Parent;
    86         constantNode.Value = CalculateReplacementValue(node);
     84        constantNode.Value = CalculateReplacementValue(node, tree);
    8785        ISymbolicExpressionTreeNode replacementNode = constantNode;
    8886        SwitchNode(parent, node, replacementNode);
     
    10098    }
    10199
    102     private double CalculateReplacementValue(ISymbolicExpressionTreeNode node) {
     100    private double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree) {
     101      // remove old ADFs
     102      while (tempTree.Root.SubtreesCount > 1) tempTree.Root.RemoveSubtree(1);
     103      // clone ADFs of source tree
     104      for (int i = 1; i < sourceTree.Root.SubtreesCount; i++) {
     105        tempTree.Root.AddSubtree((ISymbolicExpressionTreeNode)sourceTree.Root.GetSubtree(i).Clone());
     106      }
    103107      var start = tempTree.Root.GetSubtree(0);
    104108      while (start.SubtreesCount > 0) start.RemoveSubtree(0);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r5809 r5993  
    9696          for (int subTreeIndex = 0; subTreeIndex < parent.SubtreesCount; subTreeIndex++) {
    9797            var child = parent.GetSubtree(subTreeIndex);
    98             if (!(child.Symbol is Constant) && nodeImpacts[child].IsAlmost(1.0)) {
     98            if (!(child.Symbol is Constant) && nodeImpacts[child].IsAlmost(0.0)) {
    9999              SwitchNodeWithReplacementNode(parent, subTreeIndex);
    100100            }
    101101          }
    102102        }
    103         // show only interesting part of solution
    104         this.treeChart.Tree = new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0));
     103        // show only interesting part of solution
     104        if (tree.Root.SubtreesCount > 1)
     105          this.treeChart.Tree = new SymbolicExpressionTree(tree.Root); // RPB + ADFs
     106        else
     107          this.treeChart.Tree = new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); // 1st child of RPB
    105108        this.PaintNodeImpacts();
    106109      }
     
    126129        for (int i = 0; i < treeNode.SubtreesCount; i++) {
    127130          ISymbolicExpressionTreeNode subTree = treeNode.GetSubtree(i);
    128           if (subTree == visualTreeNode.SymbolicExpressionTreeNode) {
     131          // only allow to replace nodes for which a replacement value is known (replacement value for ADF nodes are not available)
     132          if (subTree == visualTreeNode.SymbolicExpressionTreeNode && replacementNodes.ContainsKey(subTree)) {
     133            double replacementImpact = nodeImpacts.ContainsKey(replacementNodes[subTree]) ? nodeImpacts[replacementNodes[subTree]] : 0.0;
     134            double originalImpact = nodeImpacts.ContainsKey(subTree) ? nodeImpacts[subTree] : 0.0;
    129135            SwitchNodeWithReplacementNode(treeNode, i);
    130           }
    131         }
    132       }
    133 
    134       // show only interesting part of solution
    135       this.treeChart.Tree = new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0));
    136 
    137       UpdateModel(tree);
     136
     137            // show only interesting part of solution
     138            if (tree.Root.SubtreesCount > 1)
     139              this.treeChart.Tree = new SymbolicExpressionTree(tree.Root); // RPB + ADFs
     140            else
     141              this.treeChart.Tree = new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); // 1st child of RPB
     142            if (!(originalImpact.IsAlmost(0.0) && replacementImpact.IsAlmost(0.0))) {
     143              // update everything after the change if necessary (impact != 0)           
     144              UpdateModel(tree);
     145            } else {
     146              // both impacts are zero, so we only need to repaint the nodes
     147              PaintNodeImpacts();
     148            }
     149            return; // break all loops
     150          }
     151        }
     152      }
    138153    }
    139154
     
    176191            visualTree.ToolTip += Environment.NewLine + "Replacement value: " + constantReplacementNode.Value;
    177192          }
    178         }
     193        } 
    179194      }
    180195      this.PaintCollapsedNodes();
Note: See TracChangeset for help on using the changeset viewer.