Class PowerLawFitter
- All Implemented Interfaces:
IFitStringGetter,IFitter
y(x) = A * x^n + C
Parameter ordering
params[0] = A— amplitudeparams[1] = n— exponent (real-valued, unconstrained)params[2] = C— baseline offset
Typical applications
Log-log scaling laws, stellar flux vs distance, turbulence spectra, fractal relationships, and any data that appears linear on a log-log plot.
Important: domain restriction
The model A * x^n is only defined for x > 0. Any data
point with x <= 0 will cause the fit to fail. If your data includes
non-positive x values, shift or truncate before fitting.
Initial guess strategy
The baseline C is estimated from the smallest-y points. The
offset-subtracted data is log-log linearised: fitting a line to
log(y − C) vs log(x) gives n as the slope and
log(A) as the intercept.
- Author:
- heddle
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intIndex of amplitude parameterA.static final intIndex of baseline-offset parameterC.static final intIndex of exponent parametern.static final String[]Display names used in legend strings and fit summaries.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
ConstructorsConstructorDescriptionCreates a fitter with the default Levenberg-Marquardt optimizer.PowerLawFitter(org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer optimizer) Creates a fitter with a custom optimizer. -
Method Summary
Modifier and TypeMethodDescriptionasEvaluator(FitResult fit) Returns anEvaluatorthat computesA * x^n + C.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).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) Return the display name of a fitted parameter.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_AIndex of amplitude parameterA.- See Also:
-
IDX_N
public static final int IDX_NIndex of exponent parametern.- See Also:
-
IDX_C
public static final int IDX_CIndex of baseline-offset parameterC.- See Also:
-
PARAM_NAMES
Display names used in legend strings and fit summaries.
-
-
Constructor Details
-
PowerLawFitter
public PowerLawFitter()Creates a fitter with the default Levenberg-Marquardt optimizer. -
PowerLawFitter
public PowerLawFitter(org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer optimizer) Creates a fitter with a custom optimizer.- Parameters:
optimizer- the least-squares optimizer to use (non-null)
-
-
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
-
asEvaluator
Returns anEvaluatorthat computesA * x^n + C.- Specified by:
asEvaluatorin classALeastSquaresFitter- Parameters:
fit- fit result from a previous call toALeastSquaresFitter.fit(double[], double[])- Returns:
- evaluator for the fitted function
- Throws:
NullPointerException- iffitisnullIllegalArgumentException- if the result has the wrong parameter count
-
modelName
- Returns:
- model name suitable for a legend or report
-
functionForm
- Returns:
- mathematical function form suitable for display
-
parameterName
Description copied from interface:IFitStringGetterReturn the display name of a fitted parameter.- Parameters:
index- zero-based parameter index- Returns:
- parameter name
-
getStringGetter
Description copied from class:ALeastSquaresFitterGet the descriptive string getter for this fitter.- Specified by:
getStringGetterin classALeastSquaresFitter- Returns:
- the string getter
-