peakml.math.function
Class LogNormalFunction

java.lang.Object
  extended by jaolho.data.lma.LMAFunction
      extended by peakml.math.function.LogNormalFunction
All Implemented Interfaces:
Function

public class LogNormalFunction
extends jaolho.data.lma.LMAFunction
implements Function

Implementation of a log-normal function, which can be used to get a fit to log-normally distributed data. The log-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
LogNormalFunction(double[] parameters)
          Constructs a new log-normal function with the given parameters.
LogNormalFunction(double scale, double mean, double variance)
          Constructs a new log-normal function with the given parameters.
 
Method Summary
static LogNormalFunction fit(double[] xvals, double[] yvals)
          Fits (i.e.
 jaolho.data.lma.LMA getLMA()
          Returns the LMA-fit used for constructing this function.
 double getMean()
           
 double getMedian()
           
 double getMode()
          This function retrieves the mode of this function.
 double[] getParameters()
           
 double getPartialDerivate(double x, double[] a, int parameterIndex)
           
 double getQuality()
          Returns the quality of the fit when an LMA-fit was done.
 double getSkewness()
           
 double getStandardDeviation()
           
 double getStartX()
          Returns the starting position of the log-normal distribution.
 double getVariation()
           
 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 log-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

LogNormalFunction

public LogNormalFunction(double[] parameters)
Constructs a new log-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.

LogNormalFunction

public LogNormalFunction(double scale,
                         double mean,
                         double variance)
Constructs a new log-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.NullPointerException
Returns the y-value for the given x-value with the parameters stored in the instance of the class.

Specified by:
getY in interface Function
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.

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.

getQuality

public double getQuality()
                  throws java.lang.NullPointerException
Returns the quality of the fit when an LMA-fit was done. If no LMA-fit was done for this function a NullPointerException is throws. The quality is expressed in a Chi-square coeficient. Closer to zero is a better fit.

Returns:
The quality of the fitted function to the data as a chi-square.
Throws:
java.lang.NullPointerException

getParameters

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

getMean

public double getMean()
               throws java.lang.NullPointerException
Throws:
java.lang.NullPointerException

getMedian

public double getMedian()
                 throws java.lang.NullPointerException
Throws:
java.lang.NullPointerException

getStandardDeviation

public double getStandardDeviation()
                            throws java.lang.NullPointerException
Throws:
java.lang.NullPointerException

getMode

public double getMode()
               throws java.lang.NullPointerException
This function retrieves the mode of this function. The mode is defined as the x-value where the distribution reaches its peak and is calculated with the formula: e^[m - s^2].

Returns:
The mode of the log-normal as an x-coordinate.
Throws:
java.lang.NullPointerException - Thrown when no parameters are stored in the instance.

getSkewness

public double getSkewness()
                   throws java.lang.NullPointerException
Throws:
java.lang.NullPointerException

getVariation

public double getVariation()
                    throws java.lang.NullPointerException
Throws:
java.lang.NullPointerException

getStartX

public double getStartX()
Returns the starting position of the log-normal distribution. This starting position is determined by mode - e^(m-s).

Returns:
The x-coordinate where the log-normal curve starts.

MLE

public static double[] MLE(double[] xvals)
Implementation of the maximum likelihood estimation for log-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, transforms these to log-space 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 LogNormalFunction fit(double[] xvals,
                                    double[] yvals)
                             throws java.lang.RuntimeException
Fits (i.e. estimates) the best parameters for the log-normal curve to the given data. The parameters are estimated and returned in the new LogNormalFunction 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.