Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/15/15 11:16:05 (10 years ago)
Author:
mkommend
Message:

#2278: Minor code cleanup in classification extensions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Classification-Extensions/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/ClassificationPerformanceMeasuresCalculator.cs

    r11685 r11761  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2624using HeuristicLab.Common;
    2725
     
    3230      this.positiveClassName = positiveClassName;
    3331      this.positiveClassValue = positiveClassValue;
    34       Reset();       
     32      Reset();
    3533    }
    3634
    3735    #region Properties
    38     private string positiveClassName;
    39     private double positiveClassValue;
    4036    private int truePositiveCount, falsePositiveCount, trueNegativeCount, falseNegativeCount;
    4137
     38    private readonly string positiveClassName;
    4239    public string PositiveClassName {
    43       get {
    44         return positiveClassName;
    45       }
     40      get { return positiveClassName; }
    4641    }
     42
     43    private readonly double positiveClassValue;
    4744    public double PositiveClassValue {
    48       get {
    49         return positiveClassValue;
    50       }
     45      get { return positiveClassValue; }
    5146    }
    5247    public double TruePositiveRate {
     
    9287    }
    9388    #endregion
    94                                
     89
    9590    public void Reset() {
    9691      truePositiveCount = 0;
     
    10398    public void Add(double originalClassValue, double estimatedClassValue) {
    10499      // ignore cases where original is NaN completely
    105       if (!double.IsNaN(originalClassValue)) {
    106         if (originalClassValue.IsAlmost(positiveClassValue)
    107               || estimatedClassValue.IsAlmost(positiveClassValue)) { //positive class/positive class estimation
    108           if (estimatedClassValue.IsAlmost(originalClassValue)) {
    109             truePositiveCount++;
    110           } else {
    111             if (estimatedClassValue.IsAlmost(positiveClassValue)) //misclassification of the negative class
    112               falsePositiveCount++;
    113             else //misclassification of the positive class
    114               falseNegativeCount++;
    115           }
    116         } else { //negative class/negative class estimation
    117           //In a multiclass classification all misclassifications of the negative class
    118           //will be treated as true negatives except on positive class estimations
    119           trueNegativeCount++;
     100      if (double.IsNaN(originalClassValue)) return;
     101
     102      if (originalClassValue.IsAlmost(positiveClassValue)
     103            || estimatedClassValue.IsAlmost(positiveClassValue)) { //positive class/positive class estimation
     104        if (estimatedClassValue.IsAlmost(originalClassValue)) {
     105          truePositiveCount++;
     106        } else {
     107          if (estimatedClassValue.IsAlmost(positiveClassValue)) //misclassification of the negative class
     108            falsePositiveCount++;
     109          else //misclassification of the positive class
     110            falseNegativeCount++;
    120111        }
    121         errorState = OnlineCalculatorError.None; // number of (non-NaN) samples >= 1
     112      } else { //negative class/negative class estimation
     113        //In a multiclass classification all misclassifications of the negative class
     114        //will be treated as true negatives except on positive class estimations
     115        trueNegativeCount++;
    122116      }
     117
     118      errorState = OnlineCalculatorError.None; // number of (non-NaN) samples >= 1
    123119    }
    124120
    125     public void Calculate(IEnumerable<double> originalClassValues, IEnumerable<double> estimatedClassValues,
    126                                                                           out OnlineCalculatorError errorState) {
     121    public void Calculate(IEnumerable<double> originalClassValues, IEnumerable<double> estimatedClassValues) {
    127122      IEnumerator<double> originalEnumerator = originalClassValues.GetEnumerator();
    128123      IEnumerator<double> estimatedEnumerator = estimatedClassValues.GetEnumerator();
     
    137132
    138133      // check if both enumerators are at the end to make sure both enumerations have the same length
    139       if (ErrorState == OnlineCalculatorError.None &&
    140           (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) {
     134      if (ErrorState == OnlineCalculatorError.None && (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) {
    141135        throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match.");
    142       } else {
    143         errorState = ErrorState;
    144136      }
     137      errorState = ErrorState;
    145138    }
    146139  }
Note: See TracChangeset for help on using the changeset viewer.