ProbFuzz
A Framework For Testing Probabilistic Programming Systems
Tutorial 2 : Adding a Custom Template
All the templates needs to placed in $ROOT/language/template and config.json* needs to be updated. The basic format of the template is: DATA+ PRIOR+ MODEL* QUERY+
Data: The user needs to specify concrete data values on which the model needs to run
      x : [0, 1, 2, ... ]    
or, use a placeholder with type and size for ProbFuzz to fill in random values:
      x : float[10]    
or specify a relation between other data items:
      x : float[10]
      weight : float
      bias : float
      y: weight*x + bias 
Prior: The user needs to specify all the parameters of the model and assign prior distributions to all of them. The user can either specify a concrete distribution
      w := normal(0,1) 
or, use a placeholder for the distribution or for its parameters:
      w := DIST(1,1)
      w := normal(CONST, CONST) 
or, let ProbFuzz choose some distribution
      w := DISTX
    
Model: ProbFuzz supports three kinds of statements as part of the model:
Assignment:
      p = x + y
Observe:
      observe(Normal(w*x + b), y)
or, Conditional:
      if (cond)
      then
      observe(DIST(w*x + b), y)
      else
      observe(DIST(0.5*x + b), y)
      
Here, w and b are parameters and x and y are data variables.
Finally, we need to specify the parameters for which we want to compute the posterior distributions:
      posterior(w)

Putting all of them together we can get something like:
    x : float[10]
    weight : float
    bias : float
    y : weight*x + bias
    w := DISTX
    b := DISTX
    p := DISTX
    cond = bernoulli(CONST)
    if (cond)
    then
    observe(DIST(w*x + b, p), y)
    else
    observe(DIST(5.0*x + b, p), y)

    posterior(w)
    posterior(b)
    posterior(p)
This is the Linear Regression with Conditionals template in ProbFuzz.