Changeset 8946
- Timestamp:
- 11/27/12 11:02:09 (12 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 deleted
- 23 edited
- 9 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic (added) merged: 8388,8391-8392,8395,8409,8915-8916,8935,8937
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification
- Property svn:mergeinfo changed
/branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification merged: 8409,8915-8916,8935
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views
-
Property
svn:mergeinfo
set to
/branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views merged eligible
-
Property
svn:mergeinfo
set to
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/InteractiveSymbolicClassificationSolutionSimplifierView.cs
r8636 r8946 30 30 } 31 31 32 public InteractiveSymbolicClassificationSolutionSimplifierView() : base() { } 32 public InteractiveSymbolicClassificationSolutionSimplifierView() 33 : base() { 34 InitializeComponent(); 35 this.Caption = "Interactive Classification Solution Simplifier"; 36 } 33 37 34 38 protected override void UpdateModel(ISymbolicExpressionTree tree) { -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/InteractiveSymbolicClassificationSolutionSimplifierViewBase.cs
r8727 r8946 29 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views { 30 30 public abstract partial class InteractiveSymbolicClassificationSolutionSimplifierViewBase : InteractiveSymbolicDataAnalysisSolutionSimplifierView { 31 private readonly ConstantTreeNode constantNode; 32 private readonly SymbolicExpressionTree tempTree; 31 private readonly SymbolicClassificationSolutionImpactValuesCalculator calculator; 33 32 34 33 public new ISymbolicClassificationSolution Content { … … 42 41 this.Caption = "Interactive Classification Solution Simplifier"; 43 42 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); 43 calculator = new SymbolicClassificationSolutionImpactValuesCalculator(); 49 44 } 50 45 … … 66 61 67 62 protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree) { 68 Dictionary<ISymbolicExpressionTreeNode, double> replacementValues = new Dictionary<ISymbolicExpressionTreeNode, double>(); 69 foreach (ISymbolicExpressionTreeNode node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) { 70 replacementValues[node] = CalculateReplacementValue(node, tree); 71 } 72 return replacementValues; 63 return tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToDictionary( 64 n => n, 65 n => calculator.CalculateReplacementValue(Content.Model, n, Content.ProblemData, Content.ProblemData.TrainingIndices) 66 ); 73 67 } 74 68 75 69 protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree) { 76 var model = Content.Model; 77 var dataset = Content.ProblemData.Dataset; 78 var rows = Content.ProblemData.TrainingIndices; 79 string targetVariable = Content.ProblemData.TargetVariable; 80 Dictionary<ISymbolicExpressionTreeNode, double> impactValues = new Dictionary<ISymbolicExpressionTreeNode, double>(); 81 List<ISymbolicExpressionTreeNode> nodes = tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPostfix().ToList(); 82 83 var targetClassValues = dataset.GetDoubleValues(targetVariable, rows); 84 var originalClassValues = model.GetEstimatedClassValues(dataset, rows); 85 OnlineCalculatorError errorState; 86 double originalAccuracy = OnlineAccuracyCalculator.Calculate(targetClassValues, originalClassValues, out errorState); 87 if (errorState != OnlineCalculatorError.None) originalAccuracy = 0.0; 88 89 foreach (ISymbolicExpressionTreeNode node in nodes) { 90 var parent = node.Parent; 91 constantNode.Value = CalculateReplacementValue(node, tree); 92 ISymbolicExpressionTreeNode replacementNode = constantNode; 93 SwitchNode(parent, node, replacementNode); 94 var newModel = CreateModel(tree); 95 var newClassValues = newModel.GetEstimatedClassValues(dataset, rows); 96 double newAccuracy = OnlineAccuracyCalculator.Calculate(targetClassValues, newClassValues, out errorState); 97 if (errorState != OnlineCalculatorError.None) newAccuracy = 0.0; 98 99 // impact = 0 if no change 100 // impact < 0 if new solution is better 101 // impact > 0 if new solution is worse 102 impactValues[node] = originalAccuracy - newAccuracy; 103 SwitchNode(parent, replacementNode, node); 104 } 105 return impactValues; 106 } 107 108 private double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree) { 109 // remove old ADFs 110 while (tempTree.Root.SubtreeCount > 1) tempTree.Root.RemoveSubtree(1); 111 // clone ADFs of source tree 112 for (int i = 1; i < sourceTree.Root.SubtreeCount; i++) { 113 tempTree.Root.AddSubtree((ISymbolicExpressionTreeNode)sourceTree.Root.GetSubtree(i).Clone()); 114 } 115 var start = tempTree.Root.GetSubtree(0); 116 while (start.SubtreeCount > 0) start.RemoveSubtree(0); 117 start.AddSubtree((ISymbolicExpressionTreeNode)node.Clone()); 118 var interpreter = Content.Model.Interpreter; 119 var rows = Content.ProblemData.TrainingIndices; 120 return interpreter.GetSymbolicExpressionTreeValues(tempTree, Content.ProblemData.Dataset, rows) 121 .LimitToRange(Content.Model.LowerEstimationLimit, Content.Model.UpperEstimationLimit).Median(); 122 } 123 124 125 private void SwitchNode(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode oldBranch, ISymbolicExpressionTreeNode newBranch) { 126 for (int i = 0; i < root.SubtreeCount; i++) { 127 if (root.GetSubtree(i) == oldBranch) { 128 root.RemoveSubtree(i); 129 root.InsertSubtree(i, newBranch); 130 return; 131 } 132 } 70 return tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToDictionary( 71 n => n, 72 n => calculator.CalculateImpactValue(Content.Model, n, Content.ProblemData, Content.ProblemData.TrainingIndices, Content.TrainingAccuracy) 73 ); 133 74 } 134 75 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/InteractiveSymbolicDiscriminantFunctionClassificationSolutionSimplifierView.cs
r8636 r8946 24 24 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views { 25 25 public partial class InteractiveSymbolicDiscriminantFunctionClassificationSolutionSimplifierView : InteractiveSymbolicClassificationSolutionSimplifierViewBase { 26 27 26 public new SymbolicDiscriminantFunctionClassificationSolution Content { 28 27 get { return (SymbolicDiscriminantFunctionClassificationSolution)base.Content; } … … 30 29 } 31 30 32 public InteractiveSymbolicDiscriminantFunctionClassificationSolutionSimplifierView() : base() { } 31 public InteractiveSymbolicDiscriminantFunctionClassificationSolutionSimplifierView() 32 : base() { 33 InitializeComponent(); 34 this.Caption = "Interactive Classification Solution Simplifier"; 35 } 33 36 34 37 protected override void UpdateModel(ISymbolicExpressionTree tree) { 35 38 var model = CreateModel(tree); 36 model.RecalculateModelParameters(Content.ProblemData, Content.ProblemData.TrainingIndices);37 39 Content.Model = (ISymbolicDiscriminantFunctionClassificationModel)model; 38 40 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4.csproj
r8606 r8946 120 120 <Compile Include="ModelCreators\NormalDistributedThresholdsModelCreator.cs" /> 121 121 <Compile Include="MultiObjective\SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer.cs" /> 122 <Compile Include="SymbolicClassificationSolutionImpactValuesCalculator.cs" /> 122 123 <Compile Include="SymbolicNearestNeighbourClassificationModel.cs" /> 123 124 <Compile Include="Plugin.cs" /> … … 258 259 --> 259 260 <PropertyGroup> 260 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)261 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir) 261 262 set ProjectDir=$(ProjectDir) 262 263 set SolutionDir=$(SolutionDir) … … 265 266 call PreBuildEvent.cmd 266 267 </PreBuildEvent> 267 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">268 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' "> 268 269 export ProjectDir=$(ProjectDir) 269 270 export SolutionDir=$(SolutionDir) -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/Properties
- Property svn:ignore
--- +++
- Property svn:ignore
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationSolutionImpactValuesCalculator.cs
r8942 r8946 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 using System.Linq;25 23 using HeuristicLab.Common; 26 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 25 28 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { 29 public class Symbolic DiscriminantFunctionClassificationSolutionImpactValuesCalculator : SymbolicDataAnalysisSolutionImpactValuesCalculator {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));27 public class SymbolicClassificationSolutionImpactValuesCalculator : SymbolicDataAnalysisSolutionImpactValuesCalculator { 28 public override double CalculateReplacementValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows) { 29 var classificationModel = (ISymbolicClassificationModel)model; 30 var classificationProblemData = (IClassificationProblemData)problemData; 31 32 return CalculateReplacementValue(node, classificationModel.SymbolicExpressionTree, classificationModel.Interpreter, classificationProblemData.Dataset, rows); 35 33 } 36 34 37 public override IEnumerable<Tuple<ISymbolicExpressionTreeNode, double>> CalculateImpactValues(ISymbolicExpressionTree tree, 38 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 39 IDataAnalysisProblemData classificationProblemData, 40 double lowerEstimationLimit, double upperEstimationLimit) { 41 var problemData = (IClassificationProblemData)classificationProblemData; 42 var dataset = problemData.Dataset; 43 var rows = problemData.TrainingIndices; 44 string targetVariable = problemData.TargetVariable; 45 var targetClassValues = dataset.GetDoubleValues(targetVariable, rows); 46 var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows).LimitToRange(lowerEstimationLimit, upperEstimationLimit).ToArray(); 35 public override double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double originalQuality = double.NaN) { 36 var classificationModel = (ISymbolicClassificationModel)model; 37 var classificationProblemData = (IClassificationProblemData)problemData; 38 39 var dataset = classificationProblemData.Dataset; 40 var targetClassValues = dataset.GetDoubleValues(classificationProblemData.TargetVariable, rows); 41 47 42 OnlineCalculatorError errorState; 48 double originalGini = NormalizedGiniCalculator.Calculate(targetClassValues, originalOutput, out errorState); 49 if (errorState != OnlineCalculatorError.None) originalGini = 0.0; 43 if (double.IsNaN(originalQuality)) { 44 var originalClassValues = classificationModel.GetEstimatedClassValues(dataset, rows); 45 originalQuality = OnlineAccuracyCalculator.Calculate(targetClassValues, originalClassValues, out errorState); 46 if (errorState != OnlineCalculatorError.None) originalQuality = 0.0; 47 } 50 48 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)); 49 var replacementValue = CalculateReplacementValue(classificationModel, node, classificationProblemData, rows); 50 var constantNode = new ConstantTreeNode(new Constant()) { Value = replacementValue }; 51 var cloner = new Cloner(); 52 cloner.RegisterClonedObject(node, constantNode); 53 var tempModel = cloner.Clone(classificationModel); 54 tempModel.RecalculateModelParameters(classificationProblemData, rows); 55 56 var estimatedClassValues = tempModel.GetEstimatedClassValues(dataset, rows); 57 double newQuality = OnlineAccuracyCalculator.Calculate(targetClassValues, estimatedClassValues, out errorState); 58 if (errorState != OnlineCalculatorError.None) newQuality = 0.0; 59 60 return originalQuality - newQuality; 53 61 } 54 62 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();62 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 change75 // impact < 0 if new solution is better76 // impact > 0 if new solution is worse77 return originalQuality - quality;78 }79 63 } 80 64 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Property svn:mergeinfo changed
-
trunk/sources/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 /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views 5700-5808
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs
r8736 r8946 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); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Property svn:ignore
-
old new 1 *.user 2 Plugin.cs 1 3 bin 2 *.user3 HeuristicLabProblemsDataAnalysisSymbolicRegressionPlugin.cs4 4 obj 5 *.vs10x6 Plugin.cs
-
- Property svn:ignore
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj
r8895 r8946 143 143 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs" /> 144 144 <Compile Include="SymbolicRegressionSolution.cs" /> 145 <Compile Include="SymbolicRegressionSolutionImpactValuesCalculator.cs" /> 145 146 <None Include="HeuristicLab.snk" /> 146 147 <None Include="Plugin.cs.frame" /> -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Properties
- Property svn:ignore
--- +++
- Property svn:ignore
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolutionImpactValuesCalculator.cs
r8942 r8946 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 using System.Linq;25 23 using HeuristicLab.Common; 26 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 28 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 29 27 public class SymbolicRegressionSolutionImpactValuesCalculator : SymbolicDataAnalysisSolutionImpactValuesCalculator { 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));28 public override double CalculateReplacementValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows) { 29 var regressionModel = (ISymbolicRegressionModel)model; 30 var regressionProblemData = (IRegressionProblemData)problemData; 31 32 return CalculateReplacementValue(node, regressionModel.SymbolicExpressionTree, regressionModel.Interpreter, regressionProblemData.Dataset, rows); 35 33 } 36 34 37 public override IEnumerable<Tuple<ISymbolicExpressionTreeNode, double>> CalculateImpactValues(ISymbolicExpressionTree tree, 38 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 39 IDataAnalysisProblemData regressionProblemData, 40 double lowerEstimationLimit, double upperEstimationLimit) { 41 var problemData = (IRegressionProblemData)regressionProblemData; 42 var dataset = problemData.Dataset; 43 var rows = problemData.TrainingIndices.ToList(); 44 string targetVariable = problemData.TargetVariable; 45 List<ISymbolicExpressionTreeNode> nodes = tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPostfix().ToList(); 46 var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows).LimitToRange(lowerEstimationLimit, upperEstimationLimit).ToArray(); 47 var targetValues = dataset.GetDoubleValues(targetVariable, rows).ToList(); 35 public override double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double originalQuality = double.NaN) { 36 var regressionModel = (ISymbolicRegressionModel)model; 37 var regressionProblemData = (IRegressionProblemData)problemData; 38 39 var dataset = regressionProblemData.Dataset; 40 var targetValues = dataset.GetDoubleValues(regressionProblemData.TargetVariable, rows); 41 48 42 OnlineCalculatorError errorState; 49 double originalR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, originalOutput, out errorState); 50 if (errorState != OnlineCalculatorError.None) originalR2 = 0.0; 43 if (double.IsNaN(originalQuality)) { 44 var originalClassValues = regressionModel.GetEstimatedValues(dataset, rows); 45 originalQuality = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, originalClassValues, out errorState); 46 if (errorState != OnlineCalculatorError.None) originalQuality = 0.0; 47 } 51 48 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)); 49 var replacementValue = CalculateReplacementValue(regressionModel, node, regressionProblemData, rows); 50 var constantNode = new ConstantTreeNode(new Constant()) { Value = replacementValue }; 51 var cloner = new Cloner(); 52 cloner.RegisterClonedObject(node, constantNode); 53 var tempModel = cloner.Clone(regressionModel); 54 SymbolicDataAnalysisModel.Scale(tempModel, regressionProblemData, regressionProblemData.TargetVariable); 55 56 var estimatedValues = tempModel.GetEstimatedValues(dataset, rows); 57 double newQuality = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, estimatedValues, out errorState); 58 if (errorState != OnlineCalculatorError.None) newQuality = 0.0; 59 60 return originalQuality - newQuality; 54 61 } 55 62 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 change76 // impact < 0 if new solution is better77 // impact > 0 if new solution is worse78 return originalQuality - quality;79 }80 63 } 81 64 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views
-
Property
svn:mergeinfo
set to
/branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Views merged eligible
-
Property
svn:mergeinfo
set to
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4
- Property svn:ignore
-
old new 1 *.user 2 Plugin.cs 1 3 bin 2 4 obj 3 *.user4 HeuristicLabProblemsDataAnalysisSymbolicViewsPlugin.cs5 *.vs10x6 Plugin.cs
-
- Property svn:ignore
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj
r8600 r8946 114 114 </ItemGroup> 115 115 <ItemGroup> 116 <Compile Include="InteractiveSymbolicExpressionTreeChart.cs"> 117 <SubType>UserControl</SubType> 118 </Compile> 119 <Compile Include="InteractiveSymbolicExpressionTreeChart.Designer.cs"> 120 <DependentUpon>InteractiveSymbolicExpressionTreeChart.cs</DependentUpon> 121 </Compile> 116 122 <Compile Include="MathSymbolicDataAnalysisModelView.cs"> 117 123 <SubType>UserControl</SubType> … … 121 127 </Compile> 122 128 <Compile Include="Plugin.cs" /> 129 <Compile Include="SymbolicExpressionTreeNodeChangeValueDialog.cs"> 130 <SubType>Form</SubType> 131 </Compile> 132 <Compile Include="SymbolicExpressionTreeNodeChangeValueDialog.Designer.cs"> 133 <DependentUpon>SymbolicExpressionTreeNodeChangeValueDialog.cs</DependentUpon> 134 </Compile> 123 135 <Compile Include="TextualSymbolicDataAnalysisModelView.cs"> 124 136 <SubType>UserControl</SubType> … … 168 180 <Compile Include="Symbols\VariableView.Designer.cs"> 169 181 <DependentUpon>VariableView.cs</DependentUpon> 182 </Compile> 183 <Compile Include="TreeEditDialogs\SymbolicExpressionTreeNodeChangeValueDialog.cs"> 184 <SubType>Form</SubType> 185 </Compile> 186 <Compile Include="TreeEditDialogs\SymbolicExpressionTreeNodeChangeValueDialog.Designer.cs"> 187 <DependentUpon>SymbolicExpressionTreeNodeChangeValueDialog.cs</DependentUpon> 188 </Compile> 189 <Compile Include="TreeEditDialogs\SymbolicExpressionTreeNodeInsertDialog.cs"> 190 <SubType>Form</SubType> 191 </Compile> 192 <Compile Include="TreeEditDialogs\SymbolicExpressionTreeNodeInsertDialog.Designer.cs"> 193 <DependentUpon>SymbolicExpressionTreeNodeInsertDialog.cs</DependentUpon> 170 194 </Compile> 171 195 <None Include="HeuristicLab.snk" /> … … 313 337 --> 314 338 <PropertyGroup> 315 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)339 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir) 316 340 set ProjectDir=$(ProjectDir) 317 341 set SolutionDir=$(SolutionDir) … … 320 344 call PreBuildEvent.cmd 321 345 </PreBuildEvent> 322 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">346 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' "> 323 347 export ProjectDir=$(ProjectDir) 324 348 export SolutionDir=$(SolutionDir) -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.Designer.cs
r8053 r8946 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 this. treeChart = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart();47 this.components = new System.ComponentModel.Container(); 48 48 this.viewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost(); 49 49 this.splitContainer = new System.Windows.Forms.SplitContainer(); … … 52 52 this.btnSimplify = new System.Windows.Forms.Button(); 53 53 this.btnOptimizeConstants = new System.Windows.Forms.Button(); 54 this.treeChart = new HeuristicLab.Problems.DataAnalysis.Symbolic.Views.InteractiveSymbolicExpressionTreeChart(); 54 55 this.grpViewHost = new System.Windows.Forms.GroupBox(); 55 56 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); … … 61 62 this.grpViewHost.SuspendLayout(); 62 63 this.SuspendLayout(); 63 //64 // treeChart65 //66 this.treeChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)67 | System.Windows.Forms.AnchorStyles.Left)68 | System.Windows.Forms.AnchorStyles.Right)));69 this.treeChart.BackgroundColor = System.Drawing.Color.White;70 this.treeChart.LineColor = System.Drawing.Color.Black;71 this.treeChart.Location = new System.Drawing.Point(6, 16);72 this.treeChart.Name = "treeChart";73 this.treeChart.Size = new System.Drawing.Size(201, 291);74 this.treeChart.Spacing = 5;75 this.treeChart.TabIndex = 0;76 this.treeChart.TextFont = new System.Drawing.Font("Times New Roman", 8F);77 this.treeChart.Tree = null;78 this.treeChart.SymbolicExpressionTreeNodeDoubleClicked += new System.Windows.Forms.MouseEventHandler(this.treeChart_SymbolicExpressionTreeNodeDoubleClicked);79 64 // 80 65 // viewHost … … 113 98 // grpSimplify 114 99 // 100 this.grpSimplify.AutoSize = true; 115 101 this.grpSimplify.Controls.Add(this.flowLayoutPanel); 116 102 this.grpSimplify.Controls.Add(this.treeChart); … … 157 143 this.btnOptimizeConstants.Click += new System.EventHandler(this.btnOptimizeConstants_Click); 158 144 // 145 // treeChart 146 // 147 this.treeChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 148 | System.Windows.Forms.AnchorStyles.Left) 149 | System.Windows.Forms.AnchorStyles.Right))); 150 this.treeChart.BackgroundColor = System.Drawing.Color.White; 151 this.treeChart.LineColor = System.Drawing.Color.Black; 152 this.treeChart.Location = new System.Drawing.Point(6, 16); 153 this.treeChart.Name = "treeChart"; 154 this.treeChart.Size = new System.Drawing.Size(201, 291); 155 this.treeChart.Spacing = 5; 156 this.treeChart.SuspendRepaint = false; 157 this.treeChart.TabIndex = 0; 158 this.treeChart.TextFont = new System.Drawing.Font("Times New Roman", 8F); 159 this.treeChart.Tree = null; 160 this.treeChart.SymbolicExpressionTreeChanged += new System.EventHandler(this.treeChart_SymbolicExpressionTreeChanged); 161 this.treeChart.SymbolicExpressionTreeNodeChanged += new System.EventHandler(this.treeChart_SymbolicExpressionTreeNodeChanged); 162 this.treeChart.SymbolicExpressionTreeNodeDoubleClicked += new System.Windows.Forms.MouseEventHandler(this.treeChart_SymbolicExpressionTreeNodeDoubleClicked); 163 // 159 164 // grpViewHost 160 165 // … … 171 176 // 172 177 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 173 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode. Inherit;178 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 174 179 this.Controls.Add(this.splitContainer); 180 this.DoubleBuffered = true; 175 181 this.Name = "InteractiveSymbolicDataAnalysisSolutionSimplifierView"; 176 182 this.Size = new System.Drawing.Size(564, 348); 177 183 this.splitContainer.Panel1.ResumeLayout(false); 184 this.splitContainer.Panel1.PerformLayout(); 178 185 this.splitContainer.Panel2.ResumeLayout(false); 179 186 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); … … 188 195 #endregion 189 196 190 private HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart treeChart;197 private InteractiveSymbolicExpressionTreeChart treeChart; 191 198 private System.Windows.Forms.SplitContainer splitContainer; 192 199 private HeuristicLab.MainForm.WindowsForms.ViewHost viewHost; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r7259 r8946 34 34 private Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> replacementNodes; 35 35 private Dictionary<ISymbolicExpressionTreeNode, double> nodeImpacts; 36 private bool updateInProgress = false; 36 private Dictionary<ISymbolicExpressionTreeNode, double> originalValues; 37 private Dictionary<ISymbolicExpressionTreeNode, string> originalVariableNames; 37 38 38 39 public InteractiveSymbolicDataAnalysisSolutionSimplifierView() { 39 40 InitializeComponent(); 40 this.replacementNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(); 41 this.nodeImpacts = new Dictionary<ISymbolicExpressionTreeNode, double>(); 41 replacementNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(); 42 nodeImpacts = new Dictionary<ISymbolicExpressionTreeNode, double>(); 43 originalValues = new Dictionary<ISymbolicExpressionTreeNode, double>(); 44 originalVariableNames = new Dictionary<ISymbolicExpressionTreeNode, string>(); 45 42 46 this.Caption = "Interactive Solution Simplifier"; 43 47 } … … 50 54 protected override void RegisterContentEvents() { 51 55 base.RegisterContentEvents(); 52 Content.ModelChanged += new EventHandler(Content_ModelChanged);53 Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);56 Content.ModelChanged += Content_Changed; 57 Content.ProblemDataChanged += Content_Changed; 54 58 } 55 59 protected override void DeregisterContentEvents() { 56 60 base.DeregisterContentEvents(); 57 Content.ModelChanged -= new EventHandler(Content_ModelChanged); 58 Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged); 59 } 60 61 private void Content_ModelChanged(object sender, EventArgs e) { 62 OnModelChanged(); 63 } 64 private void Content_ProblemDataChanged(object sender, EventArgs e) { 65 OnProblemDataChanged(); 66 } 67 68 protected virtual void OnModelChanged() { 69 this.CalculateReplacementNodesAndNodeImpacts(); 70 } 71 72 protected virtual void OnProblemDataChanged() { 73 this.CalculateReplacementNodesAndNodeImpacts(); 61 Content.ModelChanged -= Content_Changed; 62 Content.ProblemDataChanged -= Content_Changed; 63 } 64 65 private void Content_Changed(object sender, EventArgs e) { 66 UpdateView(); 74 67 } 75 68 76 69 protected override void OnContentChanged() { 77 70 base.OnContentChanged(); 78 this.CalculateReplacementNodesAndNodeImpacts(); 79 this.viewHost.Content = this.Content; 80 } 81 82 private void CalculateReplacementNodesAndNodeImpacts() { 83 if (Content != null && Content.Model != null && Content.ProblemData != null) { 84 var tree = Content.Model.SymbolicExpressionTree; 85 var replacementValues = CalculateReplacementValues(tree); 86 foreach (var pair in replacementValues) { 87 if (!(pair.Key is ConstantTreeNode)) { 88 replacementNodes[pair.Key] = MakeConstantTreeNode(pair.Value); 89 } 90 } 91 nodeImpacts = CalculateImpactValues(Content.Model.SymbolicExpressionTree); 92 93 if (!updateInProgress) { 94 // automatically fold all branches with impact = 1 95 List<ISymbolicExpressionTreeNode> nodeList = Content.Model.SymbolicExpressionTree.Root.GetSubtree(0).IterateNodesPrefix().ToList(); 96 foreach (var parent in nodeList) { 97 for (int subTreeIndex = 0; subTreeIndex < parent.SubtreeCount; subTreeIndex++) { 98 var child = parent.GetSubtree(subTreeIndex); 99 if (!(child.Symbol is Constant) && nodeImpacts[child].IsAlmost(0.0)) { 100 SwitchNodeWithReplacementNode(parent, subTreeIndex); 101 } 102 } 103 } 104 } 105 106 // show only interesting part of solution 107 if (tree.Root.SubtreeCount > 1) 108 this.treeChart.Tree = new SymbolicExpressionTree(tree.Root); // RPB + ADFs 109 else 110 this.treeChart.Tree = new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); // 1st child of RPB 111 this.PaintNodeImpacts(); 112 } 71 UpdateView(); 72 viewHost.Content = this.Content; 73 } 74 75 private void UpdateView() { 76 if (Content == null || Content.Model == null || Content.ProblemData == null) return; 77 var tree = Content.Model.SymbolicExpressionTree; 78 79 var replacementValues = CalculateReplacementValues(tree); 80 foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) { 81 replacementNodes[pair.Key] = MakeConstantTreeNode(pair.Value); 82 } 83 84 nodeImpacts = CalculateImpactValues(tree); 85 86 var model = Content.Model.SymbolicExpressionTree; 87 treeChart.Tree = model.Root.SubtreeCount > 1 ? new SymbolicExpressionTree(model.Root) : new SymbolicExpressionTree(model.Root.GetSubtree(0).GetSubtree(0)); 88 PaintNodeImpacts(); 113 89 } 114 90 … … 117 93 protected abstract void UpdateModel(ISymbolicExpressionTree tree); 118 94 119 private ConstantTreeNode MakeConstantTreeNode(double value) { 120 Constant constant = new Constant(); 121 constant.MinValue = value - 1; 122 constant.MaxValue = value + 1; 123 ConstantTreeNode constantTreeNode = (ConstantTreeNode)constant.CreateTreeNode(); 95 private static ConstantTreeNode MakeConstantTreeNode(double value) { 96 var constant = new Constant { MinValue = value - 1, MaxValue = value + 1 }; 97 var constantTreeNode = (ConstantTreeNode)constant.CreateTreeNode(); 124 98 constantTreeNode.Value = value; 125 99 return constantTreeNode; … … 127 101 128 102 private void treeChart_SymbolicExpressionTreeNodeDoubleClicked(object sender, MouseEventArgs e) { 129 VisualSymbolicExpressionTreeNode visualTreeNode = (VisualSymbolicExpressionTreeNode)sender; 103 if (!treeChart.TreeValid) return; 104 var visualNode = (VisualSymbolicExpressionTreeNode)sender; 105 var symbExprTreeNode = (SymbolicExpressionTreeNode)visualNode.SymbolicExpressionTreeNode; 106 if (symbExprTreeNode == null) return; 130 107 var tree = Content.Model.SymbolicExpressionTree; 131 foreach (SymbolicExpressionTreeNode treeNode in tree.IterateNodesPostfix()) { 132 for (int i = 0; i < treeNode.SubtreeCount; i++) { 133 ISymbolicExpressionTreeNode subTree = treeNode.GetSubtree(i); 134 // only allow to replace nodes for which a replacement value is known (replacement value for ADF nodes are not available) 135 if (subTree == visualTreeNode.SymbolicExpressionTreeNode && replacementNodes.ContainsKey(subTree)) { 136 SwitchNodeWithReplacementNode(treeNode, i); 137 138 // show only interesting part of solution 139 if (tree.Root.SubtreeCount > 1) 140 this.treeChart.Tree = new SymbolicExpressionTree(tree.Root); // RPB + ADFs 141 else 142 this.treeChart.Tree = new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); // 1st child of RPB 143 144 updateInProgress = true; 145 UpdateModel(tree); 146 updateInProgress = false; 147 return; // break all loops 108 109 bool update = false; 110 // check if the node value/weight has been altered 111 // if so, the first double click will return the node to its original value/weight/variable name 112 // the next double click will replace the ConstantNode with the original SymbolicExpressionTreeNode 113 if (originalVariableNames.ContainsKey(symbExprTreeNode)) { 114 var variable = (VariableTreeNode)symbExprTreeNode; 115 variable.VariableName = originalVariableNames[symbExprTreeNode]; 116 originalVariableNames.Remove(variable); 117 update = true; 118 } else if (originalValues.ContainsKey(symbExprTreeNode)) { 119 double value = originalValues[symbExprTreeNode]; 120 if (symbExprTreeNode.Symbol is Constant) { 121 var constantTreeNode = (ConstantTreeNode)symbExprTreeNode; 122 constantTreeNode.Value = value; 123 } else if (symbExprTreeNode.Symbol is Variable) { 124 var variable = (VariableTreeNode)symbExprTreeNode; 125 variable.Weight = value; 126 } 127 originalValues.Remove(symbExprTreeNode); 128 update = true; 129 } else if (replacementNodes.ContainsKey(symbExprTreeNode)) { 130 foreach (var treeNode in tree.IterateNodesPostfix()) { 131 for (int i = 0; i < treeNode.SubtreeCount; i++) { 132 var subtree = treeNode.GetSubtree(i); 133 if (subtree == symbExprTreeNode) { 134 SwitchNodeWithReplacementNode(treeNode, i); 135 // show only interesting part of solution 136 treeChart.Tree = tree.Root.SubtreeCount > 1 137 ? new SymbolicExpressionTree(tree.Root) 138 : new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); 139 update = true; 140 } 148 141 } 149 } 142 if (update) break; 143 } 144 } 145 if (update) UpdateModel(tree); 146 } 147 148 private void treeChart_SymbolicExpressionTreeChanged(object sender, EventArgs e) { 149 UpdateModel(Content.Model.SymbolicExpressionTree); 150 UpdateView(); 151 } 152 153 private void treeChart_SymbolicExpressionTreeNodeChanged(object sender, EventArgs e) { 154 var dialog = (ValueChangeDialog)sender; 155 bool flag1 = false, flag2 = false; 156 var node = dialog.Content; 157 158 if (node is VariableTreeNode) { 159 var variable = (VariableTreeNode)node; 160 var weight = double.Parse(dialog.newValueTextBox.Text); 161 var name = (string)dialog.variableNamesCombo.SelectedItem; 162 if (!variable.Weight.Equals(weight)) { 163 flag1 = true; 164 originalValues[variable] = variable.Weight; 165 variable.Weight = weight; 166 } 167 if (!variable.VariableName.Equals(name)) { 168 flag2 = true; 169 originalVariableNames[variable] = variable.VariableName; 170 variable.VariableName = name; 171 } 172 } else if (node is ConstantTreeNode) { 173 var constant = (ConstantTreeNode)node; 174 var value = double.Parse(dialog.newValueTextBox.Text); 175 if (!constant.Value.Equals(value)) { 176 flag1 = true; 177 originalValues[constant] = constant.Value; 178 constant.Value = value; 179 } 180 } 181 if (flag1 || flag2) { 182 UpdateView(); 150 183 } 151 184 } … … 168 201 double min = impacts.Min(); 169 202 foreach (ISymbolicExpressionTreeNode treeNode in Content.Model.SymbolicExpressionTree.IterateNodesPostfix()) { 203 VisualSymbolicExpressionTreeNode visualTree = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode); 204 bool flag1 = replacementNodes.ContainsKey(treeNode); 205 bool flag2 = originalValues.ContainsKey(treeNode); 206 bool flag3 = treeNode is ConstantTreeNode; 207 208 if (flag2) // constant or variable node was changed 209 visualTree.ToolTip += Environment.NewLine + "Original value: " + originalValues[treeNode]; 210 else if (flag1 && flag3) // symbol node was folded to a constant 211 visualTree.ToolTip += Environment.NewLine + "Original node: " + replacementNodes[treeNode]; 212 170 213 if (!(treeNode is ConstantTreeNode) && nodeImpacts.ContainsKey(treeNode)) { 171 214 double impact = nodeImpacts[treeNode]; 172 VisualSymbolicExpressionTreeNode visualTree = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode);173 215 174 216 // impact = 0 if no change … … 197 239 private void PaintCollapsedNodes() { 198 240 foreach (ISymbolicExpressionTreeNode treeNode in Content.Model.SymbolicExpressionTree.IterateNodesPostfix()) { 199 if (treeNode is ConstantTreeNode && replacementNodes.ContainsKey(treeNode))200 this.treeChart.GetVisualSymbolicExpressionTreeNode(treeNode).LineColor = Color.DarkOrange;201 else{202 VisualSymbolicExpressionTreeNode visNode = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode);203 if (visNode != null)204 visNode.LineColor = Color.Black;241 bool flag1 = replacementNodes.ContainsKey(treeNode); 242 bool flag2 = originalValues.ContainsKey(treeNode); 243 if (flag1 && treeNode is ConstantTreeNode) { 244 this.treeChart.GetVisualSymbolicExpressionTreeNode(treeNode).LineColor = flag2 ? Color.DarkViolet : Color.DarkOrange; 245 } else if (flag2) { 246 this.treeChart.GetVisualSymbolicExpressionTreeNode(treeNode).LineColor = Color.DodgerBlue; 205 247 } 206 248 } … … 208 250 209 251 private void btnSimplify_Click(object sender, EventArgs e) { 210 SymbolicDataAnalysisExpressionTreeSimplifier simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier();252 var simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier(); 211 253 var simplifiedExpressionTree = simplifier.Simplify(Content.Model.SymbolicExpressionTree); 212 254 UpdateModel(simplifiedExpressionTree); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicExpressionTreeChart.cs
r8942 r8946 28 28 29 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views { 30 public partial class InteractiveSymbolicExpressionTreeChart : SymbolicExpressionTreeChart {30 public sealed partial class InteractiveSymbolicExpressionTreeChart : SymbolicExpressionTreeChart { 31 31 private ISymbolicExpressionTreeNode tempNode; 32 32 private VisualSymbolicExpressionTreeNode lastSelected; // previously selected node … … 163 163 lastOp = EditOp.CutNode; 164 164 tempNode = currSelected.SymbolicExpressionTreeNode; 165 var visualNode = visualTreeNodes[tempNode];165 var visualNode = GetVisualSymbolicExpressionTreeNode(tempNode); 166 166 visualNode.LineColor = Color.LightGray; 167 167 visualNode.TextColor = Color.LightGray; … … 173 173 tempNode = currSelected.SymbolicExpressionTreeNode; // should never be null 174 174 foreach (var node in tempNode.IterateNodesPostfix()) { 175 var visualNode = visualTreeNodes[node];175 var visualNode = GetVisualSymbolicExpressionTreeNode(node); 176 176 visualNode.LineColor = Color.LightGray; 177 177 visualNode.TextColor = Color.LightGray; 178 178 if (node.SubtreeCount > 0) { 179 179 foreach (var subtree in node.Subtrees) { 180 var visualLine = visualLines[new Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(node, subtree)];180 var visualLine = GetVisualSymbolicExpressionTreeNodeConnection(node, subtree); 181 181 visualLine.LineColor = Color.LightGray; 182 182 } … … 198 198 tempNode = currSelected.SymbolicExpressionTreeNode; 199 199 foreach (var node in tempNode.IterateNodesPostfix()) { 200 var visualNode = visualTreeNodes[node];200 var visualNode = GetVisualSymbolicExpressionTreeNode(node); 201 201 visualNode.LineColor = Color.LightGray; 202 202 visualNode.TextColor = Color.LightGray; 203 203 if (node.SubtreeCount <= 0) continue; 204 204 foreach (var subtree in node.Subtrees) { 205 var visualLine = visualLines[new Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(node, subtree)];205 var visualLine = GetVisualSymbolicExpressionTreeNodeConnection(node, subtree); 206 206 visualLine.LineColor = Color.LightGray; 207 207 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Properties
- Property svn:ignore
--- +++
- Property svn:ignore
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Property svn:ignore
-
old new 1 *.user 2 Plugin.cs 1 3 bin 2 *.user3 HeuristicLabProblemsDataAnalysisSymbolicPlugin.cs4 4 obj 5 *.vs10x6 Plugin.cs
-
- Property svn:ignore
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r8895 r8946 140 140 <Compile Include="Crossovers\SymbolicDataAnalysisExpressionSemanticSimilarityCrossover.cs" /> 141 141 <Compile Include="Interfaces\ISymbolicDataAnalysisExpressionCrossover.cs" /> 142 <Compile Include="Interfaces\ISymbolicDataAnalysisImpactValuesCalculator.cs" /> 142 143 <Compile Include="Interpreter\InterpreterState.cs" /> 143 144 <Compile Include="Interpreter\OpCodes.cs" /> … … 164 165 <Compile Include="SymbolicDataAnalysisExpressionTreeSimplifier.cs" /> 165 166 <Compile Include="SymbolicDataAnalysisProblem.cs" /> 167 <Compile Include="SymbolicDataAnalysisSolutionImpactValuesCalculator.cs" /> 166 168 <Compile Include="Symbols\Addition.cs" /> 167 169 <Compile Include="Symbols\And.cs" /> -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisImpactValuesCalculator.cs
r8942 r8946 4 4 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 5 5 public interface ISymbolicDataAnalysisSolutionImpactValuesCalculator { 6 Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree, 7 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 8 IDataAnalysisProblemData problemData); 9 Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree, 10 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 11 IDataAnalysisProblemData problemData, 12 double lowerEstimationLimit, double upperEstimationLimit); 6 double CalculateReplacementValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows); 7 double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double originalQuality = double.NaN); 13 8 } 14 9 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Properties
- Property svn:ignore
--- +++
- Property svn:ignore
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSolutionImpactValuesCalculator.cs
r8942 r8946 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using HeuristicLab.Common; … … 26 25 27 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 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); 27 public abstract class SymbolicDataAnalysisSolutionImpactValuesCalculator : ISymbolicDataAnalysisSolutionImpactValuesCalculator { 28 public abstract double CalculateReplacementValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows); 29 public abstract double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double originalQuality = double.NaN); 36 30 37 protected static void SwitchNode(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode oldBranch, ISymbolicExpressionTreeNode newBranch) { 38 for (int i = 0; i < root.SubtreeCount; i++) { 39 if (root.GetSubtree(i) == oldBranch) { 40 root.RemoveSubtree(i); 41 root.InsertSubtree(i, newBranch); 42 return; 43 } 44 } 45 } 31 protected static double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 32 Dataset dataset, IEnumerable<int> rows) { 33 //optimization: constant nodes return always the same value 34 ConstantTreeNode constantNode = node as ConstantTreeNode; 35 if (constantNode != null) return constantNode.Value; 46 36 47 protected static double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree,48 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData) {49 37 var rootSymbol = new ProgramRootSymbol().CreateTreeNode(); 50 38 var startSymbol = new StartSymbol().CreateTreeNode(); 51 39 rootSymbol.AddSubtree(startSymbol); 52 40 startSymbol.AddSubtree((ISymbolicExpressionTreeNode)node.Clone()); 53 var rows = problemData.TrainingIndices; 41 54 42 var tempTree = new SymbolicExpressionTree(rootSymbol); 55 return interpreter.GetSymbolicExpressionTreeValues(tempTree, problemData.Dataset, rows).Median(); 43 // clone ADFs of source tree 44 for (int i = 1; i < sourceTree.Root.SubtreeCount; i++) { 45 tempTree.Root.AddSubtree((ISymbolicExpressionTreeNode)sourceTree.Root.GetSubtree(i).Clone()); 46 } 47 return interpreter.GetSymbolicExpressionTreeValues(tempTree, dataset, rows).Median(); 56 48 } 57 49 }
Note: See TracChangeset
for help on using the changeset viewer.