Tobias-Kohn / PyFOPPL

A FOPPL-Implementation in Python (Lisp-based Probabilistic Programming)
MIT License
4 stars 1 forks source link

RVs/sample statement inside if #8

Closed haohaiziround closed 6 years ago

haohaiziround commented 6 years ago

We cannot compile the model with let statement/ variable declaration inside ifs. For example, the following code does not compile correctly.

(let [x1 (sample (normal 0 1))
      y 1]
  (if (> x1 0)
    (let [x2 (sample (normal 0 1))]
      (observe (normal x2 1) y))
    (let [x3 (sample (normal 0 1))]
      (observe (normal x3 1) y)))
  (vector x1 x2 x3))

Also, the code above should behave the same as the code beneath (in terms of the joint, ie. the final logp) since the sample statements only contribute priors to the joint no matter inside branch or outside branch.

(let [x1 (sample (normal 0 1))
      x2 (sample (normal 0 1))
      x3 (sample (normal 0 1))
      y 1]
  (if (> x1 0)
    (observe (normal x2 1) y)
    (observe (normal x3 1) y))
  (vector x1 x2 x3))
haohaiziround commented 6 years ago

My bad. Some simple error in the return statement.