Changeset 16140 for branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationSolutionImpactValuesCalculator.cs
- Timestamp:
- 09/14/18 11:36:59 (6 years ago)
- Location:
- branches/2817-BinPackingSpeedup
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2817-BinPackingSpeedup
- Property svn:mergeinfo changed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification
- Property svn:mergeinfo changed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationSolutionImpactValuesCalculator.cs
r14826 r16140 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6Heuristic 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 public override void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, 43 ISymbolicExpressionTreeNode node, 44 IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, 45 out double newQualityForImpactsCalculation, 46 double qualityForImpactsCalculation = Double.NaN) { 40 protected override double CalculateQualityForImpacts(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData, IEnumerable<int> rows) { 47 41 var classificationModel = (ISymbolicClassificationModel)model; 48 42 var classificationProblemData = (IClassificationProblemData)problemData; 49 50 if (double.IsNaN(qualityForImpactsCalculation))51 qualityForImpactsCalculation = CalculateQualityForImpacts(classificationModel, classificationProblemData, rows);52 53 54 var cloner = new Cloner();55 var tempModel = cloner.Clone(classificationModel);56 var tempModelNode = (ISymbolicExpressionTreeNode)cloner.GetClone(node);57 58 var tempModelParentNode = tempModelNode.Parent;59 int i = tempModelParentNode.IndexOfSubtree(tempModelNode);60 double bestReplacementValue = 0.0;61 double bestImpactValue = double.PositiveInfinity;62 newQualityForImpactsCalculation = qualityForImpactsCalculation; // initialize63 // try the potentially reasonable replacement values and use the best one64 foreach (var repValue in CalculateReplacementValues(node, classificationModel.SymbolicExpressionTree, classificationModel.Interpreter, classificationProblemData.Dataset, classificationProblemData.TrainingIndices)) {65 tempModelParentNode.RemoveSubtree(i);66 67 var constantNode = new ConstantTreeNode(new Constant()) { Value = repValue };68 tempModelParentNode.InsertSubtree(i, constantNode);69 70 var dataset = classificationProblemData.Dataset;71 var targetClassValues = dataset.GetDoubleValues(classificationProblemData.TargetVariable, rows);72 var estimatedClassValues = tempModel.GetEstimatedClassValues(dataset, rows);73 OnlineCalculatorError errorState;74 newQualityForImpactsCalculation = OnlineAccuracyCalculator.Calculate(targetClassValues, estimatedClassValues,75 out errorState);76 if (errorState != OnlineCalculatorError.None) newQualityForImpactsCalculation = 0.0;77 78 impactValue = qualityForImpactsCalculation - newQualityForImpactsCalculation;79 80 if (impactValue < bestImpactValue) {81 bestImpactValue = impactValue;82 bestReplacementValue = repValue;83 }84 }85 replacementValue = bestReplacementValue;86 impactValue = bestImpactValue;87 }88 89 public static double CalculateQualityForImpacts(ISymbolicClassificationModel model, IClassificationProblemData problemData, IEnumerable<int> rows) {90 43 OnlineCalculatorError errorState; 91 44 var dataset = problemData.Dataset; 92 var targetClassValues = dataset.GetDoubleValues( problemData.TargetVariable, rows);93 var originalClassValues = model.GetEstimatedClassValues(dataset, rows);45 var targetClassValues = dataset.GetDoubleValues(classificationProblemData.TargetVariable, rows); 46 var originalClassValues = classificationModel.GetEstimatedClassValues(dataset, rows); 94 47 var qualityForImpactsCalculation = OnlineAccuracyCalculator.Calculate(targetClassValues, originalClassValues, out errorState); 95 48 if (errorState != OnlineCalculatorError.None) qualityForImpactsCalculation = 0.0; 96 97 49 return qualityForImpactsCalculation; 98 50 }
Note: See TracChangeset
for help on using the changeset viewer.