Changeset 12843 for branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningOperator.cs
- Timestamp:
- 08/11/15 10:11:47 (9 years ago)
- Location:
- branches/HiveStatistics/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources
- Property svn:ignore
-
old new 23 23 bin 24 24 protoc.exe 25 obj
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification
- Property svn:mergeinfo changed
-
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningOperator.cs
r12467 r12843 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)); 61 } 62 63 [StorableHook(HookType.AfterDeserialization)] 64 private void AfterDeserialization() { 65 // BackwardsCompatibility3.3 66 #region Backwards compatible code, remove with 3.4 67 base.ImpactValuesCalculator = new SymbolicClassificationSolutionImpactValuesCalculator(); 68 if (!Parameters.ContainsKey(EvaluatorParameterName)) { 69 Parameters.Add(new LookupParameter<ISymbolicClassificationSingleObjectiveEvaluator>(EvaluatorParameterName)); 70 } 71 #endregion 53 72 } 54 73 … … 62 81 63 82 protected override double Evaluate(IDataAnalysisModel model) { 64 var classificationModel = (IClassificationModel)model; 83 var evaluator = EvaluatorParameter.ActualValue; 84 var classificationModel = (ISymbolicClassificationModel)model; 65 85 var classificationProblemData = (IClassificationProblemData)ProblemDataParameter.ActualValue; 66 86 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; 87 return evaluator.Evaluate(this.ExecutionContext, classificationModel.SymbolicExpressionTree, classificationProblemData, rows); 78 88 } 79 89 … … 86 96 87 97 var nodes = clonedTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList(); 88 double quality = Evaluate(model, problemData, rows);98 double qualityForImpactsCalculation = double.NaN; 89 99 90 100 for (int i = 0; i < nodes.Count; ++i) { … … 92 102 if (node is ConstantTreeNode) continue; 93 103 94 double impactValue, replacementValue ;95 impactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, quality);104 double impactValue, replacementValue, newQualityForImpactsCalculation; 105 impactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, out newQualityForImpactsCalculation, qualityForImpactsCalculation); 96 106 97 107 if (pruneOnlyZeroImpactNodes && !impactValue.IsAlmost(0.0)) continue; … … 104 114 i += node.GetLength() - 1; // skip subtrees under the node that was folded 105 115 106 quality -= impactValue;116 qualityForImpactsCalculation = newQualityForImpactsCalculation; 107 117 } 108 118 return model.SymbolicExpressionTree;
Note: See TracChangeset
for help on using the changeset viewer.