Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/17/15 15:56:40 (10 years ago)
Author:
ehopf
Message:

#2361: Removed redundant calculations.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/SensitivityEvaluator/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator.cs

    r12211 r12216  
    3030
    3131namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.SingleObjective {
    32   [Item("Weighted Performance Measures Evaluator", "Calculates the quality a symbolic classification solution based on three weighted measures(normalized mean squared error, false negative rate and false positve rate).")]
     32  [Item("Weighted Performance Measures Evaluator", "Calculates the quality of a symbolic classification solution based on three weighted measures(normalized mean squared error, false negative rate(1-sensitivity) and false positve rate(1-specificity)).")]
    3333  [StorableClass]
    3434  public class SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator : SymbolicClassificationSingleObjectiveEvaluator {
     
    101101                IEnumerable<int> rows, bool applyLinearScaling, ISymbolicClassificationModelCreator modelCreator, double normalizedMeanSquaredErrorWeightingFactor, double falseNegativeRateWeightingFactor, double falsePositiveRateWeightingFactor) {
    102102      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    103       IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     103      IEnumerable<double> targetClassValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    104104      OnlineCalculatorError errorState;
    105105      double nmse;
    106106
    107107      //calculate performance measures
    108       var model = modelCreator.CreateSymbolicClassificationModel(solution, interpreter, lowerEstimationLimit, upperEstimationLimit);
     108      var model = (ISymbolicDiscriminantFunctionClassificationModel)modelCreator.CreateSymbolicClassificationModel(solution, interpreter, lowerEstimationLimit, upperEstimationLimit);
    109109      string positiveClassName = problemData.PositiveClass;
    110       model.RecalculateModelParameters(problemData, rows);
     110      double[] classValues, thresholds;
     111      model.ThresholdCalculator.Calculate(problemData, estimatedValues, targetClassValues, out classValues, out thresholds);
     112      model.SetThresholdsAndClassValues(thresholds, classValues);
    111113      var performanceCalculator = new ClassificationPerformanceMeasuresCalculator(positiveClassName, problemData.GetClassValue(positiveClassName));
    112       var estimatedClassValues = model.GetEstimatedClassValues(problemData.Dataset, rows);
    113       performanceCalculator.Calculate(estimatedClassValues, targetValues);
     114      var estimatedClassValues = model.GetEstimatedClassValues(estimatedValues);
     115      performanceCalculator.Calculate(targetClassValues, estimatedClassValues);
    114116      if (performanceCalculator.ErrorState != OnlineCalculatorError.None)
    115117        return Double.NaN;
     
    119121      if (applyLinearScaling) {
    120122        var nmseCalculator = new OnlineNormalizedMeanSquaredErrorCalculator();
    121         CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, nmseCalculator, problemData.Dataset.Rows);
     123        CalculateWithScaling(targetClassValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, nmseCalculator, problemData.Dataset.Rows);
    122124        errorState = nmseCalculator.ErrorState;
    123125        nmse = nmseCalculator.NormalizedMeanSquaredError;
    124126      } else {
    125127        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    126         nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
     128        nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetClassValues, boundedEstimatedValues, out errorState);
    127129      }
    128130      if (errorState != OnlineCalculatorError.None) return Double.NaN;
Note: See TracChangeset for help on using the changeset viewer.