- Timestamp:
- 06/30/17 16:41:06 (7 years ago)
- Location:
- stable
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 14435-14439,14457-14458,14493,14508,14516,14519,14582,14740,14860-14861,14982,14984,14987,14992,15042,15068,15095
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Analysis.Views
-
stable/HeuristicLab.Analysis.Views/3.3/ScatterPlotView.cs
r14982 r15097 571 571 572 572 double[] coefficients; 573 if (!Fitting(row, out coefficients)) 573 if (!Fitting(row, out coefficients)) { 574 regressionSeries.LegendToolTip = "Could not calculate regression."; 574 575 return; 576 } 575 577 576 578 // Fill regrssion series 577 var validPoints = row.Points.Where(p => !IsInvalidValue(p.X)); 578 double min = validPoints.Min(p => p.X), max = validPoints.Max(p => p.X); 579 double range = max - min, delta = range / row.Points.Count; 580 for (double x = min; x < max; x += delta) { 581 regressionSeries.Points.AddXY(x, Estimate(x, row, coefficients)); 579 double min = row.Points.Min(p => p.X), max = row.Points.Max(p => p.X); 580 double range = max - min, delta = range / Math.Max(row.Points.Count - 1, 50); 581 if (range > double.Epsilon) { 582 for (double x = min; x <= max; x += delta) { 583 regressionSeries.Points.AddXY(x, Estimate(x, row, coefficients)); 584 } 582 585 } 583 586 … … 657 660 658 661 protected static bool Fitting(ScatterPlotDataRow row, out double[] coefficients) { 662 if (!IsValidRegressionData(row)) { 663 coefficients = new double[0]; 664 return false; 665 } 666 659 667 var xs = row.Points.Select(p => p.X).ToList(); 660 668 var ys = row.Points.Select(p => p.Y).ToList(); … … 688 696 // Linear fitting 689 697 bool success = LinearFitting(matrix, nRows, out coefficients); 690 if (!success) return success;698 if (!success) return false; 691 699 692 700 // Output transformation … … 698 706 } 699 707 708 return true; 709 } 710 protected static bool IsValidRegressionData(ScatterPlotDataRow row) { 711 // No invalid values allowed 712 for (int i = 0; i < row.Points.Count; i++) { 713 if (IsInvalidValue(row.Points[i].X) || IsInvalidValue(row.Points[i].Y)) 714 return false; 715 } 716 // Exp, Power and Log Regression do not work with negative values 717 switch (row.VisualProperties.RegressionType) { 718 case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType.Exponential: 719 for (int i = 0; i < row.Points.Count; i++) { 720 if (row.Points[i].Y <= 0) 721 return false; 722 } 723 break; 724 case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType.Power: 725 for (int i = 0; i < row.Points.Count; i++) { 726 if (row.Points[i].X <= 0 || row.Points[i].Y <= 0) 727 return false; 728 } 729 break; 730 case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType.Logarithmic: 731 for (int i = 0; i < row.Points.Count; i++) { 732 if (row.Points[i].X <= 0) 733 return false; 734 } 735 break; 736 } 700 737 return true; 701 738 }
Note: See TracChangeset
for help on using the changeset viewer.