Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10492 for trunk/sources


Ignore:
Timestamp:
02/20/14 20:37:55 (11 years ago)
Author:
bburlacu
Message:

#2156: Modified the InteractiveSymbolicDataAnalysisSolutionSimplifierView to use the unified method of calculating impact and replacement values.

Location:
trunk/sources
Files:
4 edited

Legend:

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

    r9456 r10492  
    5959      return model;
    6060    }
    61 
    6261    protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree) {
    6362      return tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToDictionary(
     
    6867
    6968    protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree) {
    70       return tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToDictionary(
    71         n => n,
    72         n => calculator.CalculateImpactValue(Content.Model, n, Content.ProblemData, Content.ProblemData.TrainingIndices, Content.TrainingAccuracy)
    73         );
     69      var values = CalculateImpactAndReplacementValues(tree);
     70      return values.ToDictionary(x => x.Key, x => x.Value.Item1);
     71    }
     72
     73    protected override Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>> CalculateImpactAndReplacementValues(ISymbolicExpressionTree tree) {
     74      var impactAndReplacementValues = new Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>>();
     75      foreach (var node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) {
     76        double impactValue, replacementValue;
     77        calculator.CalculateImpactAndReplacementValues(Content.Model, node, Content.ProblemData, Content.ProblemData.TrainingIndices, out impactValue, out replacementValue);
     78        impactAndReplacementValues.Add(node, new Tuple<double, double>(impactValue, replacementValue));
     79      }
     80      return impactAndReplacementValues;
    7481    }
    7582
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs

    r9456 r10492  
    5656
    5757    protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree) {
    58       return tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToDictionary(
    59         n => n,
    60         n => calculator.CalculateImpactValue(Content.Model, n, Content.ProblemData, Content.ProblemData.TrainingIndices, Content.TrainingRSquared)
    61         );
     58      var values = CalculateImpactAndReplacementValues(tree);
     59      return values.ToDictionary(x => x.Key, x => x.Value.Item1);
     60    }
     61
     62    protected override Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>> CalculateImpactAndReplacementValues(ISymbolicExpressionTree tree) {
     63      var impactAndReplacementValues = new Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>>();
     64      foreach (var node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) {
     65        double impactValue, replacementValue;
     66        calculator.CalculateImpactAndReplacementValues(Content.Model, node, Content.ProblemData, Content.ProblemData.TrainingIndices, out impactValue, out replacementValue);
     67        impactAndReplacementValues.Add(node, new Tuple<double, double>(impactValue, replacementValue));
     68      }
     69      return impactAndReplacementValues;
    6270    }
    6371
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs

    r9462 r10492  
    4949    }
    5050
    51     protected override void UpdateModel(ISymbolicExpressionTree tree) {
    52       var model = new SymbolicTimeSeriesPrognosisModel(tree, Content.Model.Interpreter);
    53       model.Scale(Content.ProblemData);
    54       Content.Model = model;
    55     }
    56 
    57     protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree) {
    58       Dictionary<ISymbolicExpressionTreeNode, double> replacementValues = new Dictionary<ISymbolicExpressionTreeNode, double>();
    59       foreach (var componentBranch in tree.Root.GetSubtree(0).Subtrees)
    60         foreach (ISymbolicExpressionTreeNode node in componentBranch.IterateNodesPrefix()) {
    61           replacementValues[node] = CalculateReplacementValue(node, tree);
    62         }
    63       return replacementValues;
    64     }
    65 
    66     protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree) {
     51    protected override Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>> CalculateImpactAndReplacementValues(ISymbolicExpressionTree tree) {
    6752      var interpreter = Content.Model.Interpreter;
    6853      var rows = Content.ProblemData.TrainingIndices;
     
    7257      var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows).ToArray();
    7358
    74       Dictionary<ISymbolicExpressionTreeNode, double> impactValues = new Dictionary<ISymbolicExpressionTreeNode, double>();
     59      var impactAndReplacementValues = new Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>>();
    7560      List<ISymbolicExpressionTreeNode> nodes = tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPostfix().ToList();
    7661      OnlineCalculatorError errorState;
     
    9075        // impact < 0 if new solution is better
    9176        // impact > 0 if new solution is worse
    92         impactValues[node] = originalR2 - newR2;
     77        double impact = originalR2 - newR2;
     78        impactAndReplacementValues[node] = new Tuple<double, double>(impact, constantNode.Value);
    9379        SwitchNode(parent, replacementNode, node);
    9480      }
    95       return impactValues;
     81      return impactAndReplacementValues;
     82    }
     83
     84    protected override void UpdateModel(ISymbolicExpressionTree tree) {
     85      var model = new SymbolicTimeSeriesPrognosisModel(tree, Content.Model.Interpreter);
     86      model.Scale(Content.ProblemData);
     87      Content.Model = model;
     88    }
     89
     90    protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree) {
     91      var replacementValues = new Dictionary<ISymbolicExpressionTreeNode, double>();
     92      foreach (var componentBranch in tree.Root.GetSubtree(0).Subtrees)
     93        foreach (ISymbolicExpressionTreeNode node in componentBranch.IterateNodesPrefix()) {
     94          replacementValues[node] = CalculateReplacementValue(node, tree);
     95        }
     96      return replacementValues;
     97    }
     98
     99    protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree) {
     100      var impactAndReplacementValues = CalculateImpactAndReplacementValues(tree);
     101      return impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1); // item1 of the tuple is the impact value
    96102    }
    97103
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r9478 r10492  
    7575      treeChart.Tree = tree.Root.SubtreeCount > 1 ? new SymbolicExpressionTree(tree.Root) : new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0));
    7676
    77       var replacementValues = CalculateReplacementValues(tree);
     77      var impactAndReplacementValues = CalculateImpactAndReplacementValues(tree);
     78      nodeImpacts = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1);
     79      var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2);
    7880      foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) {
    7981        foldedNodes[pair.Key] = MakeConstantTreeNode(pair.Value);
    8082      }
    81 
    82       nodeImpacts = CalculateImpactValues(tree);
    8383      PaintNodeImpacts();
    8484    }
     
    8686    protected abstract Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree);
    8787    protected abstract Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree);
     88    protected abstract Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>> CalculateImpactAndReplacementValues(ISymbolicExpressionTree tree);
    8889    protected abstract void UpdateModel(ISymbolicExpressionTree tree);
    8990
Note: See TracChangeset for help on using the changeset viewer.