Package edu.cnu.mdi.splot.fit
Class GaussianFitter
java.lang.Object
edu.cnu.mdi.splot.fit.ALeastSquaresFitter
edu.cnu.mdi.splot.fit.GaussianFitter
- All Implemented Interfaces:
IFitStringGetter,IFitter
Nonlinear least-squares fitter for a 4-parameter Gaussian with baseline:
y(x) = A * exp(-(x - mu) ^ 2 / (2 * sigma ^ 2)) + B
Parameter ordering
params[0] = Aparams[1] = muparams[2] = sigmaparams[3] = B
Bounds / validation
This fitter enforcessigma >= DEFAULT_MIN_SIGMA by default using a parameter clamping
validator. Optional bounds can also be supplied via GaussianFitter.ParameterBounds.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classSimple bounds container for the Gaussian parameters. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleDefault minimum allowed sigma to avoid division by zero and ill-conditioned Jacobians.static final intParameter indices.static final intstatic final intstatic final intstatic final String[]Parameter names.Fields inherited from class edu.cnu.mdi.splot.fit.ALeastSquaresFitter
CAPSIG, checker, covarianceThreshold, initialGuesser, maxEvaluations, maxIterations, MU, OMEGA, optimizer, PHI, SMALLSIG, SUB0, SUB1, SUB2, subArray, SUBN, SUP0, SUP1, SUP2, SUPN -
Constructor Summary
ConstructorsConstructorDescriptionCreate with a Levenberg-Marquardt optimizer and a robust default guesser.GaussianFitter(org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer optimizer) Create with a custom optimizer and robust default guesser. -
Method Summary
Modifier and TypeMethodDescriptionasEvaluator(FitResult fit) Build a value getter using the fitted parameters.protected double[]defaultInitialGuess(double[] x, double[] y, double[] weights) Default initial guess used if the caller does not provide an explicit override.protected org.apache.commons.math3.fitting.leastsquares.ParameterValidatorDefault validator/bounds policy (optional).fit(double[] x, double[] y, double[] weights, GaussianFitter.ParameterBounds bounds, double[] initialGuess) Expert overload: fit with optional weights, optional bounds, and optional initial guess.protected intGet the descriptive string getter for this fitter.protected org.apache.commons.math3.fitting.leastsquares.MultivariateJacobianFunctionmodel(double[] x) Build the model + analytic (or numeric) Jacobian for this fitter, given x values.parameterName(int index) Get the parameter name for the given index.Methods inherited from class edu.cnu.mdi.splot.fit.ALeastSquaresFitter
buildFitResult, clampingValidator, fit, fit, fit, getChecker, getCovarianceThreshold, getMaxEvaluations, getMaxIterations, safeCovariances, validateWeights, validateXY, weightsFromSigmaY
-
Field Details
-
IDX_A
public static final int IDX_AParameter indices.- See Also:
-
IDX_MU
public static final int IDX_MU- See Also:
-
IDX_SIGMA
public static final int IDX_SIGMA- See Also:
-
IDX_B
public static final int IDX_B- See Also:
-
paramNames
Parameter names. -
DEFAULT_MIN_SIGMA
public static final double DEFAULT_MIN_SIGMADefault minimum allowed sigma to avoid division by zero and ill-conditioned Jacobians.- See Also:
-
-
Constructor Details
-
GaussianFitter
public GaussianFitter()Create with a Levenberg-Marquardt optimizer and a robust default guesser. -
GaussianFitter
public GaussianFitter(org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer optimizer) Create with a custom optimizer and robust default guesser.
-
-
Method Details
-
getParameterCount
protected int getParameterCount()- Specified by:
getParameterCountin classALeastSquaresFitter- Returns:
- number of parameters for this fitter.
-
model
protected org.apache.commons.math3.fitting.leastsquares.MultivariateJacobianFunction model(double[] x) Description copied from class:ALeastSquaresFitterBuild the model + analytic (or numeric) Jacobian for this fitter, given x values.- Specified by:
modelin classALeastSquaresFitter- Parameters:
x- x data (length n)- Returns:
- a
MultivariateJacobianFunctioncompatible with Commons Math least-squares
-
defaultInitialGuess
protected double[] defaultInitialGuess(double[] x, double[] y, double[] weights) Description copied from class:ALeastSquaresFitterDefault initial guess used if the caller does not provide an explicit override. The default implementation delegates to theALeastSquaresFitter.initialGuesser.Subclasses may override if they have a better model-specific guess.
- Overrides:
defaultInitialGuessin classALeastSquaresFitter- Parameters:
x- x datay- y dataweights- optional weights (may be null)- Returns:
- initial parameter vector of length
ALeastSquaresFitter.getParameterCount()
-
defaultValidator
protected org.apache.commons.math3.fitting.leastsquares.ParameterValidator defaultValidator()Description copied from class:ALeastSquaresFitterDefault validator/bounds policy (optional).Return null for "no validation". For simple bound constraints, consider using
ALeastSquaresFitter.clampingValidator(double[], double[]).- Overrides:
defaultValidatorin classALeastSquaresFitter- Returns:
- a parameter validator or null
-
fit
public FitResult fit(double[] x, double[] y, double[] weights, GaussianFitter.ParameterBounds bounds, double[] initialGuess) Expert overload: fit with optional weights, optional bounds, and optional initial guess.If
boundsis null, onlysigma >= DEFAULT_MIN_SIGMAis enforced.- Parameters:
x- x datay- y dataweights- optional weights (typically 1/sigmaY^2), may be nullbounds- optional bounds, may be nullinitialGuess- optional initial guess, may be null- Returns:
- fit result
-
asEvaluator
Build a value getter using the fitted parameters.- Specified by:
asEvaluatorin classALeastSquaresFitter- Parameters:
fit- fit result- Returns:
- an evaluator for the fitted Gaussian
-
modelName
- Returns:
- model name suitable for a legend or report
-
functionForm
- Returns:
- mathematical function form suitable for display
-
parameterName
Get the parameter name for the given index.- Parameters:
index- the parameter index- Returns:
- the parameter name
-
getStringGetter
Description copied from class:ALeastSquaresFitterGet the descriptive string getter for this fitter.- Specified by:
getStringGetterin classALeastSquaresFitter- Returns:
- the string getter
-