peakml.math.function
Class NormalFunction

java.lang.Object
  extended by jaolho.data.lma.LMAFunction
      extended by peakml.math.function.NormalFunction

public class NormalFunction
extends jaolho.data.lma.LMAFunction

Implementation of a normal function, which can be used to get a fit to normally distributed data. The normal has three degrees of freedom controlling the fit to the given data: scale, mean and variance.


Field Summary
static int PARAM_MEAN
          The index of the mean-parameter in the array returned by getParameters()
static int PARAM_SCALE
          The index of the scale-parameter in the array returned by getParameters()
static int PARAM_VARIANCE
          The index of the variance-parameter in the array returned by getParameters()
 
Constructor Summary
NormalFunction(double[] parameters)
          Constructs a new normal function with the given parameters.
NormalFunction(double scale, double mean, double variance)
          Constructs a new normal function with the given parameters.
 
Method Summary
static NormalFunction fit(double[] xvals, double[] yvals)
          Fits (i.e.
 jaolho.data.lma.LMA getLMA()
          Returns the LMA-fit used for constructing this function.
 double[] getParameters()
           
 double getPartialDerivate(double x, double[] a, int parameterIndex)
           
 double getY(double x)
          Returns the y-value for the given x-value with the parameters stored in the instance of the class.
 double getY(double x, double[] a)
           
static double[] MLE(double[] xvals)
          Implementation of the maximum likelihood estimation for normal distributions, which can be used as an initial best guess for the parameters for the LMA fit algorithm.
 
Methods inherited from class jaolho.data.lma.LMAFunction
constructWeights, generateData, generateData, generateData
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARAM_SCALE

public static final int PARAM_SCALE
The index of the scale-parameter in the array returned by getParameters()

See Also:
Constant Field Values

PARAM_MEAN

public static final int PARAM_MEAN
The index of the mean-parameter in the array returned by getParameters()

See Also:
Constant Field Values

PARAM_VARIANCE

public static final int PARAM_VARIANCE
The index of the variance-parameter in the array returned by getParameters()

See Also:
Constant Field Values
Constructor Detail

NormalFunction

public NormalFunction(double[] parameters)
Constructs a new normal function with the given parameters. The parameters should be passed as an array of 3 elements, where: element 0 is the scale parameter, element 1 is the variance parameter and the element 2 is the mean parameter.

Parameters:
parameters - The array with all the parameters.

NormalFunction

public NormalFunction(double scale,
                      double mean,
                      double variance)
Constructs a new normal function with the given parameters.

Parameters:
scale - The scale-parameter.
mean - The mean parameter.
variance - The variance parameter.
Method Detail

getY

public double getY(double x)
            throws java.lang.RuntimeException,
                   java.lang.NullPointerException
Returns the y-value for the given x-value with the parameters stored in the instance of the class.

Parameters:
x - The x-value.
Returns:
The y-value for the given x-value.
Throws:
java.lang.NullPointerException - When no parameters are stored in the class.
java.lang.RuntimeException

getY

public double getY(double x,
                   double[] a)
Specified by:
getY in class jaolho.data.lma.LMAFunction

getPartialDerivate

public double getPartialDerivate(double x,
                                 double[] a,
                                 int parameterIndex)
Specified by:
getPartialDerivate in class jaolho.data.lma.LMAFunction

getLMA

public jaolho.data.lma.LMA getLMA()
Returns the LMA-fit used for constructing this function. If no LMA-fit was used for constructing this function null is returned.

Returns:
The LMA object used to make the fit.

getParameters

public double[] getParameters()
                       throws java.lang.NullPointerException
Throws:
java.lang.NullPointerException

MLE

public static double[] MLE(double[] xvals)
Implementation of the maximum likelihood estimation for normal distributions, which can be used as an initial best guess for the parameters for the LMA fit algorithm. It takes an array containing the x-values to be used for the fit and calculates the mean and standard-deviation for these values. The resulting vector can be plugged into the LMA-algorithm.

Parameters:
xvals - The x-values to estimate the parameters to.
Returns:
The estimated parameters.

fit

public static NormalFunction fit(double[] xvals,
                                 double[] yvals)
                          throws java.lang.RuntimeException
Fits (i.e. estimates) the best parameters for the normal curve to the given data. The parameters are estimated and returned in the new NormalFunction object.

Parameters:
xvals - The x-values to fit the line to.
yvals - The y-values to fit the line to.
Returns:
A LinearFunction instance fitted to the data.
Throws:
java.lang.RuntimeException - Thrown when an error is encountered in the fitting procedure.