- Timestamp:
- 01/02/12 11:40:31 (13 years ago)
- Location:
- branches/RegressionBenchmarks
- Files:
-
- 3 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/RegressionBenchmarks
-
branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/DataAnalysisProblemView.cs
r7127 r7255 78 78 else if (Content is IClassificationProblem) 79 79 return ApplicationManager.Manager.GetInstances<IClassificationBenchmarkProblemDataGenerator>(); 80 else if (Content is ITimeSeriesPrognosisProblem)81 return ApplicationManager.Manager.GetInstances<ITimeSeriesBenchmarkProblemDataGenerator>();82 80 else if (Content is IClusteringProblem) 83 81 return ApplicationManager.Manager.GetInstances<IClusteringBenchmarkProblemDataGenerator>(); -
branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj
r6968 r7255 123 123 <DependentUpon>ClassificationEnsembleSolutionModelView.cs</DependentUpon> 124 124 </Compile> 125 <Compile Include="Plugin.cs" />126 <Compile Include="Solution Views\TimeSeriesPrognosisSolutionView.cs">127 <SubType>UserControl</SubType>128 </Compile>129 <Compile Include="Solution Views\TimeSeriesPrognosisSolutionView.Designer.cs">130 <DependentUpon>TimeSeriesPrognosisSolutionView.cs</DependentUpon>131 </Compile>132 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView.cs">133 <SubType>UserControl</SubType>134 </Compile>135 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView.Designer.cs">136 <DependentUpon>TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView.cs</DependentUpon>137 </Compile>138 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionLineChartView.cs">139 <SubType>UserControl</SubType>140 </Compile>141 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionLineChartView.Designer.cs">142 <DependentUpon>TimeSeriesPrognosisSolutionLineChartView.cs</DependentUpon>143 </Compile>144 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionPrognosedValuesView.cs">145 <SubType>UserControl</SubType>146 </Compile>147 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionPrognosedValuesView.Designer.cs">148 <DependentUpon>TimeSeriesPrognosisSolutionPrognosedValuesView.cs</DependentUpon>149 </Compile>150 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionScatterPlotView.cs">151 <SubType>UserControl</SubType>152 </Compile>153 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionScatterPlotView.Designer.cs">154 <DependentUpon>TimeSeriesPrognosisSolutionScatterPlotView.cs</DependentUpon>155 </Compile>156 125 <Compile Include="DataAnalysisSolutionEvaluationView.cs"> 157 126 <SubType>UserControl</SubType> … … 160 129 <DependentUpon>DataAnalysisSolutionEvaluationView.cs</DependentUpon> 161 130 </Compile> 131 <Compile Include="Plugin.cs" /> 162 132 <Compile Include="Regression\RegressionSolutionErrorCharacteristicsCurveView.cs"> 163 133 <SubType>UserControl</SubType> … … 171 141 <Compile Include="Regression\RegressionEnsembleSolutionModelView.Designer.cs"> 172 142 <DependentUpon>RegressionEnsembleSolutionModelView.cs</DependentUpon> 143 </Compile> 144 <Compile Include="Regression\RegressionSolutionResidualHistogram.cs"> 145 <SubType>UserControl</SubType> 146 </Compile> 147 <Compile Include="Regression\RegressionSolutionResidualHistogram.Designer.cs"> 148 <DependentUpon>RegressionSolutionResidualHistogram.cs</DependentUpon> 173 149 </Compile> 174 150 <Compile Include="Solution Views\ClassificationSolutionView.cs"> … … 294 270 </ItemGroup> 295 271 <ItemGroup> 272 <ProjectReference Include="..\..\HeuristicLab.Analysis.Views\3.3\HeuristicLab.Analysis.Views-3.3.csproj"> 273 <Project>{76945D76-CA61-4147-9DC2-0ACDCDDF87F9}</Project> 274 <Name>HeuristicLab.Analysis.Views-3.3</Name> 275 </ProjectReference> 276 <ProjectReference Include="..\..\HeuristicLab.Analysis\3.3\HeuristicLab.Analysis-3.3.csproj"> 277 <Project>{887425B4-4348-49ED-A457-B7D2C26DDBF9}</Project> 278 <Name>HeuristicLab.Analysis-3.3</Name> 279 </ProjectReference> 296 280 <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj"> 297 281 <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project> … … 405 389 <DependentUpon>DataAnalysisProblemView.cs</DependentUpon> 406 390 </EmbeddedResource> 391 <EmbeddedResource Include="Regression\RegressionSolutionResidualHistogram.resx"> 392 <DependentUpon>RegressionSolutionResidualHistogram.cs</DependentUpon> 393 </EmbeddedResource> 407 394 </ItemGroup> 408 395 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.Designer.cs
r7186 r7255 1 namespace HeuristicLab.Problems.DataAnalysis.Views .Regression{1 namespace HeuristicLab.Problems.DataAnalysis.Views { 2 2 partial class RegressionSolutionResidualHistogram { 3 3 /// <summary> … … 41 41 this.chart.Location = new System.Drawing.Point(0, 0); 42 42 this.chart.Name = "chart"; 43 this.chart.Size = new System.Drawing.Size(150, 150); 44 this.chart.TabIndex = 2; 43 this.chart.Size = new System.Drawing.Size(358, 225); 44 this.chart.TabIndex = 0; 45 this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend); 46 this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown); 47 this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove); 45 48 // 46 49 // RegressionSolutionResidualHistogram 47 50 // 51 this.AllowDrop = true; 48 52 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 49 53 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 50 54 this.Controls.Add(this.chart); 51 55 this.Name = "RegressionSolutionResidualHistogram"; 56 this.Size = new System.Drawing.Size(289, 220); 52 57 ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit(); 53 58 this.ResumeLayout(false); … … 57 62 #endregion 58 63 59 private Visualization.ChartControlsExtensions.EnhancedChart chart;64 private HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart chart; 60 65 } 61 66 } -
branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.cs
r7186 r7255 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Drawing; 24 25 using System.Linq; 26 using System.Windows.Forms; 25 27 using System.Windows.Forms.DataVisualization.Charting; 26 28 using HeuristicLab.MainForm; 27 28 namespace HeuristicLab.Problems.DataAnalysis.Views.Regression { 29 using HeuristicLab.MainForm.WindowsForms; 30 31 namespace HeuristicLab.Problems.DataAnalysis.Views { 29 32 [View("Residual Histogram")] 30 33 [Content(typeof(IRegressionSolution))] 31 34 public partial class RegressionSolutionResidualHistogram : DataAnalysisSolutionEvaluationView { 32 private const string ALL_SERIES = "All samples"; 33 private const string TRAINING_SERIES = "Training samples"; 34 private const string TEST_SERIES = "Test samples"; 35 36 // for test purposes 37 private const int bins = 9; 35 protected const string ALL_SAMPLES = "All samples"; 36 protected const string TRAINING_SAMPLES = "Training samples"; 37 protected const string TEST_SAMPLES = "Test samples"; 38 39 //to reduce code duplication 40 protected static string[] ALL_SERIES = new string[] { ALL_SAMPLES, TRAINING_SAMPLES, TEST_SAMPLES }; 41 42 //approximate amount of bins 43 protected const double bins = 25; 44 45 /* 46 * keeps for all series a list for all bins with the position of the bin, the relative frequency of the 47 * residuals and the beginning and the end of the interval of the bin 48 */ 49 protected Dictionary<string, List<List<double>>> relativeFrequencies; 38 50 39 51 public new IRegressionSolution Content { … … 42 54 } 43 55 44 public RegressionSolutionResidualHistogram() { 56 public RegressionSolutionResidualHistogram() 57 : base() { 45 58 InitializeComponent(); 46 59 47 this.chart.Series.Add(ALL_SERIES); 48 this.chart.Series[ALL_SERIES].LegendText = ALL_SERIES; 49 this.chart.Series[ALL_SERIES].ChartType = SeriesChartType.Column; 50 51 //this.chart.Series.Add(TRAINING_SERIES); 52 //this.chart.Series[TRAINING_SERIES].LegendText = TRAINING_SERIES; 53 //this.chart.Series[TRAINING_SERIES].ChartType = SeriesChartType.FastPoint; 54 //this.chart.Series[TRAINING_SERIES].Points.Add(1.0); 55 56 //this.chart.Series.Add(TEST_SERIES); 57 //this.chart.Series[TEST_SERIES].LegendText = TEST_SERIES; 58 //this.chart.Series[TEST_SERIES].ChartType = SeriesChartType.FastPoint; 60 relativeFrequencies = new Dictionary<string, List<List<double>>>(); 61 62 foreach (string series in ALL_SERIES) { 63 this.chart.Series.Add(series); 64 this.chart.Series[series].LegendText = series; 65 this.chart.Series[series].ChartType = SeriesChartType.Column; 66 this.chart.Series[series]["PointWidth"] = "0.9"; 67 this.chart.Series[series].BorderWidth = 1; 68 this.chart.Series[series].BorderDashStyle = ChartDashStyle.Solid; 69 this.chart.Series[series].BorderColor = Color.Black; 70 this.chart.Series[series].ToolTip = series + " Y = #VALY from #CUSTOMPROPERTY(from) to #CUSTOMPROPERTY(to)"; 71 72 relativeFrequencies[series] = new List<List<double>>(); 73 } 59 74 60 75 //configure axis … … 73 88 74 89 private void RedrawChart() { 75 this.chart.Series[ALL_SERIES].Points.Clear(); 90 91 foreach (string series in ALL_SERIES) { 92 this.chart.Series[series].Points.Clear(); 93 this.relativeFrequencies[series].Clear(); 94 } 95 76 96 if (Content != null) { 77 List<double> residuals = new List<double>(); 78 IEnumerable<double> targetValues = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable); 79 IEnumerable<double> estimatedValues = Content.EstimatedValues; 80 for (int i = 0; i < Content.ProblemData.Dataset.Rows; i++) { 81 residuals.Add(estimatedValues.ElementAt(i) - targetValues.ElementAt(i)); 97 98 Dictionary<string, List<double>> residuals = CalculateResiduals(); 99 100 double max = Math.Max(Math.Abs(residuals[ALL_SAMPLES].Min()), Math.Abs(residuals[ALL_SAMPLES].Max())); 101 double intervalWidth = (max * 2.0) / bins; 102 103 max = HumanRoundMax(max); 104 intervalWidth = HumanRoundMax(intervalWidth); 105 106 foreach (string series in ALL_SERIES) { 107 CalculateFrequencies(residuals[series], series, max, intervalWidth); 82 108 } 83 109 84 //no check if both are negative 85 //assumption that all values are around zero 86 double max = Math.Ceiling(Math.Max(Math.Abs(residuals.Min()), Math.Abs(residuals.Max()))); 87 double intervalWidth = (max * 2) / bins; 88 double intervalCenter = intervalWidth / 2.0; 89 double current = -max; 90 91 Series histogramSeries = this.chart.Series[ALL_SERIES]; 92 93 Dictionary<double, int> frequencies = new Dictionary<double, int>(); 94 95 for (int i = 0; i <= bins; i++) { 96 IEnumerable<double> help = residuals.Where(x => x >= (current - intervalCenter) && x < (current + intervalCenter)); 97 frequencies.Add(current, help.Count()); 98 current += intervalWidth; 110 ChartArea chartArea = chart.ChartAreas[0]; 111 112 chartArea.AxisX.Minimum = -max - intervalWidth; 113 chartArea.AxisX.Maximum = max + intervalWidth; 114 chartArea.AxisY.Maximum = relativeFrequencies[ALL_SAMPLES].Select(x => x.ElementAt(1)).Max() + 0.02; 115 chartArea.AxisY.Interval = 0.1; 116 117 chartArea.AxisX.Interval = intervalWidth; 118 int curBins = (int)Math.Round(max / intervalWidth); 119 //shifts the x axis label so that zero is in the middle 120 if (curBins % 2 == 0) 121 chartArea.AxisX.IntervalOffset = intervalWidth; 122 else 123 chartArea.AxisX.IntervalOffset = intervalWidth / 2; 124 } 125 } 126 127 private Dictionary<string, List<double>> CalculateResiduals() { 128 Dictionary<string, List<double>> residuals = new Dictionary<string, List<double>>(); 129 130 foreach (string series in ALL_SERIES) { 131 residuals[series] = new List<double>(); 132 } 133 134 IRegressionProblemData problemdata = Content.ProblemData; 135 List<double> targetValues = problemdata.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToList(); 136 List<double> estimatedValues = Content.EstimatedValues.ToList(); 137 138 for (int i = 0; i < Content.ProblemData.Dataset.Rows; i++) { 139 double residual = estimatedValues[i] - targetValues[i]; 140 residuals[ALL_SAMPLES].Add(residual); 141 if (i >= problemdata.TrainingPartition.Start && i < problemdata.TrainingPartition.End) 142 residuals[TRAINING_SAMPLES].Add(residual); 143 if (i >= problemdata.TestPartition.Start && i < problemdata.TestPartition.End) 144 residuals[TEST_SAMPLES].Add(residual); 145 } 146 147 return residuals; 148 } 149 150 private void CalculateFrequencies(List<double> residualValues, string series, double max, double intervalWidth) { 151 Series residualSeries = this.chart.Series[series]; 152 153 double intervalCenter = intervalWidth / 2.0; 154 double sampleCount = residualValues.Count(); 155 double current = -max; 156 157 for (int i = 0; i <= bins; i++) { 158 IEnumerable<double> help = residualValues.Where(x => x >= (current - intervalCenter) && x < (current + intervalCenter)); 159 relativeFrequencies[series].Add(new List<double>() { current, help.Count() / sampleCount, current - intervalCenter, current + intervalCenter }); 160 current += intervalWidth; 161 } 162 163 ShowValues(residualSeries, relativeFrequencies[series]); 164 } 165 166 private void ToggleSeriesData(Series series) { 167 if (series.Points.Count > 0) { //checks if series is shown 168 if (this.chart.Series.Any(s => s != series && s.Points.Count > 0)) { 169 series.Points.Clear(); 99 170 } 100 101 foreach (var item in frequencies) { 102 histogramSeries.Points.AddXY(item.Key, item.Value); 103 } 104 } 171 } else if (Content != null) { 172 ShowValues(series, relativeFrequencies[series.Name]); 173 chart.Legends[series.Legend].ForeColor = Color.Black; 174 chart.Refresh(); 175 } 176 } 177 178 private void ShowValues(Series series, List<List<double>> relativeSeriesFrequencies) { 179 DataPointCollection seriesPoints = series.Points; 180 181 foreach (var valueList in relativeSeriesFrequencies) { 182 seriesPoints.AddXY(valueList[0], valueList[1]); 183 seriesPoints[seriesPoints.Count - 1]["from"] = valueList[2].ToString(); 184 seriesPoints[seriesPoints.Count - 1]["to"] = valueList[3].ToString(); 185 } 186 } 187 188 private double HumanRoundMax(double max) { 189 double base10; 190 if (max > 0) base10 = Math.Pow(10.0, Math.Floor(Math.Log10(max))); 191 else base10 = Math.Pow(10.0, Math.Ceiling(Math.Log10(-max))); 192 double rounding = (max > 0) ? base10 : -base10; 193 while (rounding < max) rounding += base10; 194 return rounding; 105 195 } 106 196 … … 127 217 RedrawChart(); 128 218 } 219 220 private void chart_MouseDown(object sender, MouseEventArgs e) { 221 HitTestResult result = chart.HitTest(e.X, e.Y); 222 if (result.ChartElementType == ChartElementType.LegendItem) { 223 ToggleSeriesData(result.Series); 224 } 225 } 226 private void chart_MouseMove(object sender, MouseEventArgs e) { 227 HitTestResult result = chart.HitTest(e.X, e.Y); 228 if (result.ChartElementType == ChartElementType.LegendItem) 229 Cursor = Cursors.Hand; 230 else 231 Cursor = Cursors.Default; 232 } 233 private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) { 234 if (chart.Series.Count != 3) return; 235 e.LegendItems[0].Cells[1].ForeColor = this.chart.Series[ALL_SAMPLES].Points.Count == 0 ? Color.Gray : Color.Black; 236 e.LegendItems[1].Cells[1].ForeColor = this.chart.Series[TRAINING_SAMPLES].Points.Count == 0 ? Color.Gray : Color.Black; 237 e.LegendItems[2].Cells[1].ForeColor = this.chart.Series[TEST_SAMPLES].Points.Count == 0 ? Color.Gray : Color.Black; 238 } 129 239 #endregion 130 240 }
Note: See TracChangeset
for help on using the changeset viewer.