Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4880


Ignore:
Timestamp:
11/20/10 22:40:45 (14 years ago)
Author:
gkronber
Message:

Automatically fold branches with no impact in the InteractiveSymbolicRegressionSolutionSimplifierView. #1227

Location:
branches/SymbolicSimplifier/HeuristicLab.Problems.DataAnalysis.Views
Files:
2 edited
1 copied

Legend:

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

    r3927 r4880  
    8181      this.viewHost.Caption = "View";
    8282      this.viewHost.Content = null;
     83      this.viewHost.Enabled = false;
    8384      this.viewHost.Location = new System.Drawing.Point(6, 16);
    8485      this.viewHost.Name = "viewHost";
  • branches/SymbolicSimplifier/HeuristicLab.Problems.DataAnalysis.Views/3.3/Symbolic/InteractiveSymbolicRegressionSolutionSimplifierView.cs

    r4477 r4880  
    9393
    9494        this.CalculateNodeImpacts(simplifiedExpressionTree, simplifiedExpressionTree.Root.SubTrees[0], originalTrainingMeanSquaredError);
     95        // automatically fold all branches with impact = 1
     96        List<SymbolicExpressionTreeNode> nodeList = simplifiedExpressionTree.Root.SubTrees[0].IterateNodesPrefix().ToList();
     97        foreach (var parent in nodeList) {
     98          for (int subTreeIndex = 0; subTreeIndex < parent.SubTrees.Count; subTreeIndex++) {
     99            var child = parent.SubTrees[subTreeIndex];
     100            if (!(child.Symbol is Constant) && nodeImpacts[child].IsAlmost(1.0)) {
     101              ReplaceNodeWithConstant(parent, subTreeIndex);
     102            }
     103          }
     104        }
    95105        // show only interesting part of solution
    96106        this.treeChart.Tree = new SymbolicExpressionTree(simplifiedExpressionTree.Root.SubTrees[0].SubTrees[0]);
     
    158168          SymbolicExpressionTreeNode subTree = treeNode.SubTrees[i];
    159169          if (subTree == visualTreeNode.SymbolicExpressionTreeNode) {
    160             treeNode.RemoveSubTree(i);
    161             if (replacementNodes.ContainsKey(subTree))
    162               treeNode.InsertSubTree(i, replacementNodes[subTree]);
    163             else if (subTree is ConstantTreeNode && replacementNodes.ContainsValue((ConstantTreeNode)subTree))
    164               treeNode.InsertSubTree(i, replacementNodes.Where(v => v.Value == subTree).Single().Key);
    165             else if (!(subTree is ConstantTreeNode))
    166               throw new InvalidOperationException("Could not find replacement value.");
     170            ReplaceNodeWithConstant(treeNode, i);
    167171          }
    168172        }
     
    179183
    180184      this.PaintNodeImpacts();
     185    }
     186
     187    private void ReplaceNodeWithConstant(SymbolicExpressionTreeNode parent, int subTreeIndex) {
     188      SymbolicExpressionTreeNode subTree = parent.SubTrees[subTreeIndex];
     189      parent.RemoveSubTree(subTreeIndex);
     190      if (replacementNodes.ContainsKey(subTree))
     191        parent.InsertSubTree(subTreeIndex, replacementNodes[subTree]);
     192      else if (subTree is ConstantTreeNode && replacementNodes.ContainsValue((ConstantTreeNode)subTree))
     193        parent.InsertSubTree(subTreeIndex, replacementNodes.Where(v => v.Value == subTree).Single().Key);
     194      else if (!(subTree is ConstantTreeNode))
     195        throw new InvalidOperationException("Could not find replacement value.");
    181196    }
    182197
Note: See TracChangeset for help on using the changeset viewer.