Package org.apache.commons.math3.fitting
Class GaussianCurveFitter
java.lang.Object
org.apache.commons.math3.fitting.AbstractCurveFitter
org.apache.commons.math3.fitting.GaussianCurveFitter
Fits points to a
The
Gaussian
function.
The
initial guess values
must be passed
in the following order:
- Normalization
- Mean
- Sigma
Usage example:
WeightedObservedPoints obs = new WeightedObservedPoints(); obs.add(4.0254623, 531026.0); obs.add(4.03128248, 984167.0); obs.add(4.03839603, 1887233.0); obs.add(4.04421621, 2687152.0); obs.add(4.05132976, 3461228.0); obs.add(4.05326982, 3580526.0); obs.add(4.05779662, 3439750.0); obs.add(4.0636168, 2877648.0); obs.add(4.06943698, 2175960.0); obs.add(4.07525716, 1447024.0); obs.add(4.08237071, 717104.0); obs.add(4.08366408, 620014.0); double[] parameters = GaussianCurveFitter.create().fit(obs.toList());
- Since:
- 3.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Guesses the parametersnorm
,mean
, andsigma
of aGaussian.Parametric
based on the specified observed points.Nested classes/interfaces inherited from class org.apache.commons.math3.fitting.AbstractCurveFitter
AbstractCurveFitter.TheoreticalValuesFunction
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Gaussian.Parametric
Parametric function to be fitted.private final double[]
Initial guess.private final int
Maximum number of iterations of the optimization algorithm. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
GaussianCurveFitter
(double[] initialGuess, int maxIter) Contructor used by the factory methods. -
Method Summary
Modifier and TypeMethodDescriptionstatic GaussianCurveFitter
create()
Creates a default curve fitter.protected LeastSquaresProblem
getProblem
(Collection<WeightedObservedPoint> observations) Creates a least squares problem corresponding to the appropriate curve.withMaxIterations
(int newMaxIter) Configure the maximum number of iterations.withStartPoint
(double[] newStart) Configure the start point (initial guess).Methods inherited from class org.apache.commons.math3.fitting.AbstractCurveFitter
fit, getOptimizer
-
Field Details
-
FUNCTION
Parametric function to be fitted. -
initialGuess
private final double[] initialGuessInitial guess. -
maxIter
private final int maxIterMaximum number of iterations of the optimization algorithm.
-
-
Constructor Details
-
GaussianCurveFitter
private GaussianCurveFitter(double[] initialGuess, int maxIter) Contructor used by the factory methods.- Parameters:
initialGuess
- Initial guess. If set tonull
, the initial guess will be estimated using theGaussianCurveFitter.ParameterGuesser
.maxIter
- Maximum number of iterations of the optimization algorithm.
-
-
Method Details
-
create
Creates a default curve fitter. The initial guess for the parameters will beGaussianCurveFitter.ParameterGuesser
computed automatically, and the maximum number of iterations of the optimization algorithm is set toInteger.MAX_VALUE
.- Returns:
- a curve fitter.
- See Also:
-
withStartPoint
Configure the start point (initial guess).- Parameters:
newStart
- new start point (initial guess)- Returns:
- a new instance.
-
withMaxIterations
Configure the maximum number of iterations.- Parameters:
newMaxIter
- maximum number of iterations- Returns:
- a new instance.
-
getProblem
Creates a least squares problem corresponding to the appropriate curve.- Specified by:
getProblem
in classAbstractCurveFitter
- Parameters:
observations
- Sample points.- Returns:
- the least squares problem to use for fitting the curve to the
given
points
.
-