Package org.apache.commons.math3.fitting
Class GaussianCurveFitter.ParameterGuesser
- java.lang.Object
-
- org.apache.commons.math3.fitting.GaussianCurveFitter.ParameterGuesser
-
- Enclosing class:
- GaussianCurveFitter
public static class GaussianCurveFitter.ParameterGuesser extends java.lang.Object
Guesses the parametersnorm
,mean
, andsigma
of aGaussian.Parametric
based on the specified observed points.
-
-
Constructor Summary
Constructors Constructor Description ParameterGuesser(java.util.Collection<WeightedObservedPoint> observations)
Constructs instance with the specified observed points.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private double[]
basicGuess(WeightedObservedPoint[] points)
Guesses the parameters based on the specified observed points.private int
findMaxY(WeightedObservedPoint[] points)
Finds index of point in specified points with the largest Y.private WeightedObservedPoint[]
getInterpolationPointsForY(WeightedObservedPoint[] points, int startIdx, int idxStep, double y)
Gets the two bounding interpolation points from the specified points suitable for determining X at the specified Y.double[]
guess()
Gets an estimation of the parameters.private double
interpolateXAtY(WeightedObservedPoint[] points, int startIdx, int idxStep, double y)
Interpolates using the specified points to determine X at the specified Y.private boolean
isBetween(double value, double boundary1, double boundary2)
Determines whether a value is between two other values.private java.util.List<WeightedObservedPoint>
sortObservations(java.util.Collection<WeightedObservedPoint> unsorted)
Sort the observations.
-
-
-
Constructor Detail
-
ParameterGuesser
public ParameterGuesser(java.util.Collection<WeightedObservedPoint> observations)
Constructs instance with the specified observed points.- Parameters:
observations
- Observed points from which to guess the parameters of the Gaussian.- Throws:
NullArgumentException
- ifobservations
isnull
.NumberIsTooSmallException
- if there are less than 3 observations.
-
-
Method Detail
-
guess
public double[] guess()
Gets an estimation of the parameters.- Returns:
- the guessed parameters, in the following order:
- Normalization factor
- Mean
- Standard deviation
-
sortObservations
private java.util.List<WeightedObservedPoint> sortObservations(java.util.Collection<WeightedObservedPoint> unsorted)
Sort the observations.- Parameters:
unsorted
- Input observations.- Returns:
- the input observations, sorted.
-
basicGuess
private double[] basicGuess(WeightedObservedPoint[] points)
Guesses the parameters based on the specified observed points.- Parameters:
points
- Observed points, sorted.- Returns:
- the guessed parameters (normalization factor, mean and sigma).
-
findMaxY
private int findMaxY(WeightedObservedPoint[] points)
Finds index of point in specified points with the largest Y.- Parameters:
points
- Points to search.- Returns:
- the index in specified points array.
-
interpolateXAtY
private double interpolateXAtY(WeightedObservedPoint[] points, int startIdx, int idxStep, double y) throws OutOfRangeException
Interpolates using the specified points to determine X at the specified Y.- Parameters:
points
- Points to use for interpolation.startIdx
- Index within points from which to start the search for interpolation bounds points.idxStep
- Index step for searching interpolation bounds points.y
- Y value for which X should be determined.- Returns:
- the value of X for the specified Y.
- Throws:
ZeroException
- ifidxStep
is 0.OutOfRangeException
- if specifiedy
is not within the range of the specifiedpoints
.
-
getInterpolationPointsForY
private WeightedObservedPoint[] getInterpolationPointsForY(WeightedObservedPoint[] points, int startIdx, int idxStep, double y) throws OutOfRangeException
Gets the two bounding interpolation points from the specified points suitable for determining X at the specified Y.- Parameters:
points
- Points to use for interpolation.startIdx
- Index within points from which to start search for interpolation bounds points.idxStep
- Index step for search for interpolation bounds points.y
- Y value for which X should be determined.- Returns:
- the array containing two points suitable for determining X at the specified Y.
- Throws:
ZeroException
- ifidxStep
is 0.OutOfRangeException
- if specifiedy
is not within the range of the specifiedpoints
.
-
isBetween
private boolean isBetween(double value, double boundary1, double boundary2)
Determines whether a value is between two other values.- Parameters:
value
- Value to test whether it is betweenboundary1
andboundary2
.boundary1
- One end of the range.boundary2
- Other end of the range.- Returns:
true
ifvalue
is betweenboundary1
andboundary2
(inclusive),false
otherwise.
-
-