Free cookie consent management tool by TermsFeed Policy Generator

Changeset 672


Ignore:
Timestamp:
10/15/08 17:26:00 (16 years ago)
Author:
mkommend
Message:

division error corrected (ticket #308)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/ROCAnalyzer.cs

    r669 r672  
    3939      : base() {
    4040      AddVariableInfo(new VariableInfo("Values", "Item list holding the estimated and orignial values for the ROCAnalyzer", typeof(ItemList), VariableKind.In));
    41       AddVariableInfo(new VariableInfo("ROCValues", "The values of the ROCAnalyzer, namely TPR & FPR", typeof(ItemList), VariableKind.New | VariableKind.Out));
     41      AddVariableInfo(new VariableInfo("ROCValues", "The values of the ROCAnalyzer, namely TPR & FPR", typeof(ItemList<ItemList<DoubleArrayData>>), VariableKind.New | VariableKind.Out));
    4242    }
    4343
    4444    public override IOperation Apply(IScope scope) {
    4545      ItemList values = GetVariableValue<ItemList>("Values", scope, true);
    46       ItemList rocValues = GetVariableValue<ItemList>("ROCValues", scope, false, false);
     46      ItemList<ItemList<DoubleArrayData>> rocValues = GetVariableValue<ItemList<ItemList<DoubleArrayData>>>("ROCValues", scope, false, false);
    4747      if (rocValues == null) {
    48         rocValues = new ItemList();
     48        rocValues = new ItemList<ItemList<DoubleArrayData>>();
    4949        IVariableInfo info = GetVariableInfo("ROCValues");
    5050        if (info.Local)
     
    5252        else
    5353          scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(info.FormalName), rocValues));
    54       } else
     54      } else {
    5555        rocValues.Clear();
     56      }
    5657
     58      rocValues.Add(new ItemList<DoubleArrayData>());
    5759      //ROC Curve starts at 0,0
    58       ItemList row = new ItemList();
    59       row.Add(new DoubleData(0));
    60       row.Add(new DoubleData(0));
    61       rocValues.Add(row);
     60      DoubleArrayData point = new DoubleArrayData();
     61      point.Data = new double[2] { 0, 0 };
     62      rocValues[0].Add(point);
    6263
    6364      //calculate new ROC Values
    64       double estimated=0.0;
    65       double original=0.0;
     65      double estimated = 0.0;
     66      double original = 0.0;
    6667      double positiveClassKey;
    6768      double negativeClassKey;
    68       double truePositiveRate=0.0;
    69       double falsePositiveRate=0.0;
     69      double truePositiveRate = 0.0;
     70      double falsePositiveRate = 0.0;
    7071
    7172      //initialize classes dictionary
     
    9091      positiveClassKey = classes.Keys.Min<double>();
    9192      negativeClassKey = classes.Keys.Max<double>();
    92       for (int i = 0; i < classes[negativeClassKey].Count; i++) {
    93         truePositiveRate = classes[positiveClassKey].Count<double>(value => value < classes[negativeClassKey][i]) / classes[positiveClassKey].Count;
    94         falsePositiveRate = i / classes[negativeClassKey].Count;
    95         row = new ItemList();
    96         row.Add(new DoubleData(falsePositiveRate));
    97         row.Add(new DoubleData(truePositiveRate));
    98         rocValues.Add(row);
     93      foreach (double treshold in classes[negativeClassKey].Distinct<double>()) {
     94        truePositiveRate = ((double)classes[positiveClassKey].Count<double>(value => value < treshold)) / classes[positiveClassKey].Count;
     95        falsePositiveRate = ((double)classes[negativeClassKey].Count<double>(value => value < treshold)) / classes[negativeClassKey].Count;
     96        point = new DoubleArrayData(new double[2] { falsePositiveRate, truePositiveRate });
     97        rocValues[0].Add(point);
    9998
    10099        //stop calculation if truePositiveRate = 1; save runtime
     
    105104      //add case when treshold == max negative class value => falsePositiveRate ==1
    106105      if (truePositiveRate != 1.0) {
    107        
    108         truePositiveRate = classes[positiveClassKey].Count<double>(value => value <= classes[negativeClassKey][classes[negativeClassKey].Count - 1]) / classes[positiveClassKey].Count;
     106        truePositiveRate = ((double)classes[positiveClassKey].Count<double>(value => value <= classes[negativeClassKey][classes[negativeClassKey].Count - 1])) / classes[positiveClassKey].Count;
    109107        falsePositiveRate = 1;
    110         row = new ItemList();
    111         row.Add(new DoubleData(falsePositiveRate));
    112         row.Add(new DoubleData(truePositiveRate));
    113         rocValues.Add(row);
     108        point = new DoubleArrayData(new double[2] { falsePositiveRate, truePositiveRate });
     109        rocValues[0].Add(point);
    114110      } else {
    115111        //ROC ends at 1,1
    116         row = new ItemList();
    117         row.Add(new DoubleData(1));
    118         row.Add(new DoubleData(1));
    119         rocValues.Add(row);
     112        point = new DoubleArrayData(new double[2] { 1, 1 });
     113        rocValues[0].Add(point);
    120114      }
    121115
Note: See TracChangeset for help on using the changeset viewer.