- Timestamp:
- 05/02/16 14:58:57 (9 years ago)
- Location:
- branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChart.cs
r13818 r13820 32 32 namespace HeuristicLab.Problems.DataAnalysis.Views { 33 33 public partial class GradientChart : EnhancedChart { 34 private ModifiableDataset internalDataset;34 private ModifiableDataset dataset; 35 35 36 36 public bool ShowLegend { get; set; } 37 public bool ShowXAxisLabel { get; set; } 38 public bool ShowYAxisLabel { get; set; } 39 public bool ShowCursor { get; set; } 37 40 38 41 private bool useMedianValues; … … 98 101 throw new ArgumentException("The problem data provided does not contain all the variables required by the solutions."); 99 102 problemData = value; 100 Update InternalDataset();103 UpdateDataset(); 101 104 UpdateChart(); 102 105 } … … 178 181 this.points = points; 179 182 180 Update InternalDataset();183 UpdateDataset(); 181 184 UpdateChart(); 182 185 } … … 188 191 this.problemData = pd; 189 192 this.variable = variable; 190 this. internalDataset = dataset;193 this.dataset = dataset; 191 194 this.min = min; 192 195 this.max = max; … … 196 199 public void UpdateChart() { 197 200 // throw exceptions? 198 if ( internalDataset == null || solutionList == null || !solutionList.Any())201 if (dataset == null || solutionList == null || !solutionList.Any()) 199 202 return; 200 203 if (min.IsAlmost(max) || min > max || points == 0) 201 204 return; 202 205 Series.Clear(); 203 var vla = VerticalLineAnnotation;204 vla.Visible = true;205 206 Annotations.Clear(); 206 Annotations.Add(vla); 207 208 var defaultValue = dataset.GetDoubleValue(variable, 0); 209 if (ShowCursor) { 210 var vla = VerticalLineAnnotation; 211 vla.Visible = true; 212 Annotations.Add(vla); 213 vla.X = defaultValue; 214 } 215 207 216 double axisMin, axisMax, axisInterval; 208 217 // calculate X-axis interval … … 218 227 series.Name = Target + " " + i; 219 228 Series.Add(series); 220 var p = series.Points.Last();221 vla.X = p.XValue;222 229 } 223 230 // calculate Y-axis interval … … 232 239 axis.Maximum = axisMax; 233 240 axis.Interval = axisInterval; 234 ChartAreas[0].AxisX.Title = Variable + " : " + vla.X.ToString("N3", CultureInfo.CurrentCulture); // set axis titlet 241 242 if (ShowXAxisLabel) { 243 ChartAreas[0].AxisX.Title = Variable + " : " + defaultValue.ToString("N3", CultureInfo.CurrentCulture); // set axis title 244 } 245 235 246 AddStripLines(); // add strip lines 236 247 if (ShowLegend) … … 238 249 } 239 250 240 private void Update InternalDataset() {251 private void UpdateDataset() { 241 252 var variables = ProblemData.Dataset.DoubleVariables.ToList(); 242 253 var variableValues = new List<double>[variables.Count]; … … 253 264 } 254 265 } 255 internalDataset = new ModifiableDataset(variables, variableValues);266 dataset = new ModifiableDataset(variables, variableValues); 256 267 } 257 268 258 269 private double GetEstimatedValue(IRegressionSolution solution, double x) { 259 var v = internalDataset.GetDoubleValue(Variable, 0);260 internalDataset.SetVariableValue(x, Variable, 0);261 var y = solution.Model.GetEstimatedValues( internalDataset, new[] { 0 }).Single();262 internalDataset.SetVariableValue(v, Variable, 0);270 var v = dataset.GetDoubleValue(Variable, 0); 271 dataset.SetVariableValue(x, Variable, 0); 272 var y = solution.Model.GetEstimatedValues(dataset, new[] { 0 }).Single(); 273 dataset.SetVariableValue(v, Variable, 0); 263 274 return y; 264 275 } 265 276 266 277 private Series PlotSeries(IRegressionSolution solution) { 267 var v = internalDataset.GetDoubleValue(variable, 0);278 var v = dataset.GetDoubleValue(variable, 0); 268 279 var series = new Series { ChartType = SeriesChartType.Point }; 269 280 270 281 var step = (max - min) / points; 271 282 var axisX = ChartAreas[0].AxisX; 272 axisX.Title = Variable + " : " + v.ToString("N3", CultureInfo.CurrentCulture); 283 if (ShowXAxisLabel) { 284 axisX.Title = Variable + " : " + v.ToString("N3", CultureInfo.CurrentCulture); 285 } 273 286 var axisY = ChartAreas[0].AxisY; 274 axisY.Title = Target;287 if (ShowYAxisLabel) { axisY.Title = Target; } 275 288 double y; 276 289 // lefthand section outside of the training range … … 290 303 } 291 304 292 y = GetEstimatedValue(solution, v); 293 series.Points.Add(new DataPoint(v, y) { MarkerSize = 5, MarkerColor = Color.Red }); 294 series.IsVisibleInLegend = true; 305 if (ShowCursor) { 306 y = GetEstimatedValue(solution, v); 307 series.Points.Add(new DataPoint(v, y) { MarkerSize = 5, MarkerColor = Color.Red }); 308 } 309 if (ShowLegend) { 310 series.IsVisibleInLegend = true; 311 } 295 312 296 313 return series; … … 340 357 var annotation = VerticalLineAnnotation; 341 358 var x = annotation.X; 342 internalDataset.SetVariableValue(x, Variable, 0);359 dataset.SetVariableValue(x, Variable, 0); 343 360 for (int i = 0; i < solutionList.Count; ++i) { 344 361 var y = GetEstimatedValue(solutionList[i], x); … … 347 364 s.Points[n - 1] = new DataPoint(x, y) { MarkerColor = Color.Red, MarkerSize = 5 }; 348 365 } 349 ChartAreas[0].AxisX.Title = Variable + " : " + x.ToString("N3", CultureInfo.CurrentCulture); 366 if (ShowXAxisLabel) { 367 ChartAreas[0].AxisX.Title = Variable + " : " + x.ToString("N3", CultureInfo.CurrentCulture); 368 } 350 369 Update(); 351 370 OnVariableValueChanged(this, EventArgs.Empty); … … 360 379 if (e.NewLocationX < axisX.Minimum) 361 380 e.NewLocationX = axisX.Minimum; 362 // var x = e.NewLocationX;363 // internalDataset.SetVariableValue(x, Variable, 0);364 // for (int i = 0; i < solutionList.Count; ++i) {365 // var y = GetEstimatedValue(solutionList[i], x);366 // var s = Series[i];367 // var n = s.Points.Count;368 // s.Points[n - 1] = new DataPoint(x, y) { MarkerColor = Color.Red, MarkerSize = 5 };369 // }370 // ChartAreas[0].AxisX.Title = Variable + " : " + x.ToString("N3", CultureInfo.CurrentCulture);371 // Update();372 // OnVariableValueChanged(this, EventArgs.Empty);373 381 } 374 382 -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/RegressionSolutionTargetResponseGradientView.cs
r13818 r13820 80 80 if (v < min) min = v; 81 81 } 82 var gradientChart = new GradientChart { Dock = DockStyle.Fill, ShowLegend = false, Margin = Padding.Empty }; 82 var gradientChart = new GradientChart { 83 Dock = DockStyle.Fill, 84 Margin = Padding.Empty, 85 ShowLegend = false, 86 ShowCursor = true, 87 ShowXAxisLabel = true, 88 ShowYAxisLabel = true 89 }; 83 90 gradientChart.VariableValueChanged += (o, e) => { 84 91 foreach (var chart in gradientChartTableLayout.Controls.Cast<GradientChart>()) {
Note: See TracChangeset
for help on using the changeset viewer.