Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/24/15 11:17:08 (9 years ago)
Author:
mkommend
Message:

#2276: Merged trunk changes into dataset refactoring branch.

Location:
branches/HeuristicLab.DatasetRefactor/sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.DatasetRefactor/sources

  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Analysis.Views

  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Analysis.Views/3.3/HistogramControl.cs

    r12031 r12247  
    3131  public partial class HistogramControl : UserControl {
    3232    protected static readonly string SeriesName = "Histogram";
    33 
     33    protected static readonly decimal bandwidthMin = 0.0000000000001m;
    3434    protected Dictionary<string, List<double>> points;
     35    protected bool suppressUpdate;
     36
    3537    public int NumberOfBins {
    3638      get { return (int)binsNumericUpDown.Value; }
     
    123125    }
    124126
    125     protected void UpdateHistogram() {
     127    protected void UpdateHistogram(double bandwith = double.NaN) {
    126128      if (InvokeRequired) {
    127         Invoke((Action)UpdateHistogram, null);
     129        Invoke((Action<double>)UpdateHistogram, bandwith);
    128130        return;
    129131      }
     
    134136
    135137      chart.Series.Clear();
    136 
    137138      foreach (var point in points) {
    138139        if (!point.Value.Any()) continue;
     
    140141        Series histogramSeries = new Series(point.Key);
    141142        chart.Series.Add(histogramSeries);
    142 
    143143        double minValue = point.Value.Min();
    144144        double maxValue = point.Value.Max();
     
    165165        histogramSeries["PointWidth"] = "1";
    166166
    167         CalculateDensity(histogramSeries, point.Value);
    168 
    169167        overallMax = Math.Max(overallMax, maxValue);
    170168        overallMin = Math.Min(overallMin, minValue);
     169
     170        chart.ApplyPaletteColors();
     171        CalculateDensity(histogramSeries, point.Value, bandwith);
    171172      }
    172173
    173174      ChartArea chartArea = chart.ChartAreas[0];
     175      // don't show grid lines for second y-axis
     176      chartArea.AxisY2.MajorGrid.Enabled = false;
     177      chartArea.AxisY2.MinorGrid.Enabled = false;
    174178      chartArea.AxisY.Title = "Frequency";
    175179
     
    182186    }
    183187
    184     protected void CalculateDensity(Series series, List<double> row) {
     188    protected void CalculateDensity(Series series, List<double> row, double bandwidth = double.NaN) {
    185189      string densitySeriesName = "Density " + series.Name;
    186190      double stepWidth = series.Points[1].XValue - series.Points[0].XValue;
     191      var rowArray = row.ToArray();
    187192
    188193      if (chart.Series.Any(x => x.Name == densitySeriesName)) {
     
    191196      }
    192197
    193       var density = NormalDistribution.Density(row.ToArray(), row.Count, stepWidth);
     198      if (double.IsNaN(bandwidth)) {
     199        bandwidth = KernelDensityEstimator.EstimateBandwidth(rowArray);
     200        decimal bwDecimal = (decimal)bandwidth;
     201        if (bwDecimal < bandwidthMin) {
     202          bwDecimal = bandwidthMin;
     203          bandwidth = decimal.ToDouble(bwDecimal);
     204        }
     205        suppressUpdate = true;
     206        bandwidthNumericUpDown.Value = bwDecimal;
     207      }
     208      var density = KernelDensityEstimator.Density(rowArray, rowArray.Length, stepWidth, bandwidth);
    194209
    195210      Series newSeries = new Series(densitySeriesName);
     211      newSeries.Color = series.Color;
    196212      newSeries.ChartType = SeriesChartType.FastLine;
    197213      newSeries.BorderWidth = 2;
     
    200216      }
    201217
     218      // densities should be plotted on the second axis (different scale)
     219      newSeries.YAxisType = AxisType.Secondary;
    202220      chart.Series.Add(newSeries);
    203221    }
     
    221239      UpdateHistogram();
    222240    }
     241
     242    private void bandwidthNumericUpDown_ValueChanged(object sender, EventArgs e) {
     243      if (!suppressUpdate) {
     244        UpdateHistogram(decimal.ToDouble(bandwidthNumericUpDown.Value));
     245      }
     246      suppressUpdate = false;
     247    }
    223248  }
    224249}
Note: See TracChangeset for help on using the changeset viewer.