Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11761


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

#2278: Minor code cleanup in classification extensions.

Location:
branches/Classification-Extensions
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/Classification-Extensions/HeuristicLab.Optimization/3.3/ResultCollection.cs

    r11718 r11761  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using System.Linq;
    2726
    28 namespace HeuristicLab.Optimization {   
     27namespace HeuristicLab.Optimization {
    2928  [StorableClass]
    3029  [Item("ResultCollection", "Represents a collection of results.")]
     
    4746
    4847    public virtual void CollectResultValues(IDictionary<string, IItem> values) {
    49       CollectResultValues(values, string.Empty); 
     48      CollectResultValues(values, string.Empty);
    5049    }
    5150
     
    6766      if (result.Value == null) yield break;
    6867      yield return new KeyValuePair<string, IItem>(string.Empty, result.Value);
     68
    6969      var resultCollection = result.Value as ResultCollection;
    70       if (resultCollection != null) {       
     70      if (resultCollection != null) {
    7171        var children = new Dictionary<string, IItem>();
    7272        resultCollection.CollectResultValues(children);
  • branches/Classification-Extensions/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionBase.cs

    r11685 r11761  
    128128      TestNormalizedGiniCoefficient = testNormalizedGini;
    129129
    130       trainingPerformanceCalculator.Calculate(originalTrainingClassValues, estimatedTrainingClassValues, out errorState);
    131       if (errorState == OnlineCalculatorError.None)
     130      trainingPerformanceCalculator.Calculate(originalTrainingClassValues, estimatedTrainingClassValues);
     131      if (trainingPerformanceCalculator.ErrorState == OnlineCalculatorError.None)
    132132        ClassificationPerformanceMeasures.SetTrainingResults(trainingPerformanceCalculator);
    133       testPerformanceCalculator.Calculate(originalTestClassValues, estimatedTestClassValues, out errorState);
    134       if (errorState == OnlineCalculatorError.None)
     133
     134      testPerformanceCalculator.Calculate(originalTestClassValues, estimatedTestClassValues);
     135      if (testPerformanceCalculator.ErrorState == OnlineCalculatorError.None)
    135136        ClassificationPerformanceMeasures.SetTestResults(testPerformanceCalculator);
    136137    }
  • 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.