Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/18/16 16:28:59 (9 years ago)
Author:
pfleck
Message:

#2597

  • Extracted DensityChart from DensityTrackbar.
  • Added DensityChart to RegressionSolutionTargetResponseView with different options (none/training/test/all).
  • Moved RegressionSolutionGradientView and RegressionSolutionTargetResponseView to subfolder.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/DensityTrackbar.cs

    r13846 r13850  
    2323using System.Collections.Generic;
    2424using System.Globalization;
    25 using System.Linq;
    2625using System.Windows.Forms;
    27 using System.Windows.Forms.DataVisualization.Charting;
    28 using HeuristicLab.Common;
    2926using HeuristicLab.Problems.DataAnalysis;
    3027
     
    7673
    7774    private void UpdateDensityChart() {
    78       var series = chart.Series[0];
    79       ClearPointsQuick(series.Points);
    80 
    81       int numBuckets = trackBar.Maximum - trackBar.Minimum;
    82       var buckets = new double[numBuckets];
    83       var bucketSize = (Limits.Upper - Limits.Lower) / buckets.Length;
    84       foreach (var value in trainingValues) {
    85         if (bucketSize > 0.0) {
    86           int bucketIndex = (int)((value - Limits.Lower) / bucketSize);
    87           if (bucketIndex == numBuckets) {
    88             bucketIndex--;
    89           }
    90           buckets[bucketIndex] += 1.0;
    91         }
    92       }
    93 
    94       // set minimum height of all non-zero buckets on 20% of maximum
    95       double min = buckets.Max() / 20.0;
    96       for (int i = 0; i < buckets.Length; i++) {
    97         if (buckets[i] >= 1 && buckets[i] < min)
    98           buckets[i] = min;
    99       }
    100 
    101       series.Points.DataBindY(buckets);
    102 
    103       // Set trackbar on highest density
    104       double highestDensity = buckets.Max();
    105       var highestIndices = buckets.Select((v, i) => new { v, i }).Where(x => x.v.IsAlmost(highestDensity)).Select(x => x.i).ToList();
    106       trackBar.Value = highestIndices[highestIndices.Count / 2];
     75      chart.UpdateChart(trainingValues, Limits.Lower, Limits.Upper,
     76        numBuckets: trackBar.Maximum - trackBar.Minimum, minimumHeight: 0.1);
    10777    }
    10878
     
    155125      return (int)((value - lower) / ((upper - lower) / numberOfTicks));
    156126    }
    157 
    158     // workaround as per http://stackoverflow.com/questions/5744930/datapointcollection-clear-performance
    159     private static void ClearPointsQuick(DataPointCollection points) {
    160       points.SuspendUpdates();
    161       while (points.Count > 0)
    162         points.RemoveAt(points.Count - 1);
    163       points.ResumeUpdates();
    164     }
    165 
    166127    #endregion
    167128  }
Note: See TracChangeset for help on using the changeset viewer.