Top Description Inners Constructors Methods
org.apache.commons.math3.fitting

public Class GaussianFitter

extends CurveFitter<Gaussian.Parametric>
Class Inheritance
Annotations
@Deprecated
Imports
java.util.Arrays, .Comparator, org.apache.commons.math3.analysis.function.Gaussian, org.apache.commons.math3.exception.NullArgumentException, .NumberIsTooSmallException, .OutOfRangeException, .ZeroException, .NotStrictlyPositiveException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.optim.nonlinear.vector.MultivariateVectorOptimizer, org.apache.commons.math3.util.FastMath

Deprecated

As of 3.3. Please use GaussianCurveFitter and WeightedObservedPoints instead.

Fits points to a Gaussian function.

Usage example:

  GaussianFitter fitter = new GaussianFitter(
    new LevenbergMarquardtOptimizer());
  fitter.addObservedPoint(4.0254623,  531026.0);
  fitter.addObservedPoint(4.03128248, 984167.0);
  fitter.addObservedPoint(4.03839603, 1887233.0);
  fitter.addObservedPoint(4.04421621, 2687152.0);
  fitter.addObservedPoint(4.05132976, 3461228.0);
  fitter.addObservedPoint(4.05326982, 3580526.0);
  fitter.addObservedPoint(4.05779662, 3439750.0);
  fitter.addObservedPoint(4.0636168,  2877648.0);
  fitter.addObservedPoint(4.06943698, 2175960.0);
  fitter.addObservedPoint(4.07525716, 1447024.0);
  fitter.addObservedPoint(4.08237071, 717104.0);
  fitter.addObservedPoint(4.08366408, 620014.0);
  double[] parameters = fitter.fit();
Since
2.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
GaussianFitter.ParameterGuesser

Guesses the parameters norm, mean, and sigma of a org.apache.commons.math3.analysis.function.Gaussian.Parametric based on the specified observed points.

Constructor Summary

AccessConstructor and Description
public
GaussianFitter(MultivariateVectorOptimizer
Optimizer to use for the fitting.
optimizer
)
Deprecated as a consequence of MultivariateVectorOptimizer being deprecated.

Constructs an instance using the specified optimizer.

Method Summary

Modifier and TypeMethod and Description
public double[]

Returns:

the parameters of the Gaussian function that best fits the observed points (in the same order as above).
fit
(double[]
First guess values in the following order:
  • Norm
  • Mean
  • Sigma
initialGuess
)

Fits a Gaussian function to the observed points.

public double[]

Returns:

the parameters of the Gaussian function that best fits the observed points (in the same order as above).
fit
()

Fits a Gaussian function to the observed points.

Inherited from org.apache.commons.math3.fitting.CurveFitter:
addObservedPointaddObservedPointaddObservedPointclearObservationsfitfitgetObservations

Constructor Detail

GaussianFitterback to summary
public GaussianFitter(MultivariateVectorOptimizer optimizer)

Deprecated

as a consequence of MultivariateVectorOptimizer being deprecated. See corresponding docs for further information.

Constructs an instance using the specified optimizer.

Parameters
optimizer:MultivariateVectorOptimizer

Optimizer to use for the fitting.

Method Detail

fitback to summary
public double[] fit(double[] initialGuess)

Fits a Gaussian function to the observed points.

Parameters
initialGuess:double[]

First guess values in the following order:

  • Norm
  • Mean
  • Sigma
Returns:double[]

the parameters of the Gaussian function that best fits the observed points (in the same order as above).

Since
3.0
fitback to summary
public double[] fit()

Fits a Gaussian function to the observed points.

Returns:double[]

the parameters of the Gaussian function that best fits the observed points (in the same order as above).

org.apache.commons.math3.fitting back to summary

public Class GaussianFitter.ParameterGuesser

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.commons.math3.fitting.GaussianFitter.ParameterGuesser

Guesses the parameters norm, mean, and sigma of a org.apache.commons.math3.analysis.function.Gaussian.Parametric based on the specified observed points.

Field Summary

Modifier and TypeField and Description
private final double
mean

Mean.

private final double
norm

Normalization factor.

private final double
sigma

Standard deviation.

Constructor Summary

AccessConstructor and Description
public
ParameterGuesser(WeightedObservedPoint[]
Observed points from which to guess the parameters of the Gaussian.
observations
)

Constructs instance with the specified observed points.

Method Summary

Modifier and TypeMethod and Description
private double[]

Returns:

the guessed parameters (normalization factor, mean and sigma).
basicGuess
(WeightedObservedPoint[]
Observed points, sorted.
points
)

Guesses the parameters based on the specified observed points.

private int

Returns:

the index in specified points array.
findMaxY
(WeightedObservedPoint[]
Points to search.
points
)

Finds index of point in specified points with the largest Y.

private WeightedObservedPoint[]

Returns:

the array containing two points suitable for determining X at the specified Y.
getInterpolationPointsForY
(WeightedObservedPoint[]
Points to use for interpolation.
points
,
int
Index within points from which to start search for interpolation bounds points.
startIdx
,
int
Index step for search for interpolation bounds points.
idxStep
,
double
Y value for which X should be determined.
y
)

Gets the two bounding interpolation points from the specified points suitable for determining X at the specified Y.

public double[]

Returns:

the guessed parameters, in the following order:
  • Normalization factor
  • Mean
  • Standard deviation
guess
()

Gets an estimation of the parameters.

private double

Returns:

the value of X for the specified Y.
interpolateXAtY
(WeightedObservedPoint[]
Points to use for interpolation.
points
,
int
Index within points from which to start the search for interpolation bounds points.
startIdx
,
int
Index step for searching interpolation bounds points.
idxStep
,
double
Y value for which X should be determined.
y
)

Interpolates using the specified points to determine X at the specified Y.

private boolean

Returns:

true if value is between boundary1 and boundary2 (inclusive), false otherwise.
isBetween
(double
Value to test whether it is between boundary1 and boundary2.
value
,
double
One end of the range.
boundary1
,
double
Other end of the range.
boundary2
)

Determines whether a value is between two other values.

private WeightedObservedPoint[]

Returns:

the input observations, sorted.
sortObservations
(WeightedObservedPoint[]
Input observations.
unsorted
)

Sort the observations.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

meanback to summary
private final double mean

Mean.

normback to summary
private final double norm

Normalization factor.

sigmaback to summary
private final double sigma

Standard deviation.

Constructor Detail

ParameterGuesserback to summary
public ParameterGuesser(WeightedObservedPoint[] observations)

Constructs instance with the specified observed points.

Parameters
observations:WeightedObservedPoint[]

Observed points from which to guess the parameters of the Gaussian.

Exceptions
NullArgumentException:
if observations is null.
NumberIsTooSmallException:
if there are less than 3 observations.

Method Detail

basicGuessback to summary
private double[] basicGuess(WeightedObservedPoint[] points)

Guesses the parameters based on the specified observed points.

Parameters
points:WeightedObservedPoint[]

Observed points, sorted.

Returns:double[]

the guessed parameters (normalization factor, mean and sigma).

findMaxYback to summary
private int findMaxY(WeightedObservedPoint[] points)

Finds index of point in specified points with the largest Y.

Parameters
points:WeightedObservedPoint[]

Points to search.

Returns:int

the index in specified points array.

getInterpolationPointsForYback to summary
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:WeightedObservedPoint[]

Points to use for interpolation.

startIdx:int

Index within points from which to start search for interpolation bounds points.

idxStep:int

Index step for search for interpolation bounds points.

y:double

Y value for which X should be determined.

Returns:WeightedObservedPoint[]

the array containing two points suitable for determining X at the specified Y.

Exceptions
OutOfRangeException:
if specified y is not within the range of the specified points.
ZeroException:
if idxStep is 0.
guessback to summary
public double[] guess()

Gets an estimation of the parameters.

Returns:double[]

the guessed parameters, in the following order:

  • Normalization factor
  • Mean
  • Standard deviation
interpolateXAtYback to summary
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:WeightedObservedPoint[]

Points to use for interpolation.

startIdx:int

Index within points from which to start the search for interpolation bounds points.

idxStep:int

Index step for searching interpolation bounds points.

y:double

Y value for which X should be determined.

Returns:double

the value of X for the specified Y.

Exceptions
OutOfRangeException:
if specified y is not within the range of the specified points.
ZeroException:
if idxStep is 0.
isBetweenback to summary
private boolean isBetween(double value, double boundary1, double boundary2)

Determines whether a value is between two other values.

Parameters
value:double

Value to test whether it is between boundary1 and boundary2.

boundary1:double

One end of the range.

boundary2:double

Other end of the range.

Returns:boolean

true if value is between boundary1 and boundary2 (inclusive), false otherwise.

sortObservationsback to summary
private WeightedObservedPoint[] sortObservations(WeightedObservedPoint[] unsorted)

Sort the observations.

Parameters
unsorted:WeightedObservedPoint[]

Input observations.

Returns:WeightedObservedPoint[]

the input observations, sorted.