- Timestamp:
- 11/27/12 11:02:09 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Files:
-
- 4 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Property svn:mergeinfo changed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.