Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/30/12 16:22:04 (12 years ago)
Author:
sforsten
Message:

#1776:

  • merged r8810:8862 from trunk into branch
  • fixed exception in ClassificationEnsembleSolutionAccuracyToCoveredSamples, if no estimated values are in a partition, so nothing can be shown
Location:
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views

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

    r8862 r8863  
    118118        }
    119119
    120         int row;
    121         for (int i = 0; i < maxPoints; i++) {
    122           double confidenceValue = (1.0 / (maxPoints - 1)) * i;
    123           int notCovered = 0;
    124 
    125           for (int j = 0; j < indizes.Length; j++) {
    126             row = indizes[j];
    127             if (confidences[j] >= confidenceValue) {
    128               accuracyCalc.Add(target[row], estimatedClassValues[j]);
    129             } else {
    130               notCovered++;
     120        if (!estimatedClassValues.All(x => Double.IsNaN(x))) {
     121          int row;
     122          for (int i = 0; i < maxPoints; i++) {
     123            double confidenceValue = (1.0 / (maxPoints - 1)) * i;
     124            int notCovered = 0;
     125
     126            for (int j = 0; j < indizes.Length; j++) {
     127              row = indizes[j];
     128              if (confidences[j] >= confidenceValue) {
     129                accuracyCalc.Add(target[row], estimatedClassValues[j]);
     130              } else {
     131                notCovered++;
     132              }
    131133            }
     134
     135            accuracy[i + 1] = accuracyCalc.Accuracy;
     136            if (indizes.Length > 0) {
     137              covered[i] = 1.0 - (double)notCovered / (double)indizes.Length;
     138            }
     139            accuracyCalc.Reset();
    132140          }
    133141
    134           accuracy[i + 1] = accuracyCalc.Accuracy;
    135           if (indizes.Length > 0) {
    136             covered[i] = 1.0 - (double)notCovered / (double)indizes.Length;
    137           }
    138           accuracyCalc.Reset();
     142          accuracy[0] = accuracy[1];
     143          covered[maxPoints] = 0.0;
     144
     145          accuracy = accuracy.Reverse().ToArray();
     146          covered = covered.Reverse().ToArray();
     147
     148          Series area = this.chart.Series.Add(AREA);
     149          area.ChartType = SeriesChartType.Area;
     150          area.Color = Color.LightBlue;
     151          IEnumerable<IEnumerable<double>> areaPoints = CalculateAreaPoints(covered, accuracy);
     152          area.Points.DataBindXY(areaPoints.ElementAt(0), areaPoints.ElementAt(1));
     153
     154          Series series = this.chart.Series.Add(ACCURACYCOVERED);
     155          series.Color = Color.Red;
     156          series.ChartType = SeriesChartType.FastPoint;
     157          series.MarkerStyle = MarkerStyle.Diamond;
     158          series.MarkerSize = 5;
     159          series.Points.DataBindXY(covered, accuracy);
     160
     161          double auc = CalculateAreaUnderCurve(series);
     162          area.LegendToolTip = "AUC: " + auc;
     163
     164          AUCLabel.Text = "AUC: " + auc;
     165        } else {
     166          AUCLabel.Text = "No values in this partition!";
    139167        }
    140 
    141         accuracy[0] = accuracy[1];
    142         covered[maxPoints] = 0.0;
    143 
    144         accuracy = accuracy.Reverse().ToArray();
    145         covered = covered.Reverse().ToArray();
    146 
    147         Series area = this.chart.Series.Add(AREA);
    148         area.ChartType = SeriesChartType.Area;
    149         area.Color = Color.LightBlue;
    150         IEnumerable<IEnumerable<double>> areaPoints = CalculateAreaPoints(covered, accuracy);
    151         area.Points.DataBindXY(areaPoints.ElementAt(0), areaPoints.ElementAt(1));
    152 
    153         Series series = this.chart.Series.Add(ACCURACYCOVERED);
    154         series.Color = Color.Red;
    155         series.ChartType = SeriesChartType.FastPoint;
    156         series.MarkerStyle = MarkerStyle.Diamond;
    157         series.MarkerSize = 5;
    158         series.Points.DataBindXY(covered, accuracy);
    159 
    160         double auc = CalculateAreaUnderCurve(series);
    161         area.LegendToolTip = "AUC: " + auc;
    162 
    163         AUCLabel.Text = "AUC: " + auc;
    164168      }
    165169    }
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationEnsembleSolutionEstimatedClassValuesView.cs

    r8814 r8863  
    133133        int row = indizes[i];
    134134        values[i, 0] = row.ToString();
    135         values[i, 1] = target[i].ToString();
     135        values[i, 1] = target[row].ToString();
    136136        //display only indices and target values if no models are present
    137137        if (solutionsCount > 0) {
    138138          values[i, 2] = estimatedClassValues[i].ToString();
    139           correctClassified = target[i].IsAlmost(estimatedClassValues[i]);
     139          correctClassified = target[row].IsAlmost(estimatedClassValues[i]);
    140140          values[i, 3] = correctClassified.ToString();
    141141          curConfidence = confidences[i];
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationFeatureCorrelationView.cs

    r8811 r8863  
    3737    }
    3838
    39     protected override bool[] SetInitialVisibilityOfColumns() {
     39    protected override bool[] SetInitialVariableVisibility() {
    4040      int i = Content.Dataset.DoubleVariables.ToList().FindIndex(x => x == Content.TargetVariable);
    41       var initialVisibility = base.SetInitialVisibilityOfColumns();
     41      var initialVisibility = base.SetInitialVariableVisibility();
    4242      initialVisibility[i] = true;
    4343      return initialVisibility;
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationTimeframeFeatureCorrelationView.cs

    r8811 r8863  
    3737    }
    3838
    39     protected override bool[] SetInitialVisibilityOfColumns() {
     39    protected override bool[] SetInitialVariableVisibility() {
    4040      int i = Content.Dataset.DoubleVariables.ToList().FindIndex(x => x == Content.TargetVariable);
    41       var initialVisibility = base.SetInitialVisibilityOfColumns();
     41      var initialVisibility = base.SetInitialVariableVisibility();
    4242      initialVisibility[i] = true;
    4343      return initialVisibility;
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationRocCurvesView.cs

    r8811 r8863  
    114114        maxThreshold += thresholdIncrement;
    115115
    116         List<double> classValues = Content.Model.ClassValues.ToList();
     116        List<double> classValues = Content.ProblemData.ClassValues.ToList();
    117117
    118118        foreach (double classValue in classValues) {
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionThresholdView.Designer.cs

    r8508 r8863  
    1 namespace HeuristicLab.Problems.DataAnalysis.Views {
     1using System.Windows.Forms.DataVisualization.Charting;
     2namespace HeuristicLab.Problems.DataAnalysis.Views {
    23  partial class DiscriminantFunctionClassificationSolutionThresholdView {
    34    /// <summary>
     
    5354      this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
    5455      this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
     56      this.chart.PostPaint += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs>(chart_PostPaint);
    5557      //
    5658      // JitterTrackBar
     
    9294
    9395    }
    94 
    9596    #endregion
    9697
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionThresholdView.cs

    r8811 r8863  
    4040    private const string TestLabelText = "Test Samples";
    4141
     42    private const double ClassNameLeftOffset = 10.0;
     43    private const double ClassNameBottomOffset = 5.0;
     44
    4245    public new IDiscriminantFunctionClassificationSolution Content {
    4346      get { return (IDiscriminantFunctionClassificationSolution)base.Content; }
     
    4750    private Dictionary<double, Series> classValueSeriesMapping;
    4851    private Random random;
    49     private bool updateInProgress;
     52    private bool updateInProgress, updateThresholds;
    5053
    5154    public DiscriminantFunctionClassificationSolutionThresholdView()
     
    126129            FillSeriesWithDataPoints(series);
    127130          }
    128           AddThresholds();
     131          updateThresholds = true;
    129132        }
    130133        chart.ChartAreas[0].RecalculateAxesScale();
     
    166169    }
    167170
     171    private void chart_PostPaint(object sender, ChartPaintEventArgs e) {
     172      if (updateThresholds) {
     173        AddThresholds();
     174        updateThresholds = false;
     175      }
     176    }
     177
    168178    private void AddThresholds() {
    169179      chart.Annotations.Clear();
    170180      int classIndex = 1;
     181      SizeF textSizeInPixel;
     182      IClassificationProblemData problemData = Content.ProblemData;
     183      var classValues = Content.Model.ClassValues.ToArray();
     184      Graphics g = chart.CreateGraphics();
     185      Axis y = chart.ChartAreas[0].AxisY;
     186      Axis x = chart.ChartAreas[0].AxisX;
     187      string name;
    171188      foreach (double threshold in Content.Model.Thresholds) {
    172189        if (!double.IsInfinity(threshold)) {
     
    176193          annotation.LineWidth = 2;
    177194          annotation.LineColor = Color.Red;
    178 
    179195          annotation.IsInfinitive = true;
    180196          annotation.ClipToChartArea = chart.ChartAreas[0].Name;
    181197          annotation.Tag = classIndex;  //save classIndex as Tag to avoid moving the threshold accross class bounderies
    182 
    183198          annotation.AxisX = chart.ChartAreas[0].AxisX;
    184           annotation.AxisY = chart.ChartAreas[0].AxisY;
     199          annotation.AxisY = y;
    185200          annotation.Y = threshold;
    186201
     202          name = problemData.GetClassName(classValues[classIndex - 1]);
     203          TextAnnotation beneathLeft = CreateTextAnnotation(name, classIndex, x, y);
     204          beneathLeft.Y = threshold;
     205          beneathLeft.X = x.Minimum;
     206          TextAnnotation beneathRigth = CreateTextAnnotation(name, classIndex, x, y);
     207          beneathRigth.Y = threshold;
     208          textSizeInPixel = g.MeasureString(beneathRigth.Text, beneathRigth.Font);
     209          double textWidthPixelPos = x.ValueToPixelPosition(x.Maximum) - textSizeInPixel.Width - ClassNameLeftOffset;
     210          //check if position is within the position boundary
     211          beneathRigth.X = textWidthPixelPos < 0 || textWidthPixelPos > chart.Width ? double.NaN : x.PixelPositionToValue(textWidthPixelPos);
     212
     213          name = problemData.GetClassName(classValues[classIndex]);
     214          TextAnnotation aboveLeft = CreateTextAnnotation(name, classIndex, x, y);
     215          textSizeInPixel = g.MeasureString(aboveLeft.Text, aboveLeft.Font);
     216          double textHeightPixelPos = y.ValueToPixelPosition(threshold) - textSizeInPixel.Height - ClassNameBottomOffset;
     217          //check if position is within the position boundary
     218          aboveLeft.Y = textHeightPixelPos < 0 || textHeightPixelPos > chart.Height ? double.NaN : y.PixelPositionToValue(textHeightPixelPos);
     219          aboveLeft.X = x.Minimum;
     220          TextAnnotation aboveRight = CreateTextAnnotation(name, classIndex, x, y);
     221          aboveRight.Y = aboveLeft.Y;
     222          textWidthPixelPos = x.ValueToPixelPosition(x.Maximum) - textSizeInPixel.Width - ClassNameLeftOffset;
     223          //check if position is within the position boundary
     224          aboveRight.X = textWidthPixelPos < 0 || textWidthPixelPos > chart.Width ? double.NaN : x.PixelPositionToValue(textWidthPixelPos);
     225
    187226          chart.Annotations.Add(annotation);
     227          chart.Annotations.Add(beneathLeft);
     228          chart.Annotations.Add(aboveLeft);
     229          chart.Annotations.Add(beneathRigth);
     230          chart.Annotations.Add(aboveRight);
    188231          classIndex++;
    189232        }
    190233      }
     234    }
     235
     236    private TextAnnotation CreateTextAnnotation(string name, int classIndex, Axis x, Axis y) {
     237      TextAnnotation annotation = new TextAnnotation();
     238      annotation.Text = name;
     239      annotation.AllowMoving = true;
     240      annotation.AllowResizing = false;
     241      annotation.AllowSelecting = false;
     242      annotation.ClipToChartArea = chart.ChartAreas[0].Name;
     243      annotation.Tag = classIndex;
     244      annotation.AxisX = chart.ChartAreas[0].AxisX;
     245      annotation.AxisY = y;
     246      return annotation;
    191247    }
    192248
Note: See TracChangeset for help on using the changeset viewer.