Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/30/17 16:41:06 (7 years ago)
Author:
pfleck
Message:

#2713 #2715 #2765
Merged to stable

  • 14435-14439,14493,14516,14519,14982,14987,14992,15042 (from #2713)
  • 14457-14458,14508,14582,14740,14984,15068,15095 (from #2715)
  • 14860-14861 (from #2765)
Location:
stable
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Analysis.Views

  • stable/HeuristicLab.Analysis.Views/3.3/ScatterPlotView.cs

    r14982 r15097  
    571571
    572572      double[] coefficients;
    573       if (!Fitting(row, out coefficients))
     573      if (!Fitting(row, out coefficients)) {
     574        regressionSeries.LegendToolTip = "Could not calculate regression.";
    574575        return;
     576      }
    575577
    576578      // 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        }
    582585      }
    583586
     
    657660
    658661    protected static bool Fitting(ScatterPlotDataRow row, out double[] coefficients) {
     662      if (!IsValidRegressionData(row)) {
     663        coefficients = new double[0];
     664        return false;
     665      }
     666
    659667      var xs = row.Points.Select(p => p.X).ToList();
    660668      var ys = row.Points.Select(p => p.Y).ToList();
     
    688696      // Linear fitting
    689697      bool success = LinearFitting(matrix, nRows, out coefficients);
    690       if (!success) return success;
     698      if (!success) return false;
    691699
    692700      // Output transformation
     
    698706      }
    699707
     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      }
    700737      return true;
    701738    }
Note: See TracChangeset for help on using the changeset viewer.