Changeset 16692 for branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationSolutionImpactValuesCalculator.cs
- Timestamp:
- 03/18/19 17:24:30 (6 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring
- Property svn:ignore
-
old new 24 24 protoc.exe 25 25 obj 26 .vs
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification
- Property svn:mergeinfo changed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationSolutionImpactValuesCalculator.cs
r12720 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 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 … … 40 38 protected SymbolicClassificationSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { } 41 39 42 p ublic override double CalculateReplacementValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows) {40 protected override double CalculateQualityForImpacts(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData, IEnumerable<int> rows) { 43 41 var classificationModel = (ISymbolicClassificationModel)model; 44 42 var classificationProblemData = (IClassificationProblemData)problemData; 45 46 return CalculateReplacementValue(node, classificationModel.SymbolicExpressionTree, classificationModel.Interpreter, classificationProblemData.Dataset, rows);47 }48 49 public override double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double qualityForImpactsCalculation = double.NaN) {50 double impactValue, replacementValue;51 double newQualityForImpactsCalculation;52 CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, out newQualityForImpactsCalculation, qualityForImpactsCalculation);53 return impactValue;54 }55 56 public override void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node,57 IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation,58 double qualityForImpactsCalculation = Double.NaN) {59 var classificationModel = (ISymbolicClassificationModel)model;60 var classificationProblemData = (IClassificationProblemData)problemData;61 62 if (double.IsNaN(qualityForImpactsCalculation))63 qualityForImpactsCalculation = CalculateQualityForImpacts(classificationModel, classificationProblemData, rows);64 65 replacementValue = CalculateReplacementValue(classificationModel, node, classificationProblemData, rows);66 var constantNode = new ConstantTreeNode(new Constant()) { Value = replacementValue };67 68 var cloner = new Cloner();69 var tempModel = cloner.Clone(classificationModel);70 var tempModelNode = (ISymbolicExpressionTreeNode)cloner.GetClone(node);71 72 var tempModelParentNode = tempModelNode.Parent;73 int i = tempModelParentNode.IndexOfSubtree(tempModelNode);74 tempModelParentNode.RemoveSubtree(i);75 tempModelParentNode.InsertSubtree(i, constantNode);76 77 OnlineCalculatorError errorState;78 var dataset = classificationProblemData.Dataset;79 var targetClassValues = dataset.GetDoubleValues(classificationProblemData.TargetVariable, rows);80 var estimatedClassValues = tempModel.GetEstimatedClassValues(dataset, rows);81 newQualityForImpactsCalculation = OnlineAccuracyCalculator.Calculate(targetClassValues, estimatedClassValues, out errorState);82 if (errorState != OnlineCalculatorError.None) newQualityForImpactsCalculation = 0.0;83 84 impactValue = qualityForImpactsCalculation - newQualityForImpactsCalculation;85 }86 87 public static double CalculateQualityForImpacts(ISymbolicClassificationModel model, IClassificationProblemData problemData, IEnumerable<int> rows) {88 43 OnlineCalculatorError errorState; 89 44 var dataset = problemData.Dataset; 90 var targetClassValues = dataset.GetDoubleValues( problemData.TargetVariable, rows);91 var originalClassValues = model.GetEstimatedClassValues(dataset, rows);45 var targetClassValues = dataset.GetDoubleValues(classificationProblemData.TargetVariable, rows); 46 var originalClassValues = classificationModel.GetEstimatedClassValues(dataset, rows); 92 47 var qualityForImpactsCalculation = OnlineAccuracyCalculator.Calculate(targetClassValues, originalClassValues, out errorState); 93 48 if (errorState != OnlineCalculatorError.None) qualityForImpactsCalculation = 0.0; 94 95 49 return qualityForImpactsCalculation; 96 50 }
Note: See TracChangeset
for help on using the changeset viewer.