gov.sandia.cognition.statistics.distribution

## Class ScalarMixtureDensityModel

• All Implemented Interfaces:
Vectorizable, ClosedFormComputableDistribution<java.lang.Double>, ClosedFormDistribution<java.lang.Double>, ClosedFormUnivariateDistribution<java.lang.Double>, ComputableDistribution<java.lang.Double>, Distribution<java.lang.Double>, DistributionWithMean<java.lang.Double>, SmoothUnivariateDistribution, UnivariateDistribution<java.lang.Double>, CloneableSerializable, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
ScalarMixtureDensityModel.CDF, ScalarMixtureDensityModel.PDF

```@CodeReview(reviewer="Kevin R. Dixon",
date="2009-10-20",
changesNeeded=true,
comments={"Fixed some missing javadoc.","General style fixes.","Added task to figure out a way to avoid storing weights in matrix.","Generally looks good.","Some argument checks need to be more complete"},
@PublicationReference(author="Wikipedia",
title="Mixture Model",
type=WebPage,
year=2009,
url="http://en.wikipedia.org/wiki/Mixture_density")
public class ScalarMixtureDensityModel
extends LinearMixtureModel<java.lang.Double,SmoothUnivariateDistribution>
implements SmoothUnivariateDistribution```
ScalarMixtureDensityModel (SMDM) implements just that: a scalar mixture density model. There are n distributions which can each be different. There is an n-dimensional vector of prior probabilities which are the probability of selecting each particular distribution. So these prior probabilities must sum to 1.0. To sample from a SMDM is to first select which distribution using the prior probabilities, and then to sample from that distribution to return a sample.

Each distribution must have a mean and variance defined. A mean and variance for the SMDM can be computed. Given an input value, a weighted Z value can be computed for the SMDM distribution.
Author:
jdmorr
Serialized Form
• ### Nested Class Summary

Nested Classes
Modifier and Type Class and Description
`static class ` `ScalarMixtureDensityModel.CDF`
CDFof the SMDM
`static class ` `ScalarMixtureDensityModel.EMLearner`
An EM learner that estimates a mixture model from data
`static class ` `ScalarMixtureDensityModel.PDF`
PDF of the SMDM

• ### Fields inherited from class gov.sandia.cognition.statistics.distribution.LinearMixtureModel

`distributions, priorWeights`
• ### Constructor Summary

Constructors
Constructor and Description
`ScalarMixtureDensityModel()`
Creates a new instance of ScalarMixtureDensityModel
`ScalarMixtureDensityModel(java.util.Collection<? extends SmoothUnivariateDistribution> distributions)`
Creates a new instance of ScalarMixtureDensityModel
```ScalarMixtureDensityModel(java.util.Collection<? extends SmoothUnivariateDistribution> distributions, double[] priorWeights)```
Creates a new instance of ScalarMixtureDensityModel
`ScalarMixtureDensityModel(ScalarMixtureDensityModel other)`
Copy constructor
`ScalarMixtureDensityModel(SmoothUnivariateDistribution... distributions)`
Creates a new instance of ScalarMixtureDensityModel
• ### Method Summary

All Methods
Modifier and Type Method and Description
`ScalarMixtureDensityModel` `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.
`ScalarMixtureDensityModel.CDF` `getCDF()`
Gets the CDF of a scalar distribution.
`java.lang.Double` `getMaxSupport()`
Gets the minimum support (domain or input) of the distribution.
`java.lang.Double` `getMean()`
Gets the arithmetic mean, or "first central moment" or "expectation", of the distribution.
`double` `getMeanAsDouble()`
Gets the mean of the distribution as a double.
`java.lang.Double` `getMinSupport()`
Gets the minimum support (domain or input) of the distribution.
`ScalarMixtureDensityModel.PDF` `getProbabilityFunction()`
Gets the distribution function associated with this Distribution, either the PDF or PMF.
`double` `getVariance()`
Gets the variance of the distribution.
`double` `sampleAsDouble(java.util.Random random)`
Samples a value from this distribution as a double.
`double[]` ```sampleAsDoubles(java.util.Random random, int count)```
Samples values from this distribution as an array of doubles.
`void` ```sampleInto(java.util.Random random, double[] output, int start, int length)```
Samples values from this distribution as an array of doubles.
• ### Methods inherited from class gov.sandia.cognition.statistics.distribution.LinearMixtureModel

`getDistributionCount, getDistributions, getPriorWeights, getPriorWeightSum, sample, sampleInto, setDistributions, setPriorWeights, toString`
• ### 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, sample, sampleInto`
• ### Constructor Detail

• #### ScalarMixtureDensityModel

`public ScalarMixtureDensityModel()`
Creates a new instance of ScalarMixtureDensityModel
• #### ScalarMixtureDensityModel

`public ScalarMixtureDensityModel(SmoothUnivariateDistribution... distributions)`
Creates a new instance of ScalarMixtureDensityModel
Parameters:
`distributions` - Distributions that comprise the SMDM with equal prior weight
• #### ScalarMixtureDensityModel

`public ScalarMixtureDensityModel(java.util.Collection<? extends SmoothUnivariateDistribution> distributions)`
Creates a new instance of ScalarMixtureDensityModel
Parameters:
`distributions` - Distributions that comprise the SMDM with equal prior weight
• #### ScalarMixtureDensityModel

```public ScalarMixtureDensityModel(java.util.Collection<? extends SmoothUnivariateDistribution> distributions,
double[] priorWeights)```
Creates a new instance of ScalarMixtureDensityModel
Parameters:
`distributions` - Distributions that comprise the SMDM
`priorWeights` - Weights proportionate by which the distributions are sampled
• #### ScalarMixtureDensityModel

`public ScalarMixtureDensityModel(ScalarMixtureDensityModel other)`
Copy constructor
Parameters:
`other` - SMDM to copy
• ### Method Detail

• #### clone

`public ScalarMixtureDensityModel 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 `LinearMixtureModel<java.lang.Double,SmoothUnivariateDistribution>`
Returns:
A clone of this object.
• #### 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.
• #### getMinSupport

`public java.lang.Double getMinSupport()`
Description copied from interface: `UnivariateDistribution`
Gets the minimum support (domain or input) of the distribution.
Specified by:
`getMinSupport` in interface `UnivariateDistribution<java.lang.Double>`
Returns:
Minimum support.
• #### getMaxSupport

`public java.lang.Double getMaxSupport()`
Description copied from interface: `UnivariateDistribution`
Gets the minimum support (domain or input) of the distribution.
Specified by:
`getMaxSupport` in interface `UnivariateDistribution<java.lang.Double>`
Returns:
Minimum support.
• #### getMean

`public java.lang.Double getMean()`
Description copied from interface: `DistributionWithMean`
Gets the arithmetic mean, or "first central moment" or "expectation", of the distribution.
Specified by:
`getMean` in interface `DistributionWithMean<java.lang.Double>`
Specified by:
`getMean` in interface `SmoothUnivariateDistribution`
Returns:
Mean of the distribution.
• #### getMeanAsDouble

`public double getMeanAsDouble()`
Description copied from interface: `UnivariateDistribution`
Gets the mean of the distribution as a double.
Specified by:
`getMeanAsDouble` in interface `UnivariateDistribution<java.lang.Double>`
Returns:
The mean as a double.
• #### getVariance

```@PublicationReference(author="Wikipedia",
title="Mixture Model",
type=WebPage,
year=2009,
url="http://en.wikipedia.org/wiki/Mixture_density")
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<java.lang.Double>`
Returns:
Variance of the distribution.
• #### sampleAsDouble

`public double sampleAsDouble(java.util.Random random)`
Description copied from interface: `SmoothUnivariateDistribution`
Samples a value from this distribution as a double. This is a convenience method to potentially avoid boxing.
Specified by:
`sampleAsDouble` in interface `SmoothUnivariateDistribution`
Parameters:
`random` - Random number generator to use.
Returns:
A value sampled from this distribution.
• #### sampleAsDoubles

```public double[] sampleAsDoubles(java.util.Random random,
int count)```
Description copied from interface: `SmoothUnivariateDistribution`
Samples values from this distribution as an array of doubles. This is a convenience method to potentially avoid boxing.
Specified by:
`sampleAsDoubles` in interface `SmoothUnivariateDistribution`
Parameters:
`random` - Random number generator to use.
`count` - The number of values to sample. Cannot be negative
Returns:
An array of values sampled from this distribution. Size is that of count.
• #### sampleInto

```public void sampleInto(java.util.Random random,
double[] output,
int start,
int length)```
Description copied from interface: `SmoothUnivariateDistribution`
Samples values from this distribution as an array of doubles. This is a convenience method to potentially avoid boxing.
Specified by:
`sampleInto` in interface `SmoothUnivariateDistribution`
Parameters:
`random` - Random number generator to use.
`output` - The array to write the result into. Cannot be null.
`start` - The offset in the array to start writing at. Cannot be negative.
`length` - The number of values to sample. Cannot be negative.
• #### getProbabilityFunction

`public ScalarMixtureDensityModel.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<java.lang.Double>`
Specified by:
`getProbabilityFunction` in interface `SmoothUnivariateDistribution`
Returns:
Distribution function associated with this Distribution.
• #### getCDF

`public ScalarMixtureDensityModel.CDF getCDF()`
Description copied from interface: `UnivariateDistribution`
Gets the CDF of a scalar distribution.
Specified by:
`getCDF` in interface `ClosedFormUnivariateDistribution<java.lang.Double>`
Specified by:
`getCDF` in interface `SmoothUnivariateDistribution`
Specified by:
`getCDF` in interface `UnivariateDistribution<java.lang.Double>`
Returns:
CDF of the scalar distribution.