gov.sandia.cognition.statistics.distribution
Class UnivariateGaussian

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.statistics.AbstractDistribution<NumberType>
          extended by gov.sandia.cognition.statistics.AbstractClosedFormUnivariateDistribution<Double>
              extended by gov.sandia.cognition.statistics.AbstractClosedFormSmoothUnivariateDistribution
                  extended by gov.sandia.cognition.statistics.distribution.UnivariateGaussian
All Implemented Interfaces:
Vectorizable, ClosedFormComputableDistribution<Double>, ClosedFormDistribution<Double>, ClosedFormUnivariateDistribution<Double>, ComputableDistribution<Double>, Distribution<Double>, DistributionWithMean<Double>, EstimableDistribution<Double,UnivariateGaussian>, SmoothUnivariateDistribution, UnivariateDistribution<Double>, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
UnivariateGaussian.CDF, UnivariateGaussian.CDF.Inverse, UnivariateGaussian.PDF

@PublicationReference(author="Wikipedia",
                      title="Normal distribution",
                      type=WebPage,
                      year=2009,
                      url="http://en.wikipedia.org/wiki/Normal_distribution")
public class UnivariateGaussian
extends AbstractClosedFormSmoothUnivariateDistribution
implements EstimableDistribution<Double,UnivariateGaussian>

This class contains internal classes that implement useful functions based on the Gaussian distribution. Use this class if the underlying distribution has a univariate (scalar) Random Variable. If your distribution is Vector based, then use MultivariateGaussian. However, MultivariateGaussian is a MUCH more computationally intensive class.

Since:
3.0
Author:
Kevin R. Dixon
See Also:
Serialized Form

Nested Class Summary
static class UnivariateGaussian.CDF
          CDF of the underlying Gaussian.
static class UnivariateGaussian.ErrorFunction
          Gaussian Error Function, useful for computing the cumulative distribution function for a Gaussian.
static class UnivariateGaussian.IncrementalEstimator
          Implements an incremental estimator for the sufficient statistics for a UnivariateGaussian.
static class UnivariateGaussian.MaximumLikelihoodEstimator
          Creates a UnivariateGaussian from data
static class UnivariateGaussian.PDF
          PDF of the underlying Gaussian.
static class UnivariateGaussian.SufficientStatistic
          Captures the sufficient statistics of a UnivariateGaussian, which are the values to estimate the mean and variance.
static class UnivariateGaussian.WeightedMaximumLikelihoodEstimator
          Creates a UnivariateGaussian from weighted data
 
Field Summary
static double BIG_Z
          A big value to input into the Gaussian CDF that will get 1.0 probability, 100.0.
static double DEFAULT_MEAN
          Default mean, 0.0.
static double DEFAULT_VARIANCE
          Default variance, 1.0.
protected  double mean
          First central moment (expectation) of the distribution
static double PI2
          PI times 2.0, 6.283185307179586
static double SQRT2
          Square root of 2.0, 0.707...
protected  double variance
          Second central moment (square of standard deviation) of the distribution
 
Constructor Summary
UnivariateGaussian()
          Creates a new instance of UnivariateGaussian with zero mean and unit variance
UnivariateGaussian(double mean, double variance)
          Creates a new instance of UnivariateGaussian
UnivariateGaussian(UnivariateGaussian other)
          Copy constructor
 
Method Summary
 UnivariateGaussian clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 void convertFromVector(Vector parameters)
          Converts the object from a Vector of parameters.
 Vector convertToVector()
          Converts the object to a vector.
 UnivariateGaussian convolve(UnivariateGaussian other)
          Convolves this Gaussian with the other Gaussian.
 UnivariateGaussian.CDF getCDF()
          Gets the CDF of a scalar distribution.
 UnivariateGaussian.MaximumLikelihoodEstimator getEstimator()
          Gets an estimator associated with this distribution.
 Double getMaxSupport()
          Gets the minimum support (domain or input) of the distribution.
 Double getMean()
          Getter for mean
 Double getMinSupport()
          Gets the minimum support (domain or input) of the distribution.
 UnivariateGaussian.PDF getProbabilityFunction()
          Gets the distribution function associated with this Distribution, either the PDF or PMF.
 double getVariance()
          Gets the variance of the distribution.
 ArrayList<Double> sample(Random random, int numSamples)
          Draws multiple random samples from the distribution.
 void setMean(double mean)
          Setter for mean
 void setVariance(double variance)
          Setter for variance
 UnivariateGaussian times(UnivariateGaussian other)
          Multiplies this Gaussian with the other Gaussian.
 String toString()
          Returns the string representation of the object.
 
Methods inherited from class gov.sandia.cognition.statistics.AbstractDistribution
sample
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.statistics.Distribution
sample
 

Field Detail

DEFAULT_MEAN

public static final double DEFAULT_MEAN
Default mean, 0.0.

See Also:
Constant Field Values

DEFAULT_VARIANCE

public static final double DEFAULT_VARIANCE
Default variance, 1.0.

See Also:
Constant Field Values

mean

protected double mean
First central moment (expectation) of the distribution


variance

protected double variance
Second central moment (square of standard deviation) of the distribution


BIG_Z

public static final double BIG_Z
A big value to input into the Gaussian CDF that will get 1.0 probability, 100.0.

See Also:
Constant Field Values

SQRT2

public static final double SQRT2
Square root of 2.0, 0.707...


PI2

public static final double PI2
PI times 2.0, 6.283185307179586

See Also:
Constant Field Values
Constructor Detail

UnivariateGaussian

public UnivariateGaussian()
Creates a new instance of UnivariateGaussian with zero mean and unit variance


UnivariateGaussian

public UnivariateGaussian(double mean,
                          double variance)
Creates a new instance of UnivariateGaussian

Parameters:
mean - First central moment (expectation) of the distribution
variance - Second central moment (square of standard deviation) of the distribution

UnivariateGaussian

public UnivariateGaussian(UnivariateGaussian other)
Copy constructor

Parameters:
other - UnivariateGaussian to copy
Method Detail

clone

public UnivariateGaussian clone()
Description copied from class: AbstractCloneableSerializable
This makes public the clone method on the Object class and removes the exception that it throws. Its default behavior is to automatically create a clone of the exact type of object that the clone is called on and to copy all primitives but to keep all references, which means it is a shallow copy. Extensions of this class may want to override this method (but call super.clone() to implement a "smart copy". That is, to target the most common use case for creating a copy of the object. Because of the default behavior being a shallow copy, extending classes only need to handle fields that need to have a deeper copy (or those that need to be reset). Some of the methods in ObjectUtil may be helpful in implementing a custom clone method. Note: The contract of this method is that you must use super.clone() as the basis for your implementation.

Specified by:
clone in interface Vectorizable
Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractClosedFormUnivariateDistribution<Double>
Returns:
A clone of this object.

getMean

public Double getMean()
Getter for mean

Specified by:
getMean in interface DistributionWithMean<Double>
Specified by:
getMean in interface SmoothUnivariateDistribution
Returns:
First central moment (expectation) of the distribution

setMean

public void setMean(double mean)
Setter for mean

Parameters:
mean - First central moment (expectation) of the distribution

getVariance

public double getVariance()
Description copied from interface: UnivariateDistribution
Gets the variance of the distribution. This is sometimes called the second central moment by more pedantic people, which is equivalent to the square of the standard deviation.

Specified by:
getVariance in interface UnivariateDistribution<Double>
Returns:
Variance of the distribution.

setVariance

public void setVariance(double variance)
Setter for variance

Parameters:
variance - Second central moment (square of standard deviation) of the distribution

toString

public String toString()
Returns the string representation of the object.

Overrides:
toString in class Object
Returns:
String representation of the object.

sample

public ArrayList<Double> sample(Random random,
                                int numSamples)
Description copied from interface: Distribution
Draws multiple random samples from the distribution. It is generally more efficient to use this multiple-sample method than multiple calls of the single-sample method. (But not always.)

Specified by:
sample in interface Distribution<Double>
Parameters:
random - Random-number generator to use in order to generate random numbers.
numSamples - Number of samples to draw from the distribution.
Returns:
Samples drawn according to this distribution.

convertToVector

public Vector convertToVector()
Description copied from interface: Vectorizable
Converts the object to a vector.

Specified by:
convertToVector in interface Vectorizable
Returns:
The Vector form of the object.

convertFromVector

public void convertFromVector(Vector parameters)
Description copied from interface: Vectorizable
Converts the object from a Vector of parameters.

Specified by:
convertFromVector in interface Vectorizable
Parameters:
parameters - The parameters to incorporate.

getCDF

public UnivariateGaussian.CDF getCDF()
Description copied from interface: UnivariateDistribution
Gets the CDF of a scalar distribution.

Specified by:
getCDF in interface ClosedFormUnivariateDistribution<Double>
Specified by:
getCDF in interface SmoothUnivariateDistribution
Specified by:
getCDF in interface UnivariateDistribution<Double>
Returns:
CDF of the scalar distribution.

getProbabilityFunction

public UnivariateGaussian.PDF getProbabilityFunction()
Description copied from interface: ComputableDistribution
Gets the distribution function associated with this Distribution, either the PDF or PMF.

Specified by:
getProbabilityFunction in interface ComputableDistribution<Double>
Specified by:
getProbabilityFunction in interface SmoothUnivariateDistribution
Returns:
Distribution function associated with this Distribution.

getMinSupport

public Double getMinSupport()
Description copied from interface: UnivariateDistribution
Gets the minimum support (domain or input) of the distribution.

Specified by:
getMinSupport in interface UnivariateDistribution<Double>
Returns:
Minimum support.

getMaxSupport

public Double getMaxSupport()
Description copied from interface: UnivariateDistribution
Gets the minimum support (domain or input) of the distribution.

Specified by:
getMaxSupport in interface UnivariateDistribution<Double>
Returns:
Minimum support.

times

public UnivariateGaussian times(UnivariateGaussian other)
Multiplies this Gaussian with the other Gaussian. This is also equivalent to computing the posterior belief using one of the Gaussians as the prior and one as the conditional likelihood.

Parameters:
other - Other Gaussian to multiply with this.
Returns:
Multiplied Gaussians.

convolve

public UnivariateGaussian convolve(UnivariateGaussian other)
Convolves this Gaussian with the other Gaussian.

Parameters:
other - Other Gaussian to convolve with this.
Returns:
Convolved Gaussians.

getEstimator

public UnivariateGaussian.MaximumLikelihoodEstimator getEstimator()
Description copied from interface: EstimableDistribution
Gets an estimator associated with this distribution.

Specified by:
getEstimator in interface EstimableDistribution<Double,UnivariateGaussian>
Returns:
A distribution estimator associated for this distribution.