7
$\begingroup$

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

But then you can add:

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?

$\endgroup$
  • 1
    $\begingroup$ Well, it's just Bayes' theorem at work there, and that comes down to a straightforward formula. $\endgroup$ – Daniel Lichtblau Sep 3 '16 at 22:28
  • 1
    $\begingroup$ 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 $\endgroup$ – Luxspes Sep 3 '16 at 22:45
  • 2
    $\begingroup$ Have a look to the paper of john Cassel "Probabilistic Programming with Stochastic Memoization Implementing Nonparametric Bayesian Inference" in the Mathematica Journal $\endgroup$ – cyrille.piatecki Sep 5 '16 at 4:50
  • $\begingroup$ Somwhat related: 128945. $\endgroup$ – gwr Oct 18 '16 at 9:36
  • $\begingroup$ The link to John Cassel's article is The Mathematica Journal, Vol. 16. $\endgroup$ – gwr Nov 15 '16 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.