Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12154


Ignore:
Timestamp:
03/06/15 15:01:05 (9 years ago)
Author:
ascheibe
Message:

#2351 merged r12134,r12135,r12139,r12140,r12143,r12145 into stable

Location:
stable
Files:
1 deleted
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Analysis

  • stable/HeuristicLab.Analysis.Views

  • stable/HeuristicLab.Analysis.Views/3.3/HistogramControl.Designer.cs

    r12009 r12154  
    5555      this.label1 = new System.Windows.Forms.Label();
    5656      this.exactCheckBox = new System.Windows.Forms.CheckBox();
     57      this.label2 = new System.Windows.Forms.Label();
     58      this.bandwidthNumericUpDown = new System.Windows.Forms.NumericUpDown();
    5759      ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();
    5860      ((System.ComponentModel.ISupportInitialize)(this.binsNumericUpDown)).BeginInit();
     61      ((System.ComponentModel.ISupportInitialize)(this.bandwidthNumericUpDown)).BeginInit();
    5962      this.SuspendLayout();
    6063      //
    6164      // chart
    6265      //
    63       this.chart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    64             | System.Windows.Forms.AnchorStyles.Left)
     66      this.chart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     67            | System.Windows.Forms.AnchorStyles.Left) 
    6568            | System.Windows.Forms.AnchorStyles.Right)));
    6669      chartArea1.Name = "ChartArea1";
     
    8891            0});
    8992      this.binsNumericUpDown.Minimum = new decimal(new int[] {
    90             1,
     93            2,
    9194            0,
    9295            0,
     
    115118      this.exactCheckBox.AutoSize = true;
    116119      this.exactCheckBox.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
    117       this.exactCheckBox.Location = new System.Drawing.Point(158, 4);
     120      this.exactCheckBox.Location = new System.Drawing.Point(291, 4);
    118121      this.exactCheckBox.Name = "exactCheckBox";
    119122      this.exactCheckBox.Size = new System.Drawing.Size(56, 17);
     
    123126      this.exactCheckBox.CheckedChanged += new System.EventHandler(this.exactCheckBox_CheckedChanged);
    124127      //
     128      // label2
     129      //
     130      this.label2.AutoSize = true;
     131      this.label2.Location = new System.Drawing.Point(158, 5);
     132      this.label2.Name = "label2";
     133      this.label2.Size = new System.Drawing.Size(60, 13);
     134      this.label2.TabIndex = 5;
     135      this.label2.Text = "Bandwidth:";
     136      //
     137      // bandwidthNumericUpDown
     138      //
     139      this.bandwidthNumericUpDown.DecimalPlaces = 2;
     140      this.bandwidthNumericUpDown.Location = new System.Drawing.Point(224, 3);
     141      this.bandwidthNumericUpDown.Maximum = new decimal(new int[] {
     142            100000000,
     143            0,
     144            0,
     145            0});
     146      this.bandwidthNumericUpDown.Minimum = new decimal(new int[] {
     147            1,
     148            0,
     149            0,
     150            851968});
     151      this.bandwidthNumericUpDown.Name = "bandwidthNumericUpDown";
     152      this.bandwidthNumericUpDown.Size = new System.Drawing.Size(61, 20);
     153      this.bandwidthNumericUpDown.TabIndex = 4;
     154      this.bandwidthNumericUpDown.Value = new decimal(new int[] {
     155            1,
     156            0,
     157            0,
     158            0});
     159      this.bandwidthNumericUpDown.ValueChanged += new System.EventHandler(this.bandwidthNumericUpDown_ValueChanged);
     160      //
    125161      // HistogramControl
    126162      //
    127163      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
     164      this.Controls.Add(this.label2);
     165      this.Controls.Add(this.bandwidthNumericUpDown);
    128166      this.Controls.Add(this.exactCheckBox);
    129167      this.Controls.Add(this.label1);
     
    134172      ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
    135173      ((System.ComponentModel.ISupportInitialize)(this.binsNumericUpDown)).EndInit();
     174      ((System.ComponentModel.ISupportInitialize)(this.bandwidthNumericUpDown)).EndInit();
    136175      this.ResumeLayout(false);
    137176      this.PerformLayout();
     
    145184    private System.Windows.Forms.Label label1;
    146185    private System.Windows.Forms.CheckBox exactCheckBox;
     186    private System.Windows.Forms.Label label2;
     187    private System.Windows.Forms.NumericUpDown bandwidthNumericUpDown;
    147188  }
    148189}
  • stable/HeuristicLab.Analysis.Views/3.3/HistogramControl.cs

    r12009 r12154  
    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);
    171169      }
    172170
     171      chart.ApplyPaletteColors();
     172
     173      int i = 0;
     174      foreach (var point in points) {
     175        if (!point.Value.Any()) continue;
     176
     177        var histogramSeries = chart.Series[i];
     178        CalculateDensity(histogramSeries, point.Value, bandwith);
     179
     180        i++;
     181      }
     182
     183
    173184      ChartArea chartArea = chart.ChartAreas[0];
     185      // don't show grid lines for second y-axis
     186      chartArea.AxisY2.MajorGrid.Enabled = false;
     187      chartArea.AxisY2.MinorGrid.Enabled = false;
    174188      chartArea.AxisY.Title = "Frequency";
    175189
     
    182196    }
    183197
    184     protected void CalculateDensity(Series series, List<double> row) {
     198    protected void CalculateDensity(Series series, List<double> row, double bandwidth = double.NaN) {
    185199      string densitySeriesName = "Density " + series.Name;
    186200      double stepWidth = series.Points[1].XValue - series.Points[0].XValue;
     201      var rowArray = row.ToArray();
    187202
    188203      if (chart.Series.Any(x => x.Name == densitySeriesName)) {
     
    191206      }
    192207
    193       var density = NormalDistribution.Density(row.ToArray(), row.Count, stepWidth);
     208      if (double.IsNaN(bandwidth)) {
     209        bandwidth = KernelDensityEstimator.EstimateBandwidth(rowArray);
     210        decimal bwDecimal = (decimal)bandwidth;
     211        if (bwDecimal < bandwidthMin) {
     212          bwDecimal = bandwidthMin;
     213          bandwidth = decimal.ToDouble(bwDecimal);
     214        }
     215        suppressUpdate = true;
     216        bandwidthNumericUpDown.Value = bwDecimal;
     217      }
     218      var density = KernelDensityEstimator.Density(rowArray, rowArray.Length, stepWidth, bandwidth);
    194219
    195220      Series newSeries = new Series(densitySeriesName);
     221      newSeries.Color = series.Color;
    196222      newSeries.ChartType = SeriesChartType.FastLine;
    197223      newSeries.BorderWidth = 2;
     
    200226      }
    201227
     228      // densities should be plotted on the second axis (different scale)
     229      newSeries.YAxisType = AxisType.Secondary;
    202230      chart.Series.Add(newSeries);
    203231    }
     
    221249      UpdateHistogram();
    222250    }
     251
     252    private void bandwidthNumericUpDown_ValueChanged(object sender, EventArgs e) {
     253      if (!suppressUpdate) {
     254        UpdateHistogram(decimal.ToDouble(bandwidthNumericUpDown.Value));
     255      }
     256      suppressUpdate = false;
     257    }
    223258  }
    224259}
  • stable/HeuristicLab.Analysis/3.3/HeuristicLab.Analysis-3.3.csproj

    r11920 r12154  
    166166    <Compile Include="Statistics\Fitting\LinearLeastSquaresFitting.cs" />
    167167    <Compile Include="Statistics\Fitting\LogFitting.cs" />
    168     <Compile Include="Statistics\NormalDistribution.cs" />
     168    <Compile Include="Statistics\KernelDensityEstimator.cs" />
    169169    <Compile Include="Statistics\PairwiseTest.cs" />
    170170    <Compile Include="Statistics\SampleSizeDetermination.cs" />
Note: See TracChangeset for help on using the changeset viewer.