Changeset 8971 for branches/RuntimeOptimizer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views
- Timestamp:
- 11/29/12 09:57:15 (11 years ago)
- Location:
- branches/RuntimeOptimizer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/RuntimeOptimizer
- Property svn:mergeinfo changed
/branches/SlaveShutdown (added) merged: 8944-8945,8949,8951,8953-8954 /trunk/sources (added) merged: 8946-8948,8950,8952,8957,8960,8962-8970
- Property svn:mergeinfo changed
-
branches/RuntimeOptimizer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views merged eligible /trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views merged eligible /branches/Algorithms.GradientDescent/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 5516-5520 /branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 6917-7005 /branches/CloningRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 4656-4721 /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 5700-5808 /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 5471-5808 /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 5815-6180 /branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 4458-4459,4462,4464 /branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 6284-6795 /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 5060 /branches/NET40/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 5138-5162 /branches/ParallelEngine/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 5175-5192 /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 7568-7810 /branches/QAPAlgorithms/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 6350-6627 /branches/Restructure trunk solution/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 6828 /branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 7787-8333 /branches/SlaveShutdown/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 8944-8956 /branches/SuccessProgressAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 5370-5682 /branches/Trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 6829-6865 /branches/VNS/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 5594-5752 /branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 5959-6341
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
branches/RuntimeOptimizer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs
r8736 r8971 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Common;26 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 26 using HeuristicLab.Problems.DataAnalysis.Symbolic.Views; … … 29 28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views { 30 29 public partial class InteractiveSymbolicRegressionSolutionSimplifierView : InteractiveSymbolicDataAnalysisSolutionSimplifierView { 31 private readonly ConstantTreeNode constantNode; 32 private readonly SymbolicExpressionTree tempTree; 30 private readonly SymbolicRegressionSolutionImpactValuesCalculator calculator; 33 31 34 32 public new SymbolicRegressionSolution Content { … … 41 39 InitializeComponent(); 42 40 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(); 49 42 } 50 43 … … 56 49 57 50 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 ); 63 55 } 64 56 65 57 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 ); 94 62 } 95 96 private double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree) {97 // remove old ADFs98 while (tempTree.Root.SubtreeCount > 1) tempTree.Root.RemoveSubtree(1);99 // clone ADFs of source tree100 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 else130 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 else139 btnOptimizeConstants.Enabled = false;140 }141 142 63 143 64 protected override void btnOptimizeConstants_Click(object sender, EventArgs e) { 144 65 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, 146 67 applyLinearScaling: true, maxIterations: 50, upperEstimationLimit: model.UpperEstimationLimit, lowerEstimationLimit: model.LowerEstimationLimit); 147 68 UpdateModel(Content.Model.SymbolicExpressionTree);
Note: See TracChangeset
for help on using the changeset viewer.