- Timestamp:
- 07/10/15 15:41:09 (9 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningAnalyzer.cs
r12358 r12720 45 45 46 46 public SymbolicClassificationPruningAnalyzer() { 47 Parameters.Add(new ValueParameter<Symbolic DataAnalysisExpressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicClassificationPruningOperator(new SymbolicClassificationSolutionImpactValuesCalculator())));47 Parameters.Add(new ValueParameter<SymbolicClassificationPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicClassificationPruningOperator(new SymbolicClassificationSolutionImpactValuesCalculator()))); 48 48 } 49 49 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningOperator.cs
r12461 r12720 35 35 public class SymbolicClassificationPruningOperator : SymbolicDataAnalysisExpressionPruningOperator { 36 36 private const string ModelCreatorParameterName = "ModelCreator"; 37 private const string EvaluatorParameterName = "Evaluator"; 37 38 38 39 #region parameter properties 39 40 public ILookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter { 40 41 get { return (ILookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; } 42 } 43 44 public ILookupParameter<ISymbolicClassificationSingleObjectiveEvaluator> EvaluatorParameter { 45 get { 46 return (ILookupParameter<ISymbolicClassificationSingleObjectiveEvaluator>)Parameters[EvaluatorParameterName]; 47 } 41 48 } 42 49 #endregion … … 51 58 : base(impactValuesCalculator) { 52 59 Parameters.Add(new LookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName)); 60 Parameters.Add(new LookupParameter<ISymbolicClassificationSingleObjectiveEvaluator>(EvaluatorParameterName)); 53 61 } 54 62 … … 62 70 63 71 protected override double Evaluate(IDataAnalysisModel model) { 64 var classificationModel = (IClassificationModel)model; 72 var evaluator = EvaluatorParameter.ActualValue; 73 var classificationModel = (ISymbolicClassificationModel)model; 65 74 var classificationProblemData = (IClassificationProblemData)ProblemDataParameter.ActualValue; 66 75 var rows = Enumerable.Range(FitnessCalculationPartitionParameter.ActualValue.Start, FitnessCalculationPartitionParameter.ActualValue.Size); 67 68 return Evaluate(classificationModel, classificationProblemData, rows); 69 } 70 71 private static double Evaluate(IClassificationModel model, IClassificationProblemData problemData, IEnumerable<int> rows) { 72 var estimatedValues = model.GetEstimatedClassValues(problemData.Dataset, rows); 73 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 74 OnlineCalculatorError errorState; 75 var quality = OnlineAccuracyCalculator.Calculate(targetValues, estimatedValues, out errorState); 76 if (errorState != OnlineCalculatorError.None) return double.NaN; 77 return quality; 76 return evaluator.Evaluate(this.ExecutionContext, classificationModel.SymbolicExpressionTree, classificationProblemData, rows); 78 77 } 79 78 … … 86 85 87 86 var nodes = clonedTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList(); 88 double quality = Evaluate(model, problemData, rows);87 double qualityForImpactsCalculation = double.NaN; 89 88 90 89 for (int i = 0; i < nodes.Count; ++i) { … … 92 91 if (node is ConstantTreeNode) continue; 93 92 94 double impactValue, replacementValue ;95 impactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, quality);93 double impactValue, replacementValue, newQualityForImpactsCalculation; 94 impactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, out newQualityForImpactsCalculation, qualityForImpactsCalculation); 96 95 97 96 if (pruneOnlyZeroImpactNodes && !impactValue.IsAlmost(0.0)) continue; … … 104 103 i += node.GetLength() - 1; // skip subtrees under the node that was folded 105 104 106 quality -= impactValue;105 qualityForImpactsCalculation = newQualityForImpactsCalculation; 107 106 } 108 107 return model.SymbolicExpressionTree; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationSolutionImpactValuesCalculator.cs
r12012 r12720 47 47 } 48 48 49 public override double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double originalQuality= double.NaN) {49 public override double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double qualityForImpactsCalculation = double.NaN) { 50 50 double impactValue, replacementValue; 51 CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, originalQuality); 51 double newQualityForImpactsCalculation; 52 CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, out newQualityForImpactsCalculation, qualityForImpactsCalculation); 52 53 return impactValue; 53 54 } 54 55 55 56 public override void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, 56 IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, 57 double originalQuality= Double.NaN) {57 IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation, 58 double qualityForImpactsCalculation = Double.NaN) { 58 59 var classificationModel = (ISymbolicClassificationModel)model; 59 60 var classificationProblemData = (IClassificationProblemData)problemData; 60 61 61 var dataset = classificationProblemData.Dataset; 62 var targetClassValues = dataset.GetDoubleValues(classificationProblemData.TargetVariable, rows); 63 64 OnlineCalculatorError errorState; 65 if (double.IsNaN(originalQuality)) { 66 var originalClassValues = classificationModel.GetEstimatedClassValues(dataset, rows); 67 originalQuality = OnlineAccuracyCalculator.Calculate(targetClassValues, originalClassValues, out errorState); 68 if (errorState != OnlineCalculatorError.None) originalQuality = 0.0; 69 } 62 if (double.IsNaN(qualityForImpactsCalculation)) 63 qualityForImpactsCalculation = CalculateQualityForImpacts(classificationModel, classificationProblemData, rows); 70 64 71 65 replacementValue = CalculateReplacementValue(classificationModel, node, classificationProblemData, rows); … … 81 75 tempModelParentNode.InsertSubtree(i, constantNode); 82 76 77 OnlineCalculatorError errorState; 78 var dataset = classificationProblemData.Dataset; 79 var targetClassValues = dataset.GetDoubleValues(classificationProblemData.TargetVariable, rows); 83 80 var estimatedClassValues = tempModel.GetEstimatedClassValues(dataset, rows); 84 double newQuality= OnlineAccuracyCalculator.Calculate(targetClassValues, estimatedClassValues, out errorState);85 if (errorState != OnlineCalculatorError.None) newQuality = 0.0;81 newQualityForImpactsCalculation = OnlineAccuracyCalculator.Calculate(targetClassValues, estimatedClassValues, out errorState); 82 if (errorState != OnlineCalculatorError.None) newQualityForImpactsCalculation = 0.0; 86 83 87 impactValue = originalQuality - newQuality; 84 impactValue = qualityForImpactsCalculation - newQualityForImpactsCalculation; 85 } 86 87 public static double CalculateQualityForImpacts(ISymbolicClassificationModel model, IClassificationProblemData problemData, IEnumerable<int> rows) { 88 OnlineCalculatorError errorState; 89 var dataset = problemData.Dataset; 90 var targetClassValues = dataset.GetDoubleValues(problemData.TargetVariable, rows); 91 var originalClassValues = model.GetEstimatedClassValues(dataset, rows); 92 var qualityForImpactsCalculation = OnlineAccuracyCalculator.Calculate(targetClassValues, originalClassValues, out errorState); 93 if (errorState != OnlineCalculatorError.None) qualityForImpactsCalculation = 0.0; 94 95 return qualityForImpactsCalculation; 88 96 } 89 97 }
Note: See TracChangeset
for help on using the changeset viewer.