Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/16/17 12:53:53 (7 years ago)
Author:
pfleck
Message:

#2713

  • Fixed problems with negative values for some regression types.
  • Fixed issue where the regression line was not drawn up to the last point.
  • Tool strip now reads "Configure Chart...".
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Analysis.Views/3.3/ScatterPlotView.cs

    r14982 r14987  
    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) {
     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      for (double x = min; x <= max; x += delta) {
    581582        regressionSeries.Points.AddXY(x, Estimate(x, row, coefficients));
    582583      }
     
    657658
    658659    protected static bool Fitting(ScatterPlotDataRow row, out double[] coefficients) {
     660      if (!IsValidRegressionData(row)) {
     661        coefficients = new double[0];
     662        return false;
     663      }
     664
    659665      var xs = row.Points.Select(p => p.X).ToList();
    660666      var ys = row.Points.Select(p => p.Y).ToList();
     
    688694      // Linear fitting
    689695      bool success = LinearFitting(matrix, nRows, out coefficients);
    690       if (!success) return success;
     696      if (!success) return false;
    691697
    692698      // Output transformation
     
    698704      }
    699705
     706      return true;
     707    }
     708    protected static bool IsValidRegressionData(ScatterPlotDataRow row) {
     709      // No invalid values allowed
     710      for (int i = 0; i < row.Points.Count; i++) {
     711        if (IsInvalidValue(row.Points[i].X) || IsInvalidValue(row.Points[i].Y))
     712          return false;
     713      }
     714      // Exp, Power and Log Regression do not work with negative values
     715      switch (row.VisualProperties.RegressionType) {
     716        case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType.Exponential:
     717          for (int i = 0; i < row.Points.Count; i++) {
     718            if (row.Points[i].Y <= 0)
     719              return false;
     720          }
     721          break;
     722        case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType.Power:
     723          for (int i = 0; i < row.Points.Count; i++) {
     724            if (row.Points[i].X <= 0 || row.Points[i].Y <= 0)
     725              return false;
     726          }
     727          break;
     728        case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType.Logarithmic:
     729          for (int i = 0; i < row.Points.Count; i++) {
     730            if (row.Points[i].X <= 0)
     731              return false;
     732          }
     733          break;
     734      }
    700735      return true;
    701736    }
Note: See TracChangeset for help on using the changeset viewer.