Changeset 12139 for trunk/sources
- Timestamp:
- 03/05/15 14:17:33 (10 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Analysis.Views/3.3/HistogramControl.Designer.cs
r12012 r12139 48 48 private void InitializeComponent() { 49 49 this.components = new System.ComponentModel.Container(); 50 System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea 1= new System.Windows.Forms.DataVisualization.Charting.ChartArea();51 System.Windows.Forms.DataVisualization.Charting.Legend legend 1= new System.Windows.Forms.DataVisualization.Charting.Legend();52 System.Windows.Forms.DataVisualization.Charting.Series series 1= new System.Windows.Forms.DataVisualization.Charting.Series();50 System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); 51 System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); 52 System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); 53 53 this.chart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart(); 54 54 this.binsNumericUpDown = new System.Windows.Forms.NumericUpDown(); 55 55 this.label1 = new System.Windows.Forms.Label(); 56 56 this.exactCheckBox = new System.Windows.Forms.CheckBox(); 57 this.label2 = new System.Windows.Forms.Label(); 58 this.BandwidthNumericUpDown = new System.Windows.Forms.NumericUpDown(); 57 59 ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit(); 58 60 ((System.ComponentModel.ISupportInitialize)(this.binsNumericUpDown)).BeginInit(); 61 ((System.ComponentModel.ISupportInitialize)(this.BandwidthNumericUpDown)).BeginInit(); 59 62 this.SuspendLayout(); 60 63 // 61 64 // chart 62 65 // 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) 65 68 | System.Windows.Forms.AnchorStyles.Right))); 66 chartArea 1.Name = "ChartArea1";67 this.chart.ChartAreas.Add(chartArea 1);68 legend 1.Alignment = System.Drawing.StringAlignment.Center;69 legend 1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top;70 legend 1.Name = "Default";71 this.chart.Legends.Add(legend 1);69 chartArea2.Name = "ChartArea1"; 70 this.chart.ChartAreas.Add(chartArea2); 71 legend2.Alignment = System.Drawing.StringAlignment.Center; 72 legend2.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top; 73 legend2.Name = "Default"; 74 this.chart.Legends.Add(legend2); 72 75 this.chart.Location = new System.Drawing.Point(0, 27); 73 76 this.chart.Name = "chart"; 74 series 1.ChartArea = "ChartArea1";75 series 1.Legend = "Default";76 series 1.Name = "Series1";77 this.chart.Series.Add(series 1);77 series2.ChartArea = "ChartArea1"; 78 series2.Legend = "Default"; 79 series2.Name = "Series1"; 80 this.chart.Series.Add(series2); 78 81 this.chart.Size = new System.Drawing.Size(465, 336); 79 82 this.chart.TabIndex = 0; … … 88 91 0}); 89 92 this.binsNumericUpDown.Minimum = new decimal(new int[] { 90 1,93 2, 91 94 0, 92 95 0, … … 115 118 this.exactCheckBox.AutoSize = true; 116 119 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); 118 121 this.exactCheckBox.Name = "exactCheckBox"; 119 122 this.exactCheckBox.Size = new System.Drawing.Size(56, 17); … … 123 126 this.exactCheckBox.CheckedChanged += new System.EventHandler(this.exactCheckBox_CheckedChanged); 124 127 // 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 65536}); 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 // 125 161 // HistogramControl 126 162 // 127 163 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 164 this.Controls.Add(this.label2); 165 this.Controls.Add(this.BandwidthNumericUpDown); 128 166 this.Controls.Add(this.exactCheckBox); 129 167 this.Controls.Add(this.label1); … … 134 172 ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit(); 135 173 ((System.ComponentModel.ISupportInitialize)(this.binsNumericUpDown)).EndInit(); 174 ((System.ComponentModel.ISupportInitialize)(this.BandwidthNumericUpDown)).EndInit(); 136 175 this.ResumeLayout(false); 137 176 this.PerformLayout(); … … 145 184 private System.Windows.Forms.Label label1; 146 185 private System.Windows.Forms.CheckBox exactCheckBox; 186 private System.Windows.Forms.Label label2; 187 private System.Windows.Forms.NumericUpDown BandwidthNumericUpDown; 147 188 } 148 189 } -
trunk/sources/HeuristicLab.Analysis.Views/3.3/HistogramControl.cs
r12134 r12139 33 33 34 34 protected Dictionary<string, List<double>> points; 35 private bool suppressUpdate; 36 35 37 public int NumberOfBins { 36 38 get { return (int)binsNumericUpDown.Value; } … … 123 125 } 124 126 125 protected void UpdateHistogram( ) {127 protected void UpdateHistogram(double bandwith = double.NaN) { 126 128 if (InvokeRequired) { 127 Invoke((Action )UpdateHistogram, null);129 Invoke((Action<double>)UpdateHistogram, bandwith); 128 130 return; 129 131 } … … 164 166 histogramSeries["PointWidth"] = "1"; 165 167 166 CalculateDensity(histogramSeries, point.Value );168 CalculateDensity(histogramSeries, point.Value, bandwith); 167 169 168 170 overallMax = Math.Max(overallMax, maxValue); … … 184 186 } 185 187 186 protected void CalculateDensity(Series series, List<double> row ) {188 protected void CalculateDensity(Series series, List<double> row, double bandwidth = double.NaN) { 187 189 string densitySeriesName = "Density " + series.Name; 188 190 double stepWidth = series.Points[1].XValue - series.Points[0].XValue; 191 var rowArray = row.ToArray(); 189 192 190 193 if (chart.Series.Any(x => x.Name == densitySeriesName)) { … … 193 196 } 194 197 195 var density = NormalDistribution.Density(row.ToArray(), row.Count, stepWidth); 198 if (double.IsNaN(bandwidth)) { 199 bandwidth = KernelDensityEstimator.EstimateBandwidth(rowArray); 200 suppressUpdate = true; 201 BandwidthNumericUpDown.Value = (decimal)bandwidth; 202 } 203 var density = KernelDensityEstimator.Density(rowArray, rowArray.Length, stepWidth, bandwidth); 196 204 197 205 Series newSeries = new Series(densitySeriesName); … … 225 233 UpdateHistogram(); 226 234 } 235 236 private void BandwidthNumericUpDown_ValueChanged(object sender, EventArgs e) { 237 if (!suppressUpdate) { 238 UpdateHistogram(decimal.ToDouble(BandwidthNumericUpDown.Value)); 239 } 240 suppressUpdate = false; 241 } 227 242 } 228 243 } -
trunk/sources/HeuristicLab.Analysis/3.3/HeuristicLab.Analysis-3.3.csproj
r12069 r12139 167 167 <Compile Include="Statistics\Fitting\LinearLeastSquaresFitting.cs" /> 168 168 <Compile Include="Statistics\Fitting\LogFitting.cs" /> 169 <Compile Include="Statistics\ NormalDistribution.cs" />169 <Compile Include="Statistics\KernelDensityEstimator.cs" /> 170 170 <Compile Include="Statistics\PairwiseTest.cs" /> 171 171 <Compile Include="Statistics\SampleSizeDetermination.cs" /> -
trunk/sources/HeuristicLab.Analysis/3.3/Statistics/KernelDensityEstimator.cs
r12135 r12139 26 26 27 27 namespace HeuristicLab.Analysis.Statistics { 28 public static class NormalDistribution{28 public static class KernelDensityEstimator { 29 29 public static double[] Density(double[] x, double mean, double stdDev) { 30 30 return x.Select(xi => Density(xi, mean, stdDev)).ToArray(); … … 36 36 (2.0 * Math.Pow(stdDev, 2.0)))); 37 37 } 38 39 38 40 39 // the scale (sigma) of the kernel is a parameter … … 62 61 return newX.Zip(y, Tuple.Create).ToList(); 63 62 } 63 64 //Silverman's rule of thumb for bandwidth estimation (sigma) 65 public static double EstimateBandwidth(double[] x) { 66 return 1.06 * x.StandardDeviation() * Math.Pow(x.Length, -0.2); 67 } 64 68 } 65 69 }
Note: See TracChangeset
for help on using the changeset viewer.