Array and list factors
This page lists the built-in methods and operators for creating random variables of array and list type. The most common way of creating array variables is through the modelling API using random variable arrays and ranges
, and replicating factors across the range; many example of this can be found in the user guide. Sometimes arrays and lists can be defined directly as output of a factor, and it is those factors than are described here. Some of the factors involve variables of type ISparseList<T> where T is some domain (such as bool
); a sparse list is one where just a few of the elements have values that differ from the common value shared by all the other elements.
For both static methods and operators, you can often pass in random variables as arguments e.g. Variable<ISparseList<double>>
instead of ISparseList<double>
. 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.
A distribution factor creates a random variable from a parameterised distribution.
||Creates a random variable of type ISparseList<bool> with distribution parameterized by a sparse list of values representing probability of true.|
|Bernoulli integer subset
||Creates a random variable of type IList<int> listing membership of a set with distribution parameterized by sparse list of values representing probability of set membership.|
||Variable.GaussianListFromMeanAndPrecision(ISparseList<double> mean, ISparseList<double> precision)
||Creates a random variable of type ISparseList<double> with distribution parameterized by sparse lists of Gaussian means and precisions.|
||Variable.Multinomial(int trialCount, Vector probs)
||Creates an integer random variable array representing the counts of each index given a number of trials and the probability of each index.|
||Variable.MultinomialList(int trialCount, Vector probs)
||As with Multinomial except that the created random variable has type IList instead of array.|
||Variable.Subarray<T>(T array, int indices)
||Create a T random variable array by extracting elements of array at the specified indices, which cannot include duplicates. |
Subarray should be used instead of GetItems, whenever you can be sure that there are no duplicates, since it is more efficient.
||Variable.GetItems<T>(T array, int indices)
||Create a T random variable array by extracting elements of array at the specified indices, which may include duplicates. Some uses of GetItems can also be achieved through indexing. If there are no duplicate indices, Subarray should be used instead. |
||Create an array of double random variables corresponding to the elements of the supplied random vector. This is more efficient than calling GetItem on each element.|