Changeset 8935


Ignore:
Timestamp:
11/22/12 15:03:32 (10 years ago)
Author:
bburlacu
Message:

#1763: Bugfixes and refactoring as suggested in the comments above.

Location:
branches/HeuristicLab.TreeSimplifier
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarEditorView.Designer.cs

    r7967 r8935  
    1 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
    223  partial class SymbolicExpressionGrammarEditorView {
    324    /// <summary>
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs

    r8388 r8935  
    157157    #region events
    158158    public event MouseEventHandler SymbolicExpressionTreeNodeClicked;
    159     protected void OnSymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
     159    protected virtual void OnSymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
    160160      var clicked = SymbolicExpressionTreeNodeClicked;
    161161      if (clicked != null)
     
    163163    }
    164164
    165     protected virtual void SymbolicExpressionTreeChart_MouseClick(object sender, MouseEventArgs e) {
     165    private void SymbolicExpressionTreeChart_MouseClick(object sender, MouseEventArgs e) {
    166166      VisualSymbolicExpressionTreeNode visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y);
    167167      if (visualTreeNode != null) {
     
    171171
    172172    public event MouseEventHandler SymbolicExpressionTreeNodeDoubleClicked;
    173     protected void OnSymbolicExpressionTreeNodeDoubleClicked(object sender, MouseEventArgs e) {
     173    protected virtual void OnSymbolicExpressionTreeNodeDoubleClicked(object sender, MouseEventArgs e) {
    174174      var doubleClicked = SymbolicExpressionTreeNodeDoubleClicked;
    175175      if (doubleClicked != null)
     
    184184
    185185    public event ItemDragEventHandler SymbolicExpressionTreeNodeDrag;
    186     protected void OnSymbolicExpressionTreeNodeDragDrag(object sender, ItemDragEventArgs e) {
     186    protected virtual void OnSymbolicExpressionTreeNodeDragDrag(object sender, ItemDragEventArgs e) {
    187187      var dragged = SymbolicExpressionTreeNodeDrag;
    188188      if (dragged != null)
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/InteractiveSymbolicDiscriminantFunctionClassificationSolutionSimplifierView.cs

    r8916 r8935  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2526
     
    4849
    4950    protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree) {
    50       return calculator.CalculateReplacementValues(tree, Content.Model.Interpreter, Content.ProblemData);
     51      return calculator.CalculateReplacementValues(tree, Content.Model.Interpreter, Content.ProblemData).ToDictionary(x => x.Item1, x => x.Item2);
    5152    }
    5253
    5354    protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree) {
    5455      return calculator.CalculateImpactValues(tree, Content.Model.Interpreter, Content.ProblemData,
    55                                                Content.Model.LowerEstimationLimit, Content.Model.UpperEstimationLimit);
     56                                              Content.Model.LowerEstimationLimit, Content.Model.UpperEstimationLimit).ToDictionary(x => x.Item1, x => x.Item2); ;
    5657    }
    5758
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs

    r8915 r8935  
    1 using System.Collections.Generic;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System.Collections.Generic;
    223using HeuristicLab.Common;
    324using HeuristicLab.Core;
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicDiscriminantFunctionClassificationSolutionImpactValuesCalculator.cs

    r8409 r8935  
    1 using System.Collections.Generic;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
     23using System.Collections.Generic;
    224using System.Linq;
    325using HeuristicLab.Common;
     
    628namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
    729  public class SymbolicDiscriminantFunctionClassificationSolutionImpactValuesCalculator : SymbolicDataAnalysisSolutionImpactValuesCalculator {
    8     public override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree,
    9                                                                                       ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    10                                                                                       IDataAnalysisProblemData problemData) {
    11       var replacementValues = new Dictionary<ISymbolicExpressionTreeNode, double>();
    12       foreach (ISymbolicExpressionTreeNode node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) {
    13         replacementValues[node] = CalculateReplacementValue(node, tree, interpreter, problemData);
    14       }
    15       return replacementValues;
     30    public override IEnumerable<Tuple<ISymbolicExpressionTreeNode, double>> CalculateReplacementValues(ISymbolicExpressionTree tree,
     31                                                                                                       ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     32                                                                                                       IDataAnalysisProblemData problemData) {
     33      return from node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()
     34             select new Tuple<ISymbolicExpressionTreeNode, double>(node, CalculateReplacementValue(node, tree, interpreter, problemData));
    1635    }
    17     public override Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree,
    18                                                                                  ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    19                                                                                  IDataAnalysisProblemData classificationProblemData,
    20                                                                                  double lowerEstimationLimit, double upperEstimationLimit) {
     36
     37    public override IEnumerable<Tuple<ISymbolicExpressionTreeNode, double>> CalculateImpactValues(ISymbolicExpressionTree tree,
     38                                                                                                  ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     39                                                                                                  IDataAnalysisProblemData classificationProblemData,
     40                                                                                                  double lowerEstimationLimit, double upperEstimationLimit) {
    2141      var problemData = (IClassificationProblemData)classificationProblemData;
    2242      var dataset = problemData.Dataset;
    2343      var rows = problemData.TrainingIndices;
    2444      string targetVariable = problemData.TargetVariable;
    25       Dictionary<ISymbolicExpressionTreeNode, double> impactValues = new Dictionary<ISymbolicExpressionTreeNode, double>();
    26       List<ISymbolicExpressionTreeNode> nodes = tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPostfix().ToList();
    27 
    2845      var targetClassValues = dataset.GetDoubleValues(targetVariable, rows);
    29       var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows)
    30         .LimitToRange(lowerEstimationLimit, upperEstimationLimit)
    31         .ToArray();
     46      var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows).LimitToRange(lowerEstimationLimit, upperEstimationLimit).ToArray();
    3247      OnlineCalculatorError errorState;
    3348      double originalGini = NormalizedGiniCalculator.Calculate(targetClassValues, originalOutput, out errorState);
    3449      if (errorState != OnlineCalculatorError.None) originalGini = 0.0;
    3550
    36       foreach (ISymbolicExpressionTreeNode node in nodes) {
    37         var parent = node.Parent;
    38         var constantNode = ((ConstantTreeNode)new Constant().CreateTreeNode());
    39         constantNode.Value = CalculateReplacementValue(node, tree, interpreter, classificationProblemData);
    40         ISymbolicExpressionTreeNode replacementNode = constantNode;
    41         SwitchNode(parent, node, replacementNode);
    42         var newOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows)
    43           .LimitToRange(lowerEstimationLimit, upperEstimationLimit)
    44           .ToArray();
    45         double newGini = NormalizedGiniCalculator.Calculate(targetClassValues, newOutput, out errorState);
    46         if (errorState != OnlineCalculatorError.None) newGini = 0.0;
     51      return from node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPostfix()
     52             select new Tuple<ISymbolicExpressionTreeNode, double>(node, CalculateImpact(tree, originalGini, node, interpreter, problemData, lowerEstimationLimit, upperEstimationLimit));
     53    }
    4754
    48         // impact = 0 if no change
    49         // impact < 0 if new solution is better
    50         // impact > 0 if new solution is worse
    51         impactValues[node] = originalGini - newGini;
    52         SwitchNode(parent, replacementNode, node);
    53       }
    54       return impactValues;
     55    private static double CalculateImpact(ISymbolicExpressionTree tree, double originalQuality, ISymbolicExpressionTreeNode node,
     56                                          ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IClassificationProblemData problemData,
     57                                          double lowerEstimationLimit, double upperEstimationLimit) {
     58      var dataset = problemData.Dataset;
     59      var rows = problemData.TrainingIndices.ToList();
     60      string targetVariable = problemData.TargetVariable;
     61      var targetValues = dataset.GetDoubleValues(targetVariable, rows).ToList();
    5562
     63      var parent = node.Parent;
     64      var constantNode = (ConstantTreeNode)new Constant().CreateTreeNode();
     65      constantNode.Value = CalculateReplacementValue(node, tree, interpreter, problemData);
     66      SwitchNode(parent, node, constantNode);
     67      var newOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows)
     68                                 .LimitToRange(lowerEstimationLimit, upperEstimationLimit)
     69                                 .ToArray();
     70      OnlineCalculatorError errorState;
     71      double quality = NormalizedGiniCalculator.Calculate(targetValues, newOutput, out errorState);
     72      if (errorState != OnlineCalculatorError.None) quality = 0.0;
     73      SwitchNode(parent, constantNode, node);
     74      // impact = 0 if no change
     75      // impact < 0 if new solution is better
     76      // impact > 0 if new solution is worse
     77      return originalQuality - quality;
    5678    }
    5779  }
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs

    r8916 r8935  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2526using HeuristicLab.Problems.DataAnalysis.Symbolic.Views;
     
    4849
    4950    protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree) {
    50       return calculator.CalculateReplacementValues(tree, Content.Model.Interpreter, Content.ProblemData);
     51      return calculator.CalculateReplacementValues(tree, Content.Model.Interpreter, Content.ProblemData).ToDictionary(x => x.Item1, x => x.Item2);
    5152    }
    5253
    5354    protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree) {
    54       return calculator.CalculateImpactValues(tree, Content.Model.Interpreter, Content.ProblemData, 0, 0);
     55      return calculator.CalculateImpactValues(tree, Content.Model.Interpreter, Content.ProblemData,
     56                                              Content.Model.LowerEstimationLimit, Content.Model.UpperEstimationLimit).ToDictionary(x => x.Item1, x => x.Item2);
    5557    }
    5658
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionErrorCharacteristicsCurveView.Designer.cs

    r8100 r8935  
    1 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
    223  partial class SymbolicRegressionSolutionErrorCharacteristicsCurveView {
    324    /// <summary>
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionView.Designer.cs

    r5829 r8935  
    1 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
    223  partial class SymbolicRegressionSolutionView {
    324    /// <summary>
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/VariableTrackbar.Designer.cs

    r7967 r8935  
    1 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
    223  partial class VariableTrackbar {
    324    /// <summary>
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/VariableTrackbar.cs

    r7028 r8935  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Collections.Generic;
    3 using System.ComponentModel;
    4 using System.Drawing;
    5 using System.Data;
    624using System.Linq;
    7 using System.Text;
    825using System.Windows.Forms;
    926using System.Windows.Forms.DataVisualization.Charting;
     
    3855      boxPlotChart.Series["BoxPlot"]["BoxPlotShowMedian"] = "true";
    3956      boxPlotChart.Series["BoxPlot"]["BoxPlotShowUnusualValues"] = "true";
    40       boxPlotChart.ChartAreas[0].AxisY.Minimum = valuesArr.Min() ;
    41       boxPlotChart.ChartAreas[0].AxisY.Maximum = valuesArr.Max() ;
    42      
     57      boxPlotChart.ChartAreas[0].AxisY.Minimum = valuesArr.Min();
     58      boxPlotChart.ChartAreas[0].AxisY.Maximum = valuesArr.Max();
     59
    4360
    4461      trackBar.Minimum = (int)Math.Round(valuesArr.Min() * FACTOR);
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolutionImpactValuesCalculator.cs

    r8409 r8935  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     25using HeuristicLab.Common;
    2426using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2527
    2628namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    2729  public class SymbolicRegressionSolutionImpactValuesCalculator : SymbolicDataAnalysisSolutionImpactValuesCalculator {
    28     public override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree,
    29                                                                                                ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    30                                                                                                IDataAnalysisProblemData problemData) {
    31       var replacementValues = new Dictionary<ISymbolicExpressionTreeNode, double>();
    32       foreach (ISymbolicExpressionTreeNode node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) {
    33         replacementValues[node] = CalculateReplacementValue(node, tree, interpreter, problemData);
    34       }
    35       return replacementValues;
     30    public override IEnumerable<Tuple<ISymbolicExpressionTreeNode, double>> CalculateReplacementValues(ISymbolicExpressionTree tree,
     31                                                                                                       ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     32                                                                                                       IDataAnalysisProblemData problemData) {
     33      return from node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()
     34             select new Tuple<ISymbolicExpressionTreeNode, double>(node, CalculateReplacementValue(node, tree, interpreter, problemData));
    3635    }
    3736
    38     public override Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData regressionProblemData, double lowerEstimationLimit, double upperEstimationLimit) {
     37    public override IEnumerable<Tuple<ISymbolicExpressionTreeNode, double>> CalculateImpactValues(ISymbolicExpressionTree tree,
     38                                                                                                  ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     39                                                                                                  IDataAnalysisProblemData regressionProblemData,
     40                                                                                                  double lowerEstimationLimit, double upperEstimationLimit) {
    3941      var problemData = (IRegressionProblemData)regressionProblemData;
    4042      var dataset = problemData.Dataset;
    4143      var rows = problemData.TrainingIndices.ToList();
    4244      string targetVariable = problemData.TargetVariable;
    43       var impactValues = new Dictionary<ISymbolicExpressionTreeNode, double>();
    4445      List<ISymbolicExpressionTreeNode> nodes = tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPostfix().ToList();
    45       var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows).ToArray();
     46      var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows).LimitToRange(lowerEstimationLimit, upperEstimationLimit).ToArray();
    4647      var targetValues = dataset.GetDoubleValues(targetVariable, rows).ToList();
    4748      OnlineCalculatorError errorState;
     
    4950      if (errorState != OnlineCalculatorError.None) originalR2 = 0.0;
    5051
    51       foreach (ISymbolicExpressionTreeNode node in nodes) {
    52         var parent = node.Parent;
    53         var constantNode = ((ConstantTreeNode)new Constant().CreateTreeNode());
    54         constantNode.Value = CalculateReplacementValue(node, tree, interpreter, problemData);
    55         ISymbolicExpressionTreeNode replacementNode = constantNode;
    56         SwitchNode(parent, node, replacementNode);
    57         var newOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows);
    58         double newR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, newOutput, out errorState);
    59         if (errorState != OnlineCalculatorError.None) newR2 = 0.0;
     52      return from node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPostfix().ToList()
     53             select new Tuple<ISymbolicExpressionTreeNode, double>(node, CalculateImpact(tree, originalR2, node, interpreter, problemData, lowerEstimationLimit, upperEstimationLimit));
     54    }
    6055
    61         // impact = 0 if no change
    62         // impact < 0 if new solution is better
    63         // impact > 0 if new solution is worse
    64         impactValues[node] = originalR2 - newR2;
    65         SwitchNode(parent, replacementNode, node);
    66       }
    67       return impactValues;
     56    private static double CalculateImpact(ISymbolicExpressionTree tree, double originalQuality, ISymbolicExpressionTreeNode node,
     57                                          ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IRegressionProblemData problemData,
     58                                          double lowerEstimationLimit, double upperEstimationLimit) {
     59      var dataset = problemData.Dataset;
     60      var rows = problemData.TrainingIndices.ToList();
     61      string targetVariable = problemData.TargetVariable;
     62      var targetValues = dataset.GetDoubleValues(targetVariable, rows).ToList();
     63
     64      var parent = node.Parent;
     65      var constantNode = (ConstantTreeNode)new Constant().CreateTreeNode();
     66      constantNode.Value = CalculateReplacementValue(node, tree, interpreter, problemData);
     67      SwitchNode(parent, node, constantNode);
     68      var newOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows)
     69                                 .LimitToRange(lowerEstimationLimit, upperEstimationLimit)
     70                                 .ToArray();
     71      OnlineCalculatorError errorState;
     72      double quality = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, newOutput, out errorState);
     73      if (errorState != OnlineCalculatorError.None) quality = 0.0;
     74      SwitchNode(parent, constantNode, node);
     75      // impact = 0 if no change
     76      // impact < 0 if new solution is better
     77      // impact > 0 if new solution is worse
     78      return originalQuality - quality;
    6879    }
    6980  }
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.Designer.cs

    r8916 r8935  
    186186      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    187187      this.Controls.Add(this.splitContainer);
     188      this.DoubleBuffered = true;
    188189      this.Name = "InteractiveSymbolicDataAnalysisSolutionSimplifierView";
    189190      this.Size = new System.Drawing.Size(564, 348);
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r8916 r8935  
    9696      if (Content == null || Content.Model == null || Content.ProblemData == null) return;
    9797      var tree = model;
     98      CalculateReplacementNodesAndNodeImpacts(tree);
     99    }
     100
     101    private void CalculateReplacementNodesAndNodeImpacts(ISymbolicExpressionTree tree) {
    98102      var replacementValues = CalculateReplacementValues(tree);
    99103      foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) {
     
    117121    }
    118122
    119     private void CalculateReplacementNodesAndNodeImpacts(ISymbolicExpressionTree tree) {
    120       var replacementValues = CalculateReplacementValues(tree);
    121       foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) {
    122         replacementNodes[pair.Key] = MakeConstantTreeNode(pair.Value);
    123       }
    124       nodeImpacts = CalculateImpactValues(tree);
    125 
    126       if (!updateInProgress) {
    127         // automatically fold all branches with impact = 0
    128         List<ISymbolicExpressionTreeNode> nodeList = tree.Root.GetSubtree(0).IterateNodesPrefix().ToList();
    129         foreach (var parent in nodeList) {
    130           for (int subTreeIndex = 0; subTreeIndex < parent.SubtreeCount; subTreeIndex++) {
    131             var child = parent.GetSubtree(subTreeIndex);
    132             if (!(child.Symbol is Constant) && nodeImpacts[child].IsAlmost(0.0)) {
    133               SwitchNodeWithReplacementNode(parent, subTreeIndex);
    134             }
    135           }
    136         }
    137       }
    138       PaintModel();
    139     }
    140 
    141123    private void PaintModel() {
    142124      // show only interesting part of solution
     
    149131    protected abstract void UpdateModel(ISymbolicExpressionTree tree);
    150132
    151     private ConstantTreeNode MakeConstantTreeNode(double value) {
    152       Constant constant = new Constant();
    153       constant.MinValue = value - 1;
    154       constant.MaxValue = value + 1;
    155       ConstantTreeNode constantTreeNode = (ConstantTreeNode)constant.CreateTreeNode();
     133    private static ConstantTreeNode MakeConstantTreeNode(double value) {
     134      var constant = new Constant { MinValue = value - 1, MaxValue = value + 1 };
     135      var constantTreeNode = (ConstantTreeNode)constant.CreateTreeNode();
    156136      constantTreeNode.Value = value;
    157137      return constantTreeNode;
     
    164144      if (symbExprTreeNode == null) return;
    165145      var tree = model;
     146
     147      bool update = false;
    166148      // check if the node value/weight has been altered
    167149      // if so, the first double click will return the node to its original value/weight/variable name
     
    171153        variable.VariableName = originalVariableNames[symbExprTreeNode];
    172154        originalVariableNames.Remove(variable);
     155        update = true;
     156      } else if (originalValues.ContainsKey(symbExprTreeNode)) {
     157        double value = originalValues[symbExprTreeNode];
     158        if (symbExprTreeNode.Symbol is Constant) {
     159          var constantTreeNode = (ConstantTreeNode)symbExprTreeNode;
     160          constantTreeNode.Value = value;
     161        } else if (symbExprTreeNode.Symbol is Variable) {
     162          var variable = (VariableTreeNode)symbExprTreeNode;
     163          variable.Weight = value;
     164        }
     165        originalValues.Remove(symbExprTreeNode);
     166        update = true;
     167      } else if (replacementNodes.ContainsKey(symbExprTreeNode)) {
     168        foreach (var treeNode in tree.IterateNodesPostfix()) {
     169          for (int i = 0; i < treeNode.SubtreeCount; i++) {
     170            var subtree = treeNode.GetSubtree(i);
     171            if (subtree == symbExprTreeNode) {
     172              SwitchNodeWithReplacementNode(treeNode, i);
     173              // show only interesting part of solution
     174              treeChart.Tree = tree.Root.SubtreeCount > 1
     175                                 ? new SymbolicExpressionTree(tree.Root)
     176                                 : new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0));
     177              update = true;
     178            }
     179          }
     180          if (update) break;
     181        }
     182      }
     183      if (update) {
    173184        updateInProgress = true;
    174185        UpdateModel(tree);
    175186        updateInProgress = false;
    176         return;
    177       }
    178       if (originalValues.ContainsKey(symbExprTreeNode)) {
    179         double value = originalValues[symbExprTreeNode];
    180         if (symbExprTreeNode.Symbol is Constant)
    181           ((ConstantTreeNode)symbExprTreeNode).Value = value;
    182         else if (symbExprTreeNode.Symbol is Variable)
    183           ((VariableTreeNode)symbExprTreeNode).Weight = value;
    184         originalValues.Remove(symbExprTreeNode);
    185         updateInProgress = true;
    186         UpdateModel(tree);
    187         updateInProgress = false;
    188         return;
    189       }
    190       foreach (SymbolicExpressionTreeNode treeNode in tree.IterateNodesPostfix()) {
    191         for (int i = 0; i < treeNode.SubtreeCount; i++) {
    192           ISymbolicExpressionTreeNode subTree = treeNode.GetSubtree(i);
    193           // only allow to replace nodes for which a replacement value is known (replacement value for ADF nodes are not available)
    194           if (subTree == symbExprTreeNode && replacementNodes.ContainsKey(subTree)) {
    195             SwitchNodeWithReplacementNode(treeNode, i);
    196             // show only interesting part of solution
    197             treeChart.Tree = tree.Root.SubtreeCount > 1 ? new SymbolicExpressionTree(tree.Root) : new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0));
    198             updateInProgress = true;
    199             UpdateModel(tree);
    200             updateInProgress = false;
    201             return; // break all loops
    202           }
    203         }
    204187      }
    205188    }
     
    222205
    223206      if (node is VariableTreeNode) {
    224         var variable = dialog.Content as VariableTreeNode;
    225         var weight = double.Parse(dialog.NewValueTextBox.Text);
    226         var name = (string)dialog.VariableNameComboBox.SelectedItem;
     207        var variable = (VariableTreeNode)node;
     208        var weight = double.Parse(dialog.newValueTextBox.Text);
     209        var name = (string)dialog.variableNamesCombo.SelectedItem;
    227210        if (!variable.Weight.Equals(weight)) {
    228211          flag1 = true;
     
    236219        }
    237220      } else if (node is ConstantTreeNode) {
    238         var constant = dialog.Content as ConstantTreeNode;
    239         var value = double.Parse(dialog.NewValueTextBox.Text);
     221        var constant = (ConstantTreeNode)node;
     222        var value = double.Parse(dialog.newValueTextBox.Text);
    240223        if (!constant.Value.Equals(value)) {
    241224          flag1 = true;
     
    355338      } else if (e.Error != null) {
    356339        // There was an error during the operation.
    357         // Error-handling
    358340      } else {
    359341        // The operation completed normally. We can update the model
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicExpressionTreeChart.Designer.cs

    r8409 r8935  
    1 using System.Windows.Forms;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System.Windows.Forms;
    223
    324namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
     
    2647    /// </summary>
    2748    private void InitializeComponent() {
     49      this.DoubleBuffered = true;
    2850      this.insertNodeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    2951      this.changeValueToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     
    131153      this.pasteToolStripMenuItem.Text = "Paste";
    132154      this.pasteToolStripMenuItem.Click += new System.EventHandler(this.pasteToolStripMenuItem_Clicked);
     155      //
     156      // contextMenuStrip
     157      //
     158      this.contextMenuStrip.Opened += this.contextMenuStrip_Opened;
     159      this.contextMenuStrip.Items.AddRange(new ToolStripItem[] { insertNodeToolStripMenuItem,
     160                                                                 changeValueToolStripMenuItem,
     161                                                                 copyToolStripMenuItem,
     162                                                                 cutToolStripMenuItem,
     163                                                                 deleteToolStripMenuItem,
     164                                                                 pasteToolStripMenuItem });
    133165      //
    134166      // treeStatusLabel
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicExpressionTreeChart.cs

    r8916 r8935  
    4040      InitializeComponent();
    4141      // add extra actions in the context menu strips
    42       this.contextMenuStrip.Opened += this.contextMenuStrip_Opened;
    43       this.contextMenuStrip.Items.AddRange(new ToolStripItem[] {
    44                                                insertNodeToolStripMenuItem,
    45                                                changeValueToolStripMenuItem,
    46                                                copyToolStripMenuItem,
    47                                                cutToolStripMenuItem,
    48                                                deleteToolStripMenuItem,
    49                                                pasteToolStripMenuItem });
     42
     43
    5044      lastSelected = null;
    5145      currSelected = null;
     
    5347    }
    5448
    55     public bool TreeValid {
    56       get { return TreeState.Valid == treeState; }
    57     }
    58 
     49    public bool TreeValid { get { return TreeState.Valid == treeState; } }
    5950    // expose an additional event for signaling to the parent view when the tree structure was modified
    6051    // the emitting of the signal is conditional on the tree being valid, otherwise only a Repaint is issued
     
    6657        treeState = TreeState.Valid;
    6758        var changed = SymbolicExpressionTreeChanged;
    68         if (changed != null) {
     59        if (changed != null)
    6960          changed(sender, e);
    70         }
    7161      } else {
    7262        treeStatusValue.Text = "Invalid";
     
    8070      var menu = sender as ContextMenuStrip;
    8171      if (menu == null) return;
    82       var point = menu.SourceControl.PointToClient(Cursor.Position);
    83       var visualNode = FindVisualSymbolicExpressionTreeNodeAt(point.X, point.Y);
    84       if (visualNode != null) {
    85         lastSelected = currSelected;
    86         if (lastSelected != null) lastSelected.LineColor = Color.Black;
    87         currSelected = visualNode;
    88         currSelected.LineColor = Color.LightGreen;
    89         EnableTreeEditingMenuItems();
    90         OnSymbolicExpressionTreeNodeClicked(currSelected, new MouseEventArgs(MouseButtons.Right, 1, point.X, point.Y, 0));
     72      if (currSelected == null) {
     73        insertNodeToolStripMenuItem.Visible = false;
     74        changeValueToolStripMenuItem.Visible = false;
     75        copyToolStripMenuItem.Visible = false;
     76        cutToolStripMenuItem.Visible = false;
     77        deleteToolStripMenuItem.Visible = false;
     78        pasteToolStripMenuItem.Visible = false;
    9179      } else {
    92         DisableTreeEditingMenuItems();
    93       }
    94     }
    95 
    96     private void DisableTreeEditingMenuItems() {
    97       insertNodeToolStripMenuItem.Visible = false;
    98       changeValueToolStripMenuItem.Visible = false;
    99       copyToolStripMenuItem.Visible = false;
    100       cutToolStripMenuItem.Visible = false;
    101       deleteToolStripMenuItem.Visible = false;
    102       pasteToolStripMenuItem.Visible = false;
    103     }
    104 
    105     private void EnableTreeEditingMenuItems() {
    106 
    107       var node = currSelected.SymbolicExpressionTreeNode;
    108       changeValueToolStripMenuItem.Visible = (node is SymbolicExpressionTreeTerminalNode);
    109       insertNodeToolStripMenuItem.Visible = !changeValueToolStripMenuItem.Visible;
    110       copyToolStripMenuItem.Visible = true;
    111       cutToolStripMenuItem.Visible = true;
    112       deleteToolStripMenuItem.Visible = true;
    113       pasteToolStripMenuItem.Visible = (lastOp == EditOp.CopyNode || lastOp == EditOp.CopySubtree || lastOp == EditOp.CutNode || lastOp == EditOp.CutSubtree) && insertNodeToolStripMenuItem.Visible;
    114     }
    115 
    116 
    117     protected override void SymbolicExpressionTreeChart_MouseClick(object sender, MouseEventArgs e) {
    118       VisualSymbolicExpressionTreeNode visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y);
    119       if (visualTreeNode != null) {
    120         lastSelected = currSelected;
    121         if (lastSelected != null) lastSelected.LineColor = Color.Black;
    122         currSelected = visualTreeNode;
    123         currSelected.LineColor = Color.LightGreen;
    124       }
    125       Repaint();
    126       base.SymbolicExpressionTreeChart_MouseClick(sender, e);
     80        var node = currSelected.SymbolicExpressionTreeNode;
     81        changeValueToolStripMenuItem.Visible = (node is SymbolicExpressionTreeTerminalNode);
     82        insertNodeToolStripMenuItem.Visible = !changeValueToolStripMenuItem.Visible;
     83        copyToolStripMenuItem.Visible = true;
     84        cutToolStripMenuItem.Visible = true;
     85        deleteToolStripMenuItem.Visible = true;
     86        pasteToolStripMenuItem.Visible = tempNode != null && insertNodeToolStripMenuItem.Visible;
     87      }
     88    }
     89
     90    protected override void OnSymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
     91      var visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y);
     92      if (visualTreeNode == null || visualTreeNode == currSelected) return;
     93      lastSelected = currSelected;
     94      if (lastSelected != null)
     95        lastSelected.LineColor = Color.Black;
     96      currSelected = visualTreeNode;
     97      currSelected.LineColor = Color.LightGreen;
     98      Repaint();
     99      base.OnSymbolicExpressionTreeNodeClicked(sender, e);
    127100    }
    128101
     
    131104      var node = currSelected.SymbolicExpressionTreeNode;
    132105
    133       var dialog = new InsertNodeDialog();
    134       dialog.SetAllowedSymbols(node.Grammar.AllowedSymbols.Where(s => s.Enabled && s.InitialFrequency > 0.0 && !(s is ProgramRootSymbol || s is StartSymbol || s is Defun)));
    135       dialog.DialogValidated += OnInsertNodeDialogValidated;
    136       dialog.ShowDialog(this);
     106      using (var dialog = new InsertNodeDialog()) {
     107        dialog.SetAllowedSymbols(node.Grammar.AllowedSymbols.Where(s => s.Enabled && s.InitialFrequency > 0.0 && !(s is ProgramRootSymbol || s is StartSymbol || s is Defun)));
     108        dialog.DialogValidated += InsertNodeDialog_Validated;
     109        dialog.ShowDialog(this);
     110      }
    137111    }
    138112
     
    140114      if (currSelected == null) return;
    141115      var node = currSelected.SymbolicExpressionTreeNode;
    142       var dialog = new ValueChangeDialog();
    143       dialog.SetContent(node);
    144       dialog.DialogValidated += OnChangeValueDialogValidated;
    145       dialog.ShowDialog(this);
     116      using (var dialog = new ValueChangeDialog()) {
     117        dialog.SetContent(node);
     118        dialog.DialogValidated += ChangeValueDialog_Validated;
     119        dialog.ShowDialog(this);
     120      }
    146121    }
    147122
    148123    public event EventHandler SymbolicExpressionTreeNodeChanged;
    149 
    150     private void OnChangeValueDialogValidated(object sender, EventArgs e) {
    151       SymbolicExpressionTreeNodeChanged(sender, e);
    152     }
    153 
    154     private void OnInsertNodeDialogValidated(object sender, EventArgs e) {
     124    private void OnSymbolicExpressionTreeNodeChanged(object sender, EventArgs e) {
     125      var changed = SymbolicExpressionTreeNodeChanged;
     126      if (changed != null)
     127        SymbolicExpressionTreeNodeChanged(sender, e);
     128    }
     129
     130    private void ChangeValueDialog_Validated(object sender, EventArgs e) {
     131      OnSymbolicExpressionTreeNodeChanged(sender, e);
     132    }
     133
     134    private void InsertNodeDialog_Validated(object sender, EventArgs e) {
    155135      var dialog = (InsertNodeDialog)sender;
    156136      var symbol = dialog.SelectedSymbol();
     
    172152          }
    173153        }
    174         // we assume that there is no case in which the parents subtrees get transferred to node, but node doesn't get added as a subtree of parent
    175154      }
    176155      if (parent.Symbol.MaximumArity > parent.SubtreeCount) {
     
    210189      lastOp = EditOp.CopyNode;
    211190      tempNode = currSelected.SymbolicExpressionTreeNode;
    212       var visualNode = visualTreeNodes[tempNode];
    213       visualNode.LineColor = Color.LightGray;
    214       visualNode.TextColor = Color.LightGray;
     191      currSelected.LineColor = Color.LightGray;
     192      currSelected.TextColor = Color.LightGray;
    215193      Repaint();
    216194    }
     
    223201        visualNode.LineColor = Color.LightGray;
    224202        visualNode.TextColor = Color.LightGray;
    225         if (node.SubtreeCount > 0) {
    226           foreach (var subtree in node.Subtrees) {
    227             var visualLine = visualLines[new Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(node, subtree)];
    228             visualLine.LineColor = Color.LightGray;
    229           }
     203        if (node.SubtreeCount <= 0) continue;
     204        foreach (var subtree in node.Subtrees) {
     205          var visualLine = visualLines[new Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(node, subtree)];
     206          visualLine.LineColor = Color.LightGray;
    230207        }
    231208      }
     
    237214      var node = currSelected.SymbolicExpressionTreeNode;
    238215      var parent = node.Parent;
     216      if (parent == null || parent.Symbol is StartSymbol || parent.Symbol is ProgramRootSymbol)
     217        return; // the operation would result in the deletion of the entire tree
    239218      if (parent.Symbol.MaximumArity >= node.SubtreeCount + parent.SubtreeCount - 1) { // -1 because tempNode will be removed
    240219        parent.RemoveSubtree(parent.IndexOfSubtree(node));
     
    244223          parent.AddSubtree(child);
    245224        }
    246       } else {
    247         // if the node cannot be deleted without breaking the tree, do nothing
    248         // TODO: decide what to do
    249       }
     225      }
     226      currSelected = null; // because the currently selected node was just deleted
    250227      OnSymbolicExpressionTreeChanged(sender, e);
    251228    }
     
    255232      var node = currSelected.SymbolicExpressionTreeNode;
    256233      var parent = node.Parent;
     234      if (parent == null || parent.Symbol is StartSymbol || parent.Symbol is ProgramRootSymbol)
     235        return; // the operation makes no sense as it would result in the deletion of the entire tree
    257236      parent.RemoveSubtree(parent.IndexOfSubtree(node));
     237      currSelected = null; // because the currently selected node was just deleted
    258238      OnSymbolicExpressionTreeChanged(sender, e);
    259239    }
     
    270250        switch (lastOp) {
    271251          case (EditOp.CutNode): {
    272               // cut node
     252              // when cutting a node from the tree, it's children become children of it's parent
    273253              var parent = tempNode.Parent;
    274254              // arity checks to see if parent can accept node's children (we assume the grammar is already ok with that)
     255              // (otherise, the 'cut' part of the operation will just not do anything)
    275256              if (parent.Symbol.MaximumArity >= tempNode.SubtreeCount + parent.SubtreeCount - 1) {
    276257                // -1 because tempNode will be removed
     
    282263                }
    283264                lastOp = EditOp.CopyNode;
     265                currSelected = null;
    284266              }
    285267              break;
     
    287269          case (EditOp.CutSubtree): {
    288270              // cut subtree
    289               tempNode.Parent.RemoveSubtree(tempNode.Parent.IndexOfSubtree(tempNode));
    290               lastOp = EditOp.CopySubtree; // do this so the next paste will actually perform a copy
     271              var parent = tempNode.Parent;
     272              parent.RemoveSubtree(parent.IndexOfSubtree(tempNode));
     273              lastOp = EditOp.CopySubtree; // do this so the next paste will actually perform a copy   
     274              currSelected = null;
    291275              break;
    292276            }
    293277          case (EditOp.CopyNode): {
    294278              // copy node
    295               var clone = tempNode.Clone() as ISymbolicExpressionTreeNode; // should never be null
     279              var clone = (SymbolicExpressionTreeNode)tempNode.Clone(); // should never be null
    296280              clone.Parent = tempNode.Parent;
    297281              tempNode = clone;
    298               if (tempNode != null && tempNode.SubtreeCount > 0) {
    299                 for (int i = tempNode.SubtreeCount - 1; i >= 0; --i)
    300                   tempNode.RemoveSubtree(i);
    301               }
     282              for (int i = tempNode.SubtreeCount - 1; i >= 0; --i) tempNode.RemoveSubtree(i);
    302283              break;
    303284            }
    304285          case (EditOp.CopySubtree): {
    305286              // copy subtree
    306               var clone = tempNode.Clone() as ISymbolicExpressionTreeNode;
    307               if (clone != null) {
    308                 clone.Parent = tempNode.Parent;
    309                 tempNode = clone;
    310               }
     287              var clone = (SymbolicExpressionTreeNode)tempNode.Clone();
     288              clone.Parent = tempNode.Parent;
     289              tempNode = clone;
    311290              break;
    312291            }
    313292        }
    314293        node.AddSubtree(tempNode);
    315         Tree = Tree;
    316         // hack in order to trigger the reinitialization of the dictionaries after new nodes appeared in the graph
     294        Tree = Tree; // hack in order to trigger the reinitialization of the dictionaries after new nodes appeared in the graph
    317295        OnSymbolicExpressionTreeChanged(sender, e);
    318       } else {
    319         // throw exception or show a warning to the user about invalid arity
    320296      }
    321297    }
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeNodeChangeValueDialog.Designer.cs

    r8409 r8935  
    5353      this.variableNameLabel = new System.Windows.Forms.Label();
    5454      this.variableNamesCombo = new System.Windows.Forms.ComboBox();
     55      this.okButton = new System.Windows.Forms.Button();
     56      this.cancelButton = new System.Windows.Forms.Button();
    5557      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5658      this.SuspendLayout();
     
    5961      //
    6062      this.originalValueLabel.AutoSize = true;
    61       this.originalValueLabel.Location = new System.Drawing.Point(14, 15);
     63      this.originalValueLabel.Location = new System.Drawing.Point(12, 45);
    6264      this.originalValueLabel.Name = "originalValueLabel";
    6365      this.originalValueLabel.Size = new System.Drawing.Size(72, 13);
     
    6769      // oldValueTextBox
    6870      //
    69       this.oldValueTextBox.Location = new System.Drawing.Point(123, 12);
     71      this.oldValueTextBox.Location = new System.Drawing.Point(123, 42);
    7072      this.oldValueTextBox.Name = "oldValueTextBox";
    7173      this.oldValueTextBox.ReadOnly = true;
     
    7577      // newValueTextBox
    7678      //
    77       this.newValueTextBox.Location = new System.Drawing.Point(123, 38);
     79      this.newValueTextBox.Location = new System.Drawing.Point(123, 82);
    7880      this.newValueTextBox.Name = "newValueTextBox";
    7981      this.newValueTextBox.Size = new System.Drawing.Size(131, 20);
     
    8688      //
    8789      this.newValueLabel.AutoSize = true;
    88       this.newValueLabel.Location = new System.Drawing.Point(14, 41);
     90      this.newValueLabel.Location = new System.Drawing.Point(12, 85);
    8991      this.newValueLabel.Name = "newValueLabel";
    9092      this.newValueLabel.Size = new System.Drawing.Size(59, 13);
     
    101103      //
    102104      this.variableNameLabel.AutoSize = true;
    103       this.variableNameLabel.Location = new System.Drawing.Point(14, 74);
     105      this.variableNameLabel.Location = new System.Drawing.Point(12, 7);
    104106      this.variableNameLabel.Name = "variableNameLabel";
    105107      this.variableNameLabel.Size = new System.Drawing.Size(76, 13);
     
    112114      this.variableNamesCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    113115      this.variableNamesCombo.FormattingEnabled = true;
    114       this.variableNamesCombo.Location = new System.Drawing.Point(123, 71);
     116      this.variableNamesCombo.Location = new System.Drawing.Point(123, 4);
    115117      this.variableNamesCombo.Name = "variableNamesCombo";
    116118      this.variableNamesCombo.Size = new System.Drawing.Size(131, 21);
     
    121123      this.variableNamesCombo.Validated += new System.EventHandler(this.variableNamesCombo_Validated);
    122124      //
     125      // okButton
     126      //
     127      this.okButton.Location = new System.Drawing.Point(15, 119);
     128      this.okButton.Name = "okButton";
     129      this.okButton.Size = new System.Drawing.Size(75, 23);
     130      this.okButton.TabIndex = 8;
     131      this.okButton.Text = "OK";
     132      this.okButton.UseVisualStyleBackColor = true;
     133      this.okButton.Click += new System.EventHandler(this.okButton_Click);
     134      //
     135      // cancelButton
     136      //
     137      this.cancelButton.CausesValidation = false;
     138      this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
     139      this.cancelButton.Location = new System.Drawing.Point(179, 119);
     140      this.cancelButton.Name = "cancelButton";
     141      this.cancelButton.Size = new System.Drawing.Size(75, 23);
     142      this.cancelButton.TabIndex = 9;
     143      this.cancelButton.Text = "Cancel";
     144      this.cancelButton.UseVisualStyleBackColor = true;
     145      this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
     146      //
    123147      // ValueChangeDialog
    124148      //
     
    126150      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    127151      this.AutoSize = true;
    128       this.ClientSize = new System.Drawing.Size(269, 103);
     152      this.CancelButton = this.cancelButton;
     153      this.ClientSize = new System.Drawing.Size(269, 154);
     154      this.ControlBox = false;
     155      this.Controls.Add(this.cancelButton);
     156      this.Controls.Add(this.okButton);
    129157      this.Controls.Add(this.variableNamesCombo);
    130158      this.Controls.Add(this.variableNameLabel);
     
    133161      this.Controls.Add(this.oldValueTextBox);
    134162      this.Controls.Add(this.originalValueLabel);
     163      this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
    135164      this.MaximizeBox = false;
    136165      this.MinimizeBox = false;
     
    151180    private System.Windows.Forms.Label originalValueLabel;
    152181    private System.Windows.Forms.TextBox oldValueTextBox;
    153     private System.Windows.Forms.TextBox newValueTextBox;
    154182    private System.Windows.Forms.Label newValueLabel;
    155183    private System.Windows.Forms.ErrorProvider errorProvider;
    156     private System.Windows.Forms.ComboBox variableNamesCombo;
    157184    private System.Windows.Forms.Label variableNameLabel;
     185    private System.Windows.Forms.Button cancelButton;
     186    private System.Windows.Forms.Button okButton;
     187    public System.Windows.Forms.TextBox newValueTextBox;
     188    public System.Windows.Forms.ComboBox variableNamesCombo;
    158189  }
    159190}
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeNodeChangeValueDialog.cs

    r8916 r8935  
    2929namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    3030  public partial class ValueChangeDialog : Form {
    31     private ISymbolicExpressionTreeNode _content;
     31    private ISymbolicExpressionTreeNode content;
    3232    public ISymbolicExpressionTreeNode Content {
    33       get { return _content; }
     33      get { return content; }
    3434      set {
    3535        if (InvokeRequired)
    36           Invoke(new Action<SymbolicExpressionTreeNode>(x => _content = x), value);
     36          Invoke(new Action<SymbolicExpressionTreeNode>(x => content = x), value);
    3737        else
    38           _content = value;
     38          content = value;
    3939      }
    40     }
    41 
    42     public string Caption {
    43       get { return this.Text; }
    44       set {
    45         if (InvokeRequired)
    46           Invoke(new Action<string>(x => this.Caption = x), value);
    47         else
    48           this.Text = value;
    49       }
    50     }
    51 
    52     public string OldValue {
    53       get { return oldValueTextBox.Text; }
    54       set {
    55         if (InvokeRequired)
    56           Invoke(new Action<string>(x => this.NewValue = x), value);
    57         else
    58           oldValueTextBox.Text = value;
    59       }
    60     }
    61 
    62     public string NewValue {
    63       get { return newValueTextBox.Text; }
    64       set {
    65         if (InvokeRequired)
    66           Invoke(new Action<string>(x => this.NewValue = x), value);
    67         else
    68           newValueTextBox.Text = value;
    69       }
    70     }
    71 
    72     public TextBox NewValueTextBox {
    73       get { return newValueTextBox; }
    74     }
    75 
    76     public ComboBox VariableNameComboBox {
    77       get { return variableNamesCombo; }
    7840    }
    7941
     
    8648      Content = content;
    8749      if (Content is VariableTreeNode) {
    88         Caption = "Change variable name or weight";
     50        this.Text = "Change variable name or weight";
    8951        var variable = Content as VariableTreeNode;
    90         OldValue = Math.Round(variable.Weight, 4).ToString();
    91         NewValue = OldValue;
     52        newValueTextBox.Text = oldValueTextBox.Text = Math.Round(variable.Weight, 4).ToString();
    9253        // add a dropbox containing all the available variable names
    9354        variableNameLabel.Visible = true;
     
    9556        foreach (var name in variable.Symbol.VariableNames) variableNamesCombo.Items.Add(name);
    9657        variableNamesCombo.SelectedIndex = variableNamesCombo.Items.IndexOf(variable.VariableName);
    97         //        variableNamesCombo.SelectedText = variable.VariableName;
    98         //        variableNamesCombo.SelectedIndex = 0;
    9958      } else if (Content is ConstantTreeNode) {
    100         Caption = "Change constant value";
     59        this.Text = "Change constant value";
    10160        var constant = Content as ConstantTreeNode;
    102         OldValue = Math.Round(constant.Value, 4).ToString();
    103         NewValue = OldValue;
     61        newValueTextBox.Text = oldValueTextBox.Text = Math.Round(constant.Value, 4).ToString();
    10462      }
    10563    }
     
    155113      if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) {
    156114        if (!ValidateChildren()) return;
    157         DialogValidated(this, e);
     115        OnDialogValidated(this, e); // emit validated effect
    158116        Close();
    159117      }
     
    161119
    162120    public event EventHandler DialogValidated;
     121    private void OnDialogValidated(object sender, EventArgs e) {
     122      var dialogValidated = DialogValidated;
     123      if (dialogValidated != null)
     124        dialogValidated(sender, e);
     125    }
     126
     127    private void cancelButton_Click(object sender, EventArgs e) {
     128      Close();
     129    }
     130
     131    private void okButton_Click(object sender, EventArgs e) {
     132      if (ValidateChildren()) {
     133        OnDialogValidated(this, e);
     134        Close();
     135      }
     136    }
     137
    163138  }
    164139}
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeNodeInsertDialog.Designer.cs

    r8409 r8935  
    1 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    223  partial class InsertNodeDialog {
    324    /// <summary>
     
    3455      this.constantValueLabel = new System.Windows.Forms.Label();
    3556      this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components);
     57      this.okButton = new System.Windows.Forms.Button();
     58      this.cancelButton = new System.Windows.Forms.Button();
    3659      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    3760      this.SuspendLayout();
     
    7093      //
    7194      this.variableNameLabel.AutoSize = true;
    72       this.variableNameLabel.Location = new System.Drawing.Point(13, 77);
     95      this.variableNameLabel.Location = new System.Drawing.Point(13, 74);
    7396      this.variableNameLabel.Name = "variableNameLabel";
    7497      this.variableNameLabel.Size = new System.Drawing.Size(35, 13);
     
    81104      this.variableNamesCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    82105      this.variableNamesCombo.FormattingEnabled = true;
    83       this.variableNamesCombo.Location = new System.Drawing.Point(120, 74);
     106      this.variableNamesCombo.Location = new System.Drawing.Point(120, 71);
    84107      this.variableNamesCombo.Name = "variableNamesCombo";
    85108      this.variableNamesCombo.Size = new System.Drawing.Size(108, 21);
     
    123146      this.errorProvider.RightToLeft = true;
    124147      //
     148      // okButton
     149      //
     150      this.okButton.Location = new System.Drawing.Point(12, 112);
     151      this.okButton.Name = "okButton";
     152      this.okButton.Size = new System.Drawing.Size(75, 23);
     153      this.okButton.TabIndex = 9;
     154      this.okButton.Text = "OK";
     155      this.okButton.UseVisualStyleBackColor = true;
     156      this.okButton.Click += new System.EventHandler(this.okButton_Click);
     157      //
     158      // cancelButton
     159      //
     160      this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
     161      this.cancelButton.Location = new System.Drawing.Point(153, 112);
     162      this.cancelButton.Name = "cancelButton";
     163      this.cancelButton.Size = new System.Drawing.Size(75, 23);
     164      this.cancelButton.TabIndex = 10;
     165      this.cancelButton.Text = "Cancel";
     166      this.cancelButton.UseVisualStyleBackColor = true;
     167      this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
     168      //
    125169      // InsertNodeDialog
    126170      //
    127171      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    128172      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    129       this.ClientSize = new System.Drawing.Size(240, 107);
     173      this.CancelButton = this.cancelButton;
     174      this.ClientSize = new System.Drawing.Size(240, 147);
     175      this.ControlBox = false;
     176      this.Controls.Add(this.cancelButton);
     177      this.Controls.Add(this.okButton);
    130178      this.Controls.Add(this.constantValueLabel);
    131179      this.Controls.Add(this.constantValueTextBox);
     
    136184      this.Controls.Add(this.allowedSymbolsCombo);
    137185      this.Controls.Add(this.nodeSymbolLabel);
     186      this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
    138187      this.Name = "InsertNodeDialog";
    139188      this.Text = "SymbolicExpressionTreeNodeInsertDialog";
     
    156205    internal System.Windows.Forms.TextBox variableWeightTextBox;
    157206    internal System.Windows.Forms.ComboBox variableNamesCombo;
     207    private System.Windows.Forms.Button cancelButton;
     208    private System.Windows.Forms.Button okButton;
    158209  }
    159210}
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeNodeInsertDialog.cs

    r8409 r8935  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Collections.Generic;
    324using System.ComponentModel;
     
    930namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    1031  public partial class InsertNodeDialog : Form {
    11     public string Caption {
    12       get { return this.Text; }
    13       set {
    14         if (InvokeRequired)
    15           Invoke(new Action<string>(x => this.Caption = x), value);
    16         else
    17           this.Text = value;
    18       }
    19     }
    20 
    2132    public InsertNodeDialog() {
    2233      InitializeComponent();
     
    5566        constantValueTextBox.Visible = false;
    5667        // add controls to the dialog for changing the variable name or weight
     68      } else {
     69        variableNameLabel.Visible = false;
     70        variableNamesCombo.Visible = false;
     71        variableWeightLabel.Visible = false;
     72        variableWeightTextBox.Visible = false;
     73        constantValueLabel.Visible = false;
     74        constantValueTextBox.Visible = false;
    5775      }
    5876    }
     
    90108
    91109    public event EventHandler DialogValidated;
     110    private void OnDialogValidated(object sender, EventArgs e) {
     111      var dialogValidated = DialogValidated;
     112      if (dialogValidated != null)
     113        dialogValidated(sender, e);
     114    }
    92115
    93116    private void childControl_KeyDown(object sender, KeyEventArgs e) {
     
    98121      if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return) {
    99122        if (ValidateChildren()) {
    100           DialogValidated(this, e);
     123          OnDialogValidated(this, e);
    101124          Close();
    102125        }
    103126      }
    104127    }
     128
     129    private void okButton_Click(object sender, EventArgs e) {
     130      if (ValidateChildren()) {
     131        OnDialogValidated(this, e);
     132        Close();
     133      }
     134    }
     135
     136    private void cancelButton_Click(object sender, EventArgs e) {
     137      Close();
     138    }
    105139  }
    106140}
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r8916 r8935  
    204204    <Compile Include="Crossovers\SymbolicDataAnalysisExpressionSemanticSimilarityCrossover.cs" />
    205205    <Compile Include="Interfaces\ISymbolicDataAnalysisExpressionCrossover.cs" />
    206     <Compile Include="Interfaces\ISymbolicDataAnalysisImpactValuesCalculator.cs" />
    207206    <Compile Include="Interpreter\InterpreterState.cs" />
    208207    <Compile Include="Interpreter\OpCodes.cs" />
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSolutionImpactValuesCalculator.cs

    r8916 r8935  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using HeuristicLab.Common;
     
    2526
    2627namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    27   public abstract class SymbolicDataAnalysisSolutionImpactValuesCalculator : ISymbolicDataAnalysisSolutionImpactValuesCalculator {
    28     public abstract Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData);
    29     public abstract Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData, double lowerEstimationLimit, double upperEstimationLimit);
     28  public abstract class SymbolicDataAnalysisSolutionImpactValuesCalculator {
     29    public abstract IEnumerable<Tuple<ISymbolicExpressionTreeNode, double>> CalculateReplacementValues(ISymbolicExpressionTree tree,
     30                                                                                                       ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     31                                                                                                       IDataAnalysisProblemData problemData);
     32    public abstract IEnumerable<Tuple<ISymbolicExpressionTreeNode, double>> CalculateImpactValues(ISymbolicExpressionTree tree,
     33                                                                                                  ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     34                                                                                                  IDataAnalysisProblemData problemData,
     35                                                                                                  double lowerEstimationLimit, double upperEstimationLimit);
    3036
    31     protected void SwitchNode(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode oldBranch, ISymbolicExpressionTreeNode newBranch) {
     37    protected static void SwitchNode(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode oldBranch, ISymbolicExpressionTreeNode newBranch) {
    3238      for (int i = 0; i < root.SubtreeCount; i++) {
    3339        if (root.GetSubtree(i) == oldBranch) {
     
    3945    }
    4046
    41     protected double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData) {
    42       var root = new ProgramRootSymbol().CreateTreeNode();
    43       var start = new StartSymbol().CreateTreeNode();
    44       root.AddSubtree(start);
    45       start.AddSubtree((ISymbolicExpressionTreeNode)node.Clone());
     47    protected static double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree,
     48                                                      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData) {
     49      var rootSymbol = new ProgramRootSymbol().CreateTreeNode();
     50      var startSymbol = new StartSymbol().CreateTreeNode();
     51      rootSymbol.AddSubtree(startSymbol);
     52      startSymbol.AddSubtree((ISymbolicExpressionTreeNode)node.Clone());
    4653      var rows = problemData.TrainingIndices;
    47       var tempTree = new SymbolicExpressionTree(root);
     54      var tempTree = new SymbolicExpressionTree(rootSymbol);
    4855      return interpreter.GetSymbolicExpressionTreeValues(tempTree, problemData.Dataset, rows).Median();
    4956    }
  • branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/LaggedSymbol.cs

    r5809 r8935  
    1 using HeuristicLab.Common;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using HeuristicLab.Common;
    223using HeuristicLab.Core;
    324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
Note: See TracChangeset for help on using the changeset viewer.