Tobias-Kohn / PyFOPPL

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

Nested if expressions not compiling #6

Closed bayesianbrad closed 6 years ago

bayesianbrad commented 6 years ago

For example

(let [x1 (sample (normal 0 1))
      x2 (sample (gamma 3 2))]
  (if (> x1 0)
    (observe (normal 1 1) 1)
    (observe (normal -1 1) 1))
    (if (> x2 1)
      (observe (gamma 1 2) 2)
      (observe (gamma 3 4  ) 4 )))
  x1 x2)
haohaiziround commented 6 years ago

The syntax does not seem correct. Try this one.

(let [x (sample (normal 0 1))]
  (if (> x 0)
    (if (< x 1)
      (observe (normal 0.5 1) 1)
      (observe (normal 2 1) 1))
    (if (> x -1)
      (observe (normal -0.5 1) 1)
      (observe (normal -2 1) 1)))
  x)
Tobias-Kohn commented 6 years ago

@haohaiziround is absolutely correct; basically, there is an if missing in the code. However, I slightly improved the error message. If I add the missing if, it seems to work fine:

(let [x1 (sample (normal 0 1))
      x2 (sample (gamma 3 2))]
  (if (< x1 x2)
    (if (> x1 0)
      (observe (normal 1 1) 1)
      (observe (normal -1 1) 1))
    (if (> x2 1)
      (observe (gamma 1 2) 2)
      (observe (gamma 3 4) 4 )))
  [x1 x2])