- Timestamp:
- 03/28/18 17:41:20 (7 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationSolutionImpactValuesCalculator.cs
r15583 r15871 43 43 OnlineCalculatorError errorState; 44 44 var dataset = problemData.Dataset; 45 classificationModel.RecalculateModelParameters(classificationProblemData, rows); 45 46 var targetClassValues = dataset.GetDoubleValues(classificationProblemData.TargetVariable, rows); 46 47 var originalClassValues = classificationModel.GetEstimatedClassValues(dataset, rows); -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSolutionImpactValuesCalculator.cs
r15583 r15871 40 40 out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation, 41 41 double qualityForImpactsCalculation = double.NaN) { 42 if (double.IsNaN(qualityForImpactsCalculation))43 qualityForImpactsCalculation = CalculateQualityForImpacts(model, problemData, rows);44 42 45 43 var cloner = new Cloner(); 46 44 var tempModel = cloner.Clone(model); 45 46 if (double.IsNaN(qualityForImpactsCalculation)) { 47 qualityForImpactsCalculation = CalculateQualityForImpacts(tempModel, problemData, rows); 48 } 49 47 50 var tempModelNode = (ISymbolicExpressionTreeNode)cloner.GetClone(node); 48 49 51 var tempModelParentNode = tempModelNode.Parent; 50 52 int i = tempModelParentNode.IndexOfSubtree(tempModelNode); … … 54 56 newQualityForImpactsCalculation = qualityForImpactsCalculation; // initialize 55 57 // try the potentially reasonable replacement values and use the best one 56 foreach (var repValue in CalculateReplacementValues(node, model.SymbolicExpressionTree, model.Interpreter, problemData.Dataset, problemData.TrainingIndices)) {58 foreach (var repValue in CalculateReplacementValues(node, model.SymbolicExpressionTree, model.Interpreter, problemData.Dataset, rows)) { 57 59 tempModelParentNode.RemoveSubtree(i); 58 60 -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionVariableImpactsCalculator.cs
r15674 r15871 100 100 var problemData = solution.ProblemData; 101 101 var dataset = problemData.Dataset; 102 var model = (IClassificationModel)solution.Model.Clone(); //mkommend: clone of model is necessary, because the thresholds for IDiscriminantClassificationModels are updated 102 103 103 104 IEnumerable<int> rows; … … 137 138 // calculate impacts for double variables 138 139 foreach (var inputVariable in allowedInputVariables.Where(problemData.Dataset.VariableHasType<double>)) { 139 var newEstimates = EvaluateModelWithReplacedVariable( solution.Model, inputVariable, modifiableDataset, rows, replacementMethod);140 var newEstimates = EvaluateModelWithReplacedVariable(model, inputVariable, modifiableDataset, rows, replacementMethod); 140 141 var newAccuracy = OnlineAccuracyCalculator.Calculate(targetValues, newEstimates, out error); 141 142 if (error != OnlineCalculatorError.None) throw new InvalidOperationException("Error during R² calculation with replaced inputs."); … … 150 151 var smallestImpact = double.PositiveInfinity; 151 152 foreach (var repl in problemData.Dataset.GetStringValues(inputVariable, rows).Distinct()) { 152 var newEstimates = EvaluateModelWithReplacedVariable( solution.Model, inputVariable, modifiableDataset, rows,153 var newEstimates = EvaluateModelWithReplacedVariable(model, inputVariable, modifiableDataset, rows, 153 154 Enumerable.Repeat(repl, dataset.Rows)); 154 155 var newAccuracy = OnlineAccuracyCalculator.Calculate(targetValues, newEstimates, out error); … … 164 165 // calculate impacts for factor variables 165 166 166 var newEstimates = EvaluateModelWithReplacedVariable( solution.Model, inputVariable, modifiableDataset, rows,167 var newEstimates = EvaluateModelWithReplacedVariable(model, inputVariable, modifiableDataset, rows, 167 168 factorReplacementMethod); 168 169 var newAccuracy = OnlineAccuracyCalculator.Calculate(targetValues, newEstimates, out error); … … 263 264 var originalValues = dataset.GetReadOnlyDoubleValues(variable).ToList(); 264 265 dataset.ReplaceVariable(variable, replacementValues.ToList()); 266 267 var discModel = model as IDiscriminantFunctionClassificationModel; 268 if (discModel != null) { 269 var problemData = new ClassificationProblemData(dataset, dataset.VariableNames, model.TargetVariable); 270 discModel.RecalculateModelParameters(problemData, rows); 271 } 272 265 273 //mkommend: ToList is used on purpose to avoid lazy evaluation that could result in wrong estimates due to variable replacements 266 274 var estimates = model.GetEstimatedClassValues(dataset, rows).ToList(); … … 273 281 var originalValues = dataset.GetReadOnlyStringValues(variable).ToList(); 274 282 dataset.ReplaceVariable(variable, replacementValues.ToList()); 283 284 285 var discModel = model as IDiscriminantFunctionClassificationModel; 286 if (discModel != null) { 287 var problemData = new ClassificationProblemData(dataset, dataset.VariableNames, model.TargetVariable); 288 discModel.RecalculateModelParameters(problemData, rows); 289 } 290 275 291 //mkommend: ToList is used on purpose to avoid lazy evaluation that could result in wrong estimates due to variable replacements 276 292 var estimates = model.GetEstimatedClassValues(dataset, rows).ToList();
Note: See TracChangeset
for help on using the changeset viewer.