Changeset 15321 for branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Timestamp:
- 08/10/17 17:16:07 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolutionImpactValuesCalculator.cs
r14826 r15321 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;27 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 26 … … 32 30 public class SymbolicRegressionSolutionImpactValuesCalculator : SymbolicDataAnalysisSolutionImpactValuesCalculator { 33 31 public SymbolicRegressionSolutionImpactValuesCalculator() { } 34 35 32 protected SymbolicRegressionSolutionImpactValuesCalculator(SymbolicRegressionSolutionImpactValuesCalculator original, Cloner cloner) 36 33 : base(original, cloner) { } … … 38 35 return new SymbolicRegressionSolutionImpactValuesCalculator(this, cloner); 39 36 } 40 41 37 [StorableConstructor] 42 38 protected SymbolicRegressionSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { } 43 39 44 public override void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, 45 IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation, 46 double qualityForImpactsCalculation = double.NaN) { 40 protected override double CalculateQualityForImpacts(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData, IEnumerable<int> rows) { 47 41 var regressionModel = (ISymbolicRegressionModel)model; 48 42 var regressionProblemData = (IRegressionProblemData)problemData; 49 50 var dataset = regressionProblemData.Dataset; 51 var targetValues = dataset.GetDoubleValues(regressionProblemData.TargetVariable, rows); 52 53 if (double.IsNaN(qualityForImpactsCalculation)) 54 qualityForImpactsCalculation = CalculateQualityForImpacts(regressionModel, regressionProblemData, rows); 55 56 var cloner = new Cloner(); 57 var tempModel = cloner.Clone(regressionModel); 58 var tempModelNode = (ISymbolicExpressionTreeNode)cloner.GetClone(node); 59 60 var tempModelParentNode = tempModelNode.Parent; 61 int i = tempModelParentNode.IndexOfSubtree(tempModelNode); 62 63 double bestReplacementValue = 0.0; 64 double bestImpactValue = double.PositiveInfinity; 65 newQualityForImpactsCalculation = qualityForImpactsCalculation; // initialize 66 // try the potentially reasonable replacement values and use the best one 67 foreach (var repValue in CalculateReplacementValues(node, regressionModel.SymbolicExpressionTree, regressionModel.Interpreter, regressionProblemData.Dataset, regressionProblemData.TrainingIndices)) { 68 69 tempModelParentNode.RemoveSubtree(i); 70 71 var constantNode = new ConstantTreeNode(new Constant()) { Value = repValue }; 72 73 tempModelParentNode.InsertSubtree(i, constantNode); 74 75 var estimatedValues = tempModel.GetEstimatedValues(dataset, rows); 76 OnlineCalculatorError errorState; 77 double r = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState); 78 if (errorState != OnlineCalculatorError.None) r = 0.0; 79 newQualityForImpactsCalculation = r * r; 80 81 impactValue = qualityForImpactsCalculation - newQualityForImpactsCalculation; 82 if (impactValue < bestImpactValue) { 83 bestImpactValue = impactValue; 84 bestReplacementValue = repValue; 85 } 86 } 87 replacementValue = bestReplacementValue; 88 impactValue = bestImpactValue; 89 } 90 91 public static double CalculateQualityForImpacts(ISymbolicRegressionModel model, IRegressionProblemData problemData, IEnumerable<int> rows) { 92 var estimatedValues = model.GetEstimatedValues(problemData.Dataset, rows); // also bounds the values 93 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 43 var estimatedValues = regressionModel.GetEstimatedValues(problemData.Dataset, rows); // also bounds the values 44 var targetValues = problemData.Dataset.GetDoubleValues(regressionProblemData.TargetVariable, rows); 94 45 OnlineCalculatorError errorState; 95 46 var r = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState);
Note: See TracChangeset
for help on using the changeset viewer.