Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/29/12 09:57:15 (11 years ago)
Author:
abeham
Message:

#1985: Synchronized with trunk

Location:
branches/RuntimeOptimizer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/RuntimeOptimizer

  • branches/RuntimeOptimizer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Viewsmergedeligible
      /trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Viewsmergedeligible
      /branches/Algorithms.GradientDescent/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views5516-5520
      /branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views6917-7005
      /branches/CloningRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views4656-4721
      /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views5700-5808
      /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views5471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views5815-6180
      /branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views4458-4459,​4462,​4464
      /branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views5060
      /branches/NET40/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views5138-5162
      /branches/ParallelEngine/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views7568-7810
      /branches/QAPAlgorithms/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views6350-6627
      /branches/Restructure trunk solution/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views6828
      /branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views7787-8333
      /branches/SlaveShutdown/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views8944-8956
      /branches/SuccessProgressAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views5370-5682
      /branches/Trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views6829-6865
      /branches/VNS/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views5594-5752
      /branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views5959-6341
  • branches/RuntimeOptimizer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs

    r8736 r8971  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using HeuristicLab.Common;
    2625using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2726using HeuristicLab.Problems.DataAnalysis.Symbolic.Views;
     
    2928namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
    3029  public partial class InteractiveSymbolicRegressionSolutionSimplifierView : InteractiveSymbolicDataAnalysisSolutionSimplifierView {
    31     private readonly ConstantTreeNode constantNode;
    32     private readonly SymbolicExpressionTree tempTree;
     30    private readonly SymbolicRegressionSolutionImpactValuesCalculator calculator;
    3331
    3432    public new SymbolicRegressionSolution Content {
     
    4139      InitializeComponent();
    4240      this.Caption = "Interactive Regression Solution Simplifier";
    43 
    44       constantNode = ((ConstantTreeNode)new Constant().CreateTreeNode());
    45       ISymbolicExpressionTreeNode root = new ProgramRootSymbol().CreateTreeNode();
    46       ISymbolicExpressionTreeNode start = new StartSymbol().CreateTreeNode();
    47       root.AddSubtree(start);
    48       tempTree = new SymbolicExpressionTree(root);
     41      calculator = new SymbolicRegressionSolutionImpactValuesCalculator();
    4942    }
    5043
     
    5649
    5750    protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree) {
    58       Dictionary<ISymbolicExpressionTreeNode, double> replacementValues = new Dictionary<ISymbolicExpressionTreeNode, double>();
    59       foreach (ISymbolicExpressionTreeNode node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) {
    60         replacementValues[node] = CalculateReplacementValue(node, tree);
    61       }
    62       return replacementValues;
     51      return tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToDictionary(
     52        n => n,
     53        n => calculator.CalculateReplacementValue(Content.Model, n, Content.ProblemData, Content.ProblemData.TrainingIndices)
     54        );
    6355    }
    6456
    6557    protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree) {
    66       var interpreter = Content.Model.Interpreter;
    67       var dataset = Content.ProblemData.Dataset;
    68       var rows = Content.ProblemData.TrainingIndices;
    69       string targetVariable = Content.ProblemData.TargetVariable;
    70       Dictionary<ISymbolicExpressionTreeNode, double> impactValues = new Dictionary<ISymbolicExpressionTreeNode, double>();
    71       List<ISymbolicExpressionTreeNode> nodes = tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPostfix().ToList();
    72       var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows).LimitToRange(Content.Model.LowerEstimationLimit, Content.Model.UpperEstimationLimit).ToArray();
    73       var targetValues = dataset.GetDoubleValues(targetVariable, rows);
    74       OnlineCalculatorError errorState;
    75       double originalR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, originalOutput, out errorState);
    76       if (errorState != OnlineCalculatorError.None) originalR2 = 0.0;
    77 
    78       foreach (ISymbolicExpressionTreeNode node in nodes) {
    79         var parent = node.Parent;
    80         constantNode.Value = CalculateReplacementValue(node, tree);
    81         ISymbolicExpressionTreeNode replacementNode = constantNode;
    82         SwitchNode(parent, node, replacementNode);
    83         var newOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows).LimitToRange(Content.Model.LowerEstimationLimit, Content.Model.UpperEstimationLimit);
    84         double newR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, newOutput, out errorState);
    85         if (errorState != OnlineCalculatorError.None) newR2 = 0.0;
    86 
    87         // impact = 0 if no change
    88         // impact < 0 if new solution is better
    89         // impact > 0 if new solution is worse
    90         impactValues[node] = originalR2 - newR2;
    91         SwitchNode(parent, replacementNode, node);
    92       }
    93       return impactValues;
     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        );
    9462    }
    95 
    96     private double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree) {
    97       // remove old ADFs
    98       while (tempTree.Root.SubtreeCount > 1) tempTree.Root.RemoveSubtree(1);
    99       // clone ADFs of source tree
    100       for (int i = 1; i < sourceTree.Root.SubtreeCount; i++) {
    101         tempTree.Root.AddSubtree((ISymbolicExpressionTreeNode)sourceTree.Root.GetSubtree(i).Clone());
    102       }
    103       var start = tempTree.Root.GetSubtree(0);
    104       while (start.SubtreeCount > 0) start.RemoveSubtree(0);
    105       start.AddSubtree((ISymbolicExpressionTreeNode)node.Clone());
    106       var interpreter = Content.Model.Interpreter;
    107       var rows = Content.ProblemData.TrainingIndices;
    108       return interpreter.GetSymbolicExpressionTreeValues(tempTree, Content.ProblemData.Dataset, rows)
    109                          .LimitToRange(Content.Model.LowerEstimationLimit, Content.Model.UpperEstimationLimit)
    110                          .Median();
    111     }
    112 
    113 
    114     private void SwitchNode(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode oldBranch, ISymbolicExpressionTreeNode newBranch) {
    115       for (int i = 0; i < root.SubtreeCount; i++) {
    116         if (root.GetSubtree(i) == oldBranch) {
    117           root.RemoveSubtree(i);
    118           root.InsertSubtree(i, newBranch);
    119           return;
    120         }
    121       }
    122     }
    123 
    124     protected override void OnModelChanged() {
    125       base.OnModelChanged();
    126       if (Content != null)
    127         btnOptimizeConstants.Enabled =
    128           SymbolicRegressionConstantOptimizationEvaluator.CanOptimizeConstants(Content.Model.SymbolicExpressionTree);
    129       else
    130         btnOptimizeConstants.Enabled = false;
    131     }
    132     protected override void OnContentChanged() {
    133       base.OnContentChanged();
    134       base.OnModelChanged();
    135       if (Content != null)
    136         btnOptimizeConstants.Enabled =
    137           SymbolicRegressionConstantOptimizationEvaluator.CanOptimizeConstants(Content.Model.SymbolicExpressionTree);
    138       else
    139         btnOptimizeConstants.Enabled = false;
    140     }
    141 
    14263
    14364    protected override void btnOptimizeConstants_Click(object sender, EventArgs e) {
    14465      var model = Content.Model;
    145       SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(Content.Model.Interpreter, Content.Model.SymbolicExpressionTree, Content.ProblemData, Content.ProblemData.TrainingIndices,
     66      SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(model.Interpreter, model.SymbolicExpressionTree, Content.ProblemData, Content.ProblemData.TrainingIndices,
    14667        applyLinearScaling: true, maxIterations: 50, upperEstimationLimit: model.UpperEstimationLimit, lowerEstimationLimit: model.LowerEstimationLimit);
    14768      UpdateModel(Content.Model.SymbolicExpressionTree);
Note: See TracChangeset for help on using the changeset viewer.