CSOFT: Probabilistic modelling in C#

John Winn, Tom Minka


CSOFT is an extension to the C# language that adds probabilistic modelling and inference capabilities. CSOFT allows probabilistic models to be defined directly in C# by extending the language to include random variables and stochastic constraints between variables.

The primary aims of CSOFT are:

A CSOFT program defines one or more probabilistic models along with the inference queries to be made on each model. Critically, the program does not say how the inference is to be performed – this is handled separately, for example by using the Infer.NET inference framework.

A key advantage of CSOFT is that it allows stochastic code to be mixed with standard C# code, allowing easy integration of probabilistic inference into ordinary C# programs. As the inference framework is not directly invoked, there is no need to learn a new API, or a new XML modelling file format. The model is expressed naturally in C# with just a few additional operators.

For example, the CSOFT method below defines a Gaussian mixture model. The return value is a random variable of type double, with a mixture of Gaussians distribution on its value.

double MixtureOfGaussians(double[] means,double[] vars) 
{
  int i = random new Uniform(0,means.Length-1);
  return random new Gaussian(means[i], vars[i]);
}

In this example, the CSOFT random operator allows random variables to be defined. Gaussian and Uniform are C# classes that define distributions.  CSOFT also allows constraints to be added through the weight and observe operators and inference to be performed via the infer operator.


Links


Machine Learning and Perception Machine Learning—CSOFT