# Is it possible to do probabilistic programming by variable elimination with plain Mathematica 10 or later?

Using frameworks like Figaro it is possible to do probabilistic programming by variable elimination to build a probabilistic model and then run inferences against it in a very intuitive way. Example:

import com.cra.figaro.language._
import com.cra.figaro.algorithm.factored.VariableElimination
import com.cra.figaro.library.compound.If

val sunnyToday = Flip(0.2)
println(VariableElimination.probability(sunnyToday, true))


Will print 0.2

val greetingToday = If(sunnyToday, Select(0.6->"Hello, world!", 0.4->"Howdy, universe!"),
Select(0.2->"Hello, world!", 0.8->"Oh no, not again!"))


And state that you have observed "Hello, world!"

greetingToday.observe("Hello, world!")
println(VariableElimination.probability(sunnyToday,true))


And you will get 0.4285

And after that you can remove that observation:

greetingToday.unobserve()
println(VariableElimination.probability(sunnyToday,true))


and you will get 0.2

And you can even chain this further and represent conditional probabilities for the next day...

I have the nagging feeling that Mathematica's Probability should be able to describe this high level operations intuitively and make the same calculations, but I have been unable to find such an example anywhere... Is it possible to do this with plain mathematica? Or is Probability too low level and a higher level framework has yet to be built on top of it to achieve something like this?

• Well, it's just Bayes' theorem at work there, and that comes down to a straightforward formula. – Daniel Lichtblau Sep 3 '16 at 22:28
• Which makes it all the more surprising that Mathematica doesn't support it out of the box @DanielLichtblau nor have any similar examples or tutorials – Luxspes Sep 3 '16 at 22:45
• Have a look to the paper of john Cassel "Probabilistic Programming with Stochastic Memoization Implementing Nonparametric Bayesian Inference" in the Mathematica Journal – cyrille.piatecki Sep 5 '16 at 4:50
• Somwhat related: 128945. – gwr Oct 18 '16 at 9:36
• The link to John Cassel's article is The Mathematica Journal, Vol. 16. – gwr Nov 15 '16 at 15:48