Class FitVectors

java.lang.Object
edu.cnu.mdi.splot.pdata.FitVectors
Direct Known Subclasses:
HistoFitPrep.FitWindowData

public class FitVectors extends Object
Immutable fit vectors (x, y, optional weights) used by the Apache least-squares fitters.

Weights are derived from the Y-error column e using w = 1/(e^2). If an error value is non-finite or <= 0, the corresponding weight is set to 0, which effectively removes that point from a weighted fit.

Important: This class validates that X and Y have the same length, and if an error column is provided, that it matches Y length as well.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final double[]
    Optional weights (length n) or null.
    final double[]
    x data (length n).
    final double[]
    y data (length n).
  • Constructor Summary

    Constructors
    Constructor
    Description
    FitVectors(double[] x, double[] y, double[] weights)
    Create fit vectors from raw arrays.
    Create fit vectors from data columns.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    boolean
     
    boolean
    Lightweight sanity check for callers that want to “attempt a fit” without throwing.
    int
     
    static FitVectors
    testData(Evaluator evaluator, double xStart, double xEnd, int nPoints, double jitterPercent, double sigmaYPercent)
    Generate test data (with randomness)for fitting.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • x

      public final double[] x
      x data (length n).
    • y

      public final double[] y
      y data (length n).
    • w

      public final double[] w
      Optional weights (length n) or null. Convention: w[i] = 1/(sigmaY[i]^2).
  • Constructor Details

    • FitVectors

      public FitVectors(double[] x, double[] y, double[] weights)
      Create fit vectors from raw arrays.
      Parameters:
      x - the X data array (non-null)
      y - the Y data array (non-null)
      weights - the weights array (may be null)
      Throws:
      IllegalArgumentException - if array lengths are inconsistent
    • FitVectors

      public FitVectors(DataColumn xcol, DataColumn ycol, DataColumn ecol)
      Create fit vectors from data columns.
      Parameters:
      xcol - the X data column (non-null)
      ycol - the Y data column (non-null)
      ecol - the E (Y error bar) data column (may be null)
      Throws:
      IllegalArgumentException - if column lengths are inconsistent
  • Method Details

    • length

      public int length()
      Returns:
      number of points.
    • hasWeights

      public boolean hasWeights()
      Returns:
      true if weights are present (array is non-null).
    • hasAnyPositiveWeight

      public boolean hasAnyPositiveWeight()
      Returns:
      true if there is at least one strictly positive weight. Useful to avoid degenerate weighted problems when all weights are 0.
    • isUsable

      public boolean isUsable()
      Lightweight sanity check for callers that want to “attempt a fit” without throwing.
      Returns:
      true if x/y exist, lengths match, and there are at least 2 points
    • testData

      public static FitVectors testData(Evaluator evaluator, double xStart, double xEnd, int nPoints, double jitterPercent, double sigmaYPercent)
      Generate test data (with randomness)for fitting.
      Parameters:
      evaluator - the evaluator to generate y values
      xStart - starting x value
      xEnd - ending x value
      nPoints - number of points evenly spaced between xStart and xEnd
      jitterPercent - percentage jitter to apply to y values. The jitter is computed as a random percentage [0, jitterPercentage] of the y value.
      sigmaYPercent - percentage of the signal scale to use as sigmaY. The sigmaY is computed as a random percentage [0, sigmaYPercent] of |yTrue| (falling back to a scale of 1.0 when yTrue is zero or non-finite, to avoid a degenerate sigma of 0).
      Returns:
      the fit vectors, with weights derived from sigmaY by w = 1/(sigmaY^2)