- Timestamp:
- 06/25/12 15:05:28 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.Designer.cs
r7967 r8104 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( 358, 225);43 this.chart.Size = new System.Drawing.Size(289, 220); 44 44 this.chart.TabIndex = 0; 45 45 this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend); … … 50 50 // 51 51 this.AllowDrop = true; 52 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);53 52 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 54 53 this.Controls.Add(this.chart); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.cs
r8098 r8104 38 38 protected const string TRAINING_SAMPLES = "Training samples"; 39 39 protected const string TEST_SAMPLES = "Test samples"; 40 /// <summary>41 /// used to reduce code duplication42 /// </summary>43 protected readonly string[] ALL_SERIES = new string[] { ALL_SAMPLES, TRAINING_SAMPLES, TEST_SAMPLES };44 40 /// <summary> 45 41 /// approximate amount of bins … … 62 58 InitializeComponent(); 63 59 relativeFrequencies = new Dictionary<string, List<List<double>>>(); 64 foreach (string series in ALL_SERIES) {60 foreach (string series in new List<String>() { ALL_SAMPLES, TRAINING_SAMPLES, TEST_SAMPLES }) { 65 61 chart.Series.Add(series); 66 62 chart.Series[series].LegendText = series; … … 87 83 88 84 private void RedrawChart() { 89 foreach ( string series in ALL_SERIES) {90 chart.Series[series].Points.Clear();91 relativeFrequencies[series ].Clear();85 foreach (Series series in chart.Series) { 86 series.Points.Clear(); 87 relativeFrequencies[series.Name].Clear(); 92 88 } 93 89 if (Content != null) { 94 Dictionary<string, List<double>> residuals = CalculateResiduals();95 double realMax = Math.Max(Math.Abs(residuals [ALL_SAMPLES].Min()), Math.Abs(residuals[ALL_SAMPLES].Max()));90 List<double> residuals = CalculateResiduals(); 91 double realMax = Math.Max(Math.Abs(residuals.Min()), Math.Abs(residuals.Max())); 96 92 double roundedMax = HumanRoundMax(realMax); 97 93 double intervalWidth = (roundedMax * 2.0) / bins; … … 102 98 roundedMax = help * intervalWidth; 103 99 104 foreach ( string series in ALL_SERIES) {105 CalculateFrequencies(residuals [series], series, roundedMax, intervalWidth);100 foreach (Series series in chart.Series) { 101 CalculateFrequencies(residuals, series.Name, roundedMax, intervalWidth); 106 102 if (!series.Equals(ALL_SAMPLES)) 107 ShowValues( chart.Series[series], relativeFrequencies[series]);103 ShowValues(series); 108 104 } 109 105 … … 132 128 } 133 129 134 private Dictionary<string, List<double>> CalculateResiduals() { 135 Dictionary<string, List<double>> residuals = new Dictionary<string, List<double>>(); 136 137 foreach (string series in ALL_SERIES) { 138 residuals[series] = new List<double>(); 139 } 130 private List<double> CalculateResiduals() { 131 List<double> residuals = new List<double>(); 132 140 133 IRegressionProblemData problemdata = Content.ProblemData; 141 134 List<double> targetValues = problemdata.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToList(); … … 144 137 for (int i = 0; i < Content.ProblemData.Dataset.Rows; i++) { 145 138 double residual = estimatedValues[i] - targetValues[i]; 146 residuals[ALL_SAMPLES].Add(residual); 147 if (i >= problemdata.TrainingPartition.Start && i < problemdata.TrainingPartition.End) 148 residuals[TRAINING_SAMPLES].Add(residual); 149 if (i >= problemdata.TestPartition.Start && i < problemdata.TestPartition.End) 150 residuals[TEST_SAMPLES].Add(residual); 139 residuals.Add(residual); 151 140 } 152 141 return residuals; … … 154 143 155 144 private void CalculateFrequencies(List<double> residualValues, string series, double max, double intervalWidth) { 145 IEnumerable<double> relevantResiduals = residualValues; 146 IRegressionProblemData problemdata = Content.ProblemData; 147 if (series.Equals(TRAINING_SAMPLES)) { 148 relevantResiduals = residualValues.Skip(problemdata.TrainingPartition.Start).Take(problemdata.TrainingPartition.Size); 149 } else if (series.Equals(TEST_SAMPLES)) { 150 relevantResiduals = residualValues.Skip(problemdata.TestPartition.Start).Take(problemdata.TestPartition.Size); 151 } 152 156 153 double intervalCenter = intervalWidth / 2.0; 157 double sampleCount = re sidualValues.Count;154 double sampleCount = relevantResiduals.Count(); 158 155 double current = -max; 159 156 160 157 for (int i = 0; i <= bins; i++) { 161 IEnumerable<double> help = re sidualValues.Where(x => x >= (current - intervalCenter) && x < (current + intervalCenter));158 IEnumerable<double> help = relevantResiduals.Where(x => x >= (current - intervalCenter) && x < (current + intervalCenter)); 162 159 relativeFrequencies[series].Add(new List<double>() { current, help.Count() / sampleCount, current - intervalCenter, current + intervalCenter }); 163 160 current += intervalWidth; 161 } 162 } 163 164 private void ShowValues(Series series) { 165 List<List<double>> relativeSeriesFrequencies = relativeFrequencies[series.Name]; 166 DataPointCollection seriesPoints = series.Points; 167 168 foreach (var valueList in relativeSeriesFrequencies) { 169 seriesPoints.AddXY(valueList[0], valueList[1]); 170 seriesPoints[seriesPoints.Count - 1]["from"] = valueList[2].ToString(); 171 seriesPoints[seriesPoints.Count - 1]["to"] = valueList[3].ToString(); 172 } 173 } 174 175 private void ToggleSeriesData(Series series) { 176 if (series.Points.Count > 0) { //checks if series is shown 177 if (chart.Series.Any(s => s != series && s.Points.Count > 0)) { 178 series.Points.Clear(); 179 } 180 } else if (Content != null) { 181 ShowValues(series); 182 chart.Legends[series.Legend].ForeColor = Color.Black; 183 chart.Refresh(); 164 184 } 165 185 } … … 216 236 } 217 237 #endregion 218 219 private void ToggleSeriesData(Series series) {220 if (series.Points.Count > 0) { //checks if series is shown221 if (chart.Series.Any(s => s != series && s.Points.Count > 0)) {222 series.Points.Clear();223 }224 } else if (Content != null) {225 ShowValues(series, relativeFrequencies[series.Name]);226 chart.Legends[series.Legend].ForeColor = Color.Black;227 chart.Refresh();228 }229 }230 private void ShowValues(Series series, List<List<double>> relativeSeriesFrequencies) {231 DataPointCollection seriesPoints = series.Points;232 233 foreach (var valueList in relativeSeriesFrequencies) {234 seriesPoints.AddXY(valueList[0], valueList[1]);235 seriesPoints[seriesPoints.Count - 1]["from"] = valueList[2].ToString();236 seriesPoints[seriesPoints.Count - 1]["to"] = valueList[3].ToString();237 }238 }239 238 } 240 239 }
Note: See TracChangeset
for help on using the changeset viewer.