Package edu.cnu.mdi.splot.pdata
Class FitVectors
java.lang.Object
edu.cnu.mdi.splot.pdata.FitVectors
- Direct Known Subclasses:
HistoFitPrep.FitWindowData
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 -
Constructor Summary
ConstructorsConstructorDescriptionFitVectors(double[] x, double[] y, double[] weights) Create fit vectors from raw arrays.FitVectors(DataColumn xcol, DataColumn ycol, DataColumn ecol) Create fit vectors from data columns. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanbooleanisUsable()Lightweight sanity check for callers that want to “attempt a fit” without throwing.intlength()static FitVectorstestData(Evaluator evaluator, double xStart, double xEnd, int nPoints, double jitterPercent, double sigmaYPercent) Generate test data (with randomness)for fitting.
-
Field Details
-
x
public final double[] xx data (length n). -
y
public final double[] yy data (length n). -
w
public final double[] wOptional 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
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 valuesxStart- starting x valuexEnd- ending x valuenPoints- number of points evenly spaced between xStart and xEndjitterPercent- 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 whenyTrueis 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)
-