Skip to main content

Infer.NET user guide : Factors and Constraints

Miscellaneous Factors

This page lists the remaining built-in methods, which have not already been covered. In these methods, you can often pass in random variables as arguments e.g. Variable<Vector> instead of Vector. 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.

Operation Syntax Description
Subarray 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.
GetItems 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.
Enum to int Variable.EnumToInt<TEnum>(TEnum enumVar) Create an int random variable corresponding to the supplied enum random variable. This allows enums to be used as arguments to Variable.Case() or Variable.Switch().
Vector from array Variable.Vector(double[] array) Create a vector random variable corresponding the supplied array of random doubles.
Array from vector Variable.ArrayFromVector(Vector vector) 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.
Concat Variable.Concat(Vector first, Vector second) Concatenates two random vectors.
Subvector Variable.Subvector(Vector subVector, int startIndex, int count) Extract contiguous elements from a random vector.
StringFromArray Variable.StringFromArray(char[] chars) Create a string random variable from a random character array.
GetItem Variable.GetItem(Vector source, int index) Variable.GetItem(string str, int pos) Extract an element of a random vector or a string.
FunctionEvaluate Variable.FunctionEvaluate(IFunction func, Vector x) Evaluate a random function at a point. Used to construct Gaussian Process models like this one.