org.apache.commons.math.optimization.fitting

## Class ParametricGaussianFunction

- java.lang.Object
- - org.apache.commons.math.optimization.fitting.ParametricGaussianFunction

- All Implemented Interfaces:
    Serializable, ParametricRealFunction

      public class ParametricGaussianFunction
      extends Object
      implements ParametricRealFunction, Serializable

  A Gaussian function. Specifically:

  `f(x) = a + b*exp(-((x - c)^2 / (2*d^2)))`

  The parameters have the following meaning:

  - `a` is a constant offset that shifts `f(x)` up or down
  - `b` is the height of the peak
  - `c` is the position of the center of the peak
  - `d` is related to the FWHM by `FWHM = 2*sqrt(2*ln(2))*d`
  Notation key:
  - `x^n`: `x` raised to the power of `n`
  - `exp(x)`: e`^x`
  - `sqrt(x)`: the square root of `x`
  - `ln(x)`: the natural logarithm of `x`
  References:
  - Wikipedia: Gaussian function
  Since:
    2.2
  Version:
    $Revision: 1037327 $ $Date: 2010-11-20 21:57:37 +0100 (sam. 20 nov. 2010) $
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private static long` | `serialVersionUID` Serializable version Id.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ParametricGaussianFunction()` Constructs an instance.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `double[]` | `gradient(double x, double[] parameters)` Computes the gradient vector for a four variable version of the function where the parameters, `a`, `b`, `c`, and `d`, are considered the variables, not `x`.
    `private void` | `validateParameters(double[] parameters)` Validates parameters to ensure they are appropriate for the evaluation of the `value` and `gradient` methods.
    `double` | `value(double x, double[] parameters)` Computes value of function `f(x)` for the specified `x` and parameters `a`, `b`, `c`, and `d`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### serialVersionUID

          private static final long serialVersionUID

      Serializable version Id.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### ParametricGaussianFunction

          public ParametricGaussianFunction()

      Constructs an instance.

  - ### Method Detail

    - #### value

          public double value(double x,
                     double[] parameters)
                       throws ZeroException

      Computes value of function `f(x)` for the specified `x` and parameters `a`, `b`, `c`, and `d`.
      Specified by:
        `value` in interface `ParametricRealFunction`
      Parameters:
        `x` - `x` value
        `parameters` - values of `a`, `b`, `c`, and `d`
      Returns:
        value of `f(x)` evaluated at `x` with the specified parameters
      Throws:
        `IllegalArgumentException` - if `parameters` is invalid as determined by `validateParameters(double[])`
        `ZeroException` - if `parameters` values are invalid as determined by `validateParameters(double[])`

    - #### gradient

          public double[] gradient(double x,
                          double[] parameters)
                            throws ZeroException

      Computes the gradient vector for a four variable version of the function where the parameters, `a`, `b`, `c`, and `d`, are considered the variables, not `x`. That is, instead of computing the gradient vector for the function `f(x)` (which would just be the derivative of `f(x)` with respect to `x` since it's a one-dimensional function), computes the gradient vector for the function `f(a, b, c, d) = a + b*exp(-((x - c)^2 / (2*d^2)))` treating the specified `x` as a constant.

      The components of the computed gradient vector are the partial derivatives of `f(a, b, c, d)` with respect to each variable. That is, the partial derivative of `f(a, b, c, d)` with respect to `a`, the partial derivative of `f(a, b, c, d)` with respect to `b`, the partial derivative of `f(a, b, c, d)` with respect to `c`, and the partial derivative of `f(a, b, c, d)` with respect to `d`.

      Specified by:
        `gradient` in interface `ParametricRealFunction`
      Parameters:
        `x` - `x` value to be used as constant in `f(a, b, c, d)`
        `parameters` - values of `a`, `b`, `c`, and `d` for computation of gradient vector of `f(a, b, c, d)`
      Returns:
        gradient vector of `f(a, b, c, d)`
      Throws:
        `IllegalArgumentException` - if `parameters` is invalid as determined by `validateParameters(double[])`
        `ZeroException` - if `parameters` values are invalid as determined by `validateParameters(double[])`

    - #### validateParameters

          private void validateParameters(double[] parameters)
                                   throws ZeroException

      Validates parameters to ensure they are appropriate for the evaluation of the `value` and `gradient` methods.
      Parameters:
        `parameters` - values of `a`, `b`, `c`, and `d`
      Throws:
        `IllegalArgumentException` - if `parameters` is `null` or if `parameters` does not have length == 4
        `ZeroException` - if `parameters[3]` (`d`) is 0

Copyright (c) 2003-2013 Apache Software Foundation