Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12216 for branches


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

#2361: Removed redundant calculations.

Location:
branches/SensitivityEvaluator/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/SensitivityEvaluator/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/Interfaces/ISymbolicDiscriminantFunctionClassificationModel.cs

    r12012 r12216  
    2020#endregion
    2121
     22using System.Collections.Generic;
     23
    2224namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
    2325  public interface ISymbolicDiscriminantFunctionClassificationModel : IDiscriminantFunctionClassificationModel, ISymbolicClassificationModel {
    24 
     26    IEnumerable<double> GetEstimatedClassValues(IEnumerable<double> estimatedValues);
    2527  }
    2628}
  • 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;
  • branches/SensitivityEvaluator/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicDiscriminantFunctionClassificationModel.cs

    r12012 r12216  
    123123      }
    124124    }
    125 
     125    public IEnumerable<double> GetEstimatedClassValues(IEnumerable<double> estimatedValues) {
     126      if (!Thresholds.Any() && !ClassValues.Any()) throw new ArgumentException("No thresholds and class values were set for the current symbolic classification model.");
     127      foreach (var x in estimatedValues) {
     128        int classIndex = 0;
     129        // find first threshold value which is larger than x => class index = threshold index + 1
     130        for (int i = 0; i < thresholds.Length; i++) {
     131          if (x > thresholds[i]) classIndex++;
     132          else break;
     133        }
     134        yield return classValues.ElementAt(classIndex - 1);
     135      }
     136    }
    126137
    127138    public override ISymbolicClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
Note: See TracChangeset for help on using the changeset viewer.