Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/20/12 16:34:14 (12 years ago)
Author:
sforsten
Message:

#1776: adapted ClassificationEnsembleSolutionAccuracyToCoveredSamples

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationEnsembleSolutionAccuracyToCoveredSamples.cs

    r8329 r8507  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Drawing;
    2425using System.Linq;
    2526using System.Windows.Forms;
     
    3435  public partial class ClassificationEnsembleSolutionAccuracyToCoveredSamples : DataAnalysisSolutionEvaluationView {
    3536    private const string ACCURACYCOVERED = "Accuracy to Covered percentage";
     37    private const string AREA = "Area";
    3638
    3739    private const string SamplesComboBoxAllSamples = "All Samples";
     
    3941    private const string SamplesComboBoxTestSamples = "Test Samples";
    4042
    41     // zero is also a point
    4243    private const int maxPoints = 101;
    4344
     
    137138        covered = covered.Reverse().ToArray();
    138139
    139 
    140 
    141         Series serie = this.chart.Series.Add(ACCURACYCOVERED);
    142         serie.LegendText = ACCURACYCOVERED;
    143         serie.ChartType = SeriesChartType.StepLine;
    144         //serie.MarkerStyle = MarkerStyle.Diamond;
    145         //serie.MarkerSize = 5;
    146         serie.Points.DataBindXY(covered, accuracy);
     140        Series area = this.chart.Series.Add(AREA);
     141        area.ChartType = SeriesChartType.Area;
     142        area.Color = Color.LightBlue;
     143        IEnumerable<IEnumerable<double>> areaPoints = CalculateAreaPoints(covered, accuracy);
     144        area.Points.DataBindXY(areaPoints.ElementAt(0), areaPoints.ElementAt(1));
     145
     146        Series series = this.chart.Series.Add(ACCURACYCOVERED);
     147        series.Color = Color.Red;
     148        series.ChartType = SeriesChartType.FastPoint;
     149        series.MarkerStyle = MarkerStyle.Diamond;
     150        series.MarkerSize = 5;
     151        series.Points.DataBindXY(covered, accuracy);
     152
     153        double auc = CalculateAreaUnderCurve(series);
     154        area.LegendToolTip = "AUC: " + auc;
    147155      }
     156    }
     157
     158    private IEnumerable<IEnumerable<double>> CalculateAreaPoints(double[] covered, double[] accuracy) {
     159      List<double> newCovered = new List<double>();
     160      List<double> worseAccuracy = new List<double>();
     161      newCovered.Add(covered[0]);
     162      worseAccuracy.Add(accuracy[0]);
     163      for (int i = 1; i < covered.Length; i++) {
     164        if (accuracy[i] > accuracy[i - 1]) {
     165          worseAccuracy.Add(accuracy[i - 1]);
     166          newCovered.Add(covered[i] - Double.Epsilon);
     167        } else {
     168          worseAccuracy.Add(accuracy[i]);
     169          newCovered.Add(covered[i - 1] + Double.Epsilon);
     170        }
     171        worseAccuracy.Add(accuracy[i]);
     172        newCovered.Add(covered[i]);
     173      }
     174      return new List<IEnumerable<double>>() { newCovered, worseAccuracy };
    148175    }
    149176
     
    159186    }
    160187
     188    private double CalculateAreaUnderCurve(Series series) {
     189      if (series.Points.Count < 1) throw new ArgumentException("Could not calculate area under curve if less than 1 data points were given.");
     190
     191      double auc = 0.0;
     192      for (int i = 1; i < series.Points.Count; i++) {
     193        double width = series.Points[i].XValue - series.Points[i - 1].XValue;
     194        double y1 = series.Points[i - 1].YValues[0];
     195        double y2 = series.Points[i].YValues[0];
     196
     197        auc += (y1 + y2) * width / 2;
     198      }
     199
     200      return auc;
     201    }
     202
    161203    #region events
    162204    protected override void RegisterContentEvents() {
Note: See TracChangeset for help on using the changeset viewer.