Distributions Factors

This page lists the built-in methods for creating random variables with various distribution factors.  In many cases, you can pass in random variables as arguments e.g. Variable<int> instead of int. For compactness, this is not shown in the syntax below.
 
These methods provide a convenient short alternative to using Variable<T>.Factor and passing in the factor method, as described on this page.  Note also that you can create a random variable with any prior distribution using Variable.Random(IDistribution<T> dist).  This is useful if you already have a distribution object, such as the posterior from a previous inference, and wish to create a new random variable with that distribution as its prior.

Discrete Distributions

Distributions where the random variable can take one of a discrete set of states. Where the discrete set of states is indexed by a Range, it should replace a size argument or be passed as an additional parameter.

Distribution
Syntax
Description
Bernoulli
Variable.Bernoulli(double probTrue)
 
Creates a boolean random variable from the probability of being true P(true).
Variable.BernoulliFromLogOdds(double logOdds)
Creates a boolean random variable from the log odds i.e. log P(true)/P(false).  Equivalent to Variable.Bernoulli(Variable.Logistic(logOdds)).
Discrete
Variable.Discrete(double[] probs)
Variable.Discrete(Vector probs)
Creates an int random variable from supplied array or vector of probabilities (which must add up to 1). The variable can take values between 0 and N-1 where N is the length of the array/vector.
Variable.DiscreteFromLogProbs(double[] logProbs)
Creates an int random variable from supplied array or vector of log probabilities.  Equivalent to Variable.Discrete(Variable.Softmax(logProbs)).
Variable.DiscreteUniform(int size)
Creates an int random variable which can take values from 0 to size-1 with equal probability.
Discrete enum
 
Variable.EnumDiscrete<TEnum>(double[] probs)
Variable.EnumDiscrete<TEnum>(Vector probs)
Creates an enum random variable where the probability of each enum value is given by the specified array or vector.  TEnum specifies the enum type.
Variable.EnumUniform<TEnum>()
Creates an enum random variable with equal probability of taking each possible value of the enumeration.  TEnum specifies the enum type.

Binomial

Variable.Binomial(double probSuccess, int trialCount)
Creates an int random variable which has a Binomial distribution with the specified probability of success per trial and number of trials.
Multinomial
Variable.Multinomial(Vector probs, int trialCount)
Creates an int[] random variable array which has a Multinomial distribution with the specified array of probabilities and number of trials.
Poisson
Variable.Poisson(double mean)
Creates an int random variable which has a Poisson distribution with the specified mean.
 

Continuous Distributions

Distributions where the random variable is can take one of a continuous range of values.

Distribution
Syntax
Description
Beta
Variable.Beta(double trueCount, double falseCount)
Creates a double random variable with a Beta distribution with the specified counts.
Variable.BetaFromMeanAndVariance(double mean, double variance)
Creates a double random variable with a Beta distribution of the specified mean and variance.
Gaussian
Variable.GaussianFromMeanAndPrecision(double mean, double precision)
Creates a double random variable with a Gaussian distribution of the specified mean and precision (inverse variance).
Variable.GaussianFromMeanAndVariance(double mean, double variance)
Creates a double random variable with a Gaussian distribution of the specified mean and variance.
Gamma
Variable.GammaFromShapeAndScale(double shape, double scale)
Creates a positive double random variable with a Gamma distribution of the specified shape and scale.
Variable.GammaFromShapeAndRate(double shape, double rate)
Creates a positive double random variable with a Gamma distribution of the specified shape and rate. We now support both stochastic shape and rate, but the support for stochastic shape is experimental.
Variable.GammaFromMeanAndVariance(double mean, double variance)
Creates a positive double random variable with a Gamma distribution of the specified mean and variance.
 

Multivariate Distributions

Distributions where the random variable is multivariate.

Distribution
Syntax
Description
Dirichlet
Variable.Dirichlet(double[] u)
Variable.Dirichlet(Vector v)
Creates a Vector random variable with a Dirichlet distribution with the specified array or vector of pseudo-counts.
Variable.DirichletUniform(int dimension)
Creates a Vector random variable with a Dirichlet distribution whose pseudo-counts are all set to 1.
Wishart
Variable.WishartFromShapeAndScale(double shape, PositiveDefiniteMatrix scale)
Creates a PositiveDefiniteMatrix random variable with a Wishart distribution with the specified shape parameter and scale matrix.
 
©2009-2013 Microsoft Corporation. All rights reserved.  Terms of Use | Trademarks | Privacy Statement