probprog / anglican-examples

Examples for Probabilistic System Anglican
13 stars 6 forks source link

The branching model has non-deterministic error #1

Open xukai92 opened 7 years ago

xukai92 commented 7 years ago

The branching model in the branching_aistats.clj file has some non-deterministic error.

(defn fib [n]
  "returns the n-th number in the Fibonacci sequence"
  (loop [a 0 b 1 m 0]
    (if (= m n)
      a
      (recur b (+ a b) (inc m)))))

(with-primitive-procedures [fib]
  (defquery branching
      "A simple example illustrating flow control with
      dependence on random choices"
      []
      (let [count-prior (poisson 4)
            r (sample count-prior)
            l (if (< 4 r)
                6
                (+ (fib (* 3 r))
                   (sample count-prior)))]
        (observe (poisson l) 6)
        (predict :r r)
        (predict :l l))))

If I run it with a lot of particles with SMC sampler, it sometimes give Error during inference: org.apache.commons.math3.exception.NotStrictlyPositiveException: mean (0) (but sometimes not). If the # of particles is large (say 500,000), it will be broken nearly every time.

fwood commented 7 years ago

Good catch!

Many apologies both for the delay and for the error.

Please note that this is a simple bug in the implementation of fib. The correct code can be found here http://www.robots.ox.ac.uk/~fwood/anglican/examples/viewer/?worksheet=aistats/branching-aistats. For ease of reference I include it here

(defn fib [n] "returns the n-th number in the Fibonacci sequence" (loop [a 1 b 1 m 0](if %28= m n%29 a %28recur b %28+ a b%29 %28inc m%29%29)))


Dr. Frank Wood Associate Professor - Information Engineering, Oxford Fellow - Kellogg College, Oxford Fellow - Alan Turing Institute Telephone: +441865283060 Web: http://www.robots.ox.ac.uk/~fwood Email: fwood@robots.ox.ac.uk Office: IEB 20.03

University of Oxford Department of Engineering Science Parks Road Oxford OX1 3PJ

Assistant: Maddy Crudge Email: maddy@robots.ox.ac.uk +44 1865 283058

Where: http://www.eng.ox.ac.uk/contact/how-to-reach-the-department

On Tue, Nov 8, 2016 at 9:03 PM, Kai Xu notifications@github.com wrote:

The branching model in the branching_aistats.clj file has some non-deterministic error.

(defn fib [n] "returns the n-th number in the Fibonacci sequence" (loop [a 0 b 1 m 0](if %28= m n%29 a %28recur b %28+ a b%29 %28inc m%29%29)))

(with-primitive-procedures [fib](defquery branching "A simple example illustrating flow control with dependence on random choices" [] %28let [count-prior %28poisson 4) r (sample count-prior) l (if (< 4 r) 6 (+ (fib (* 3 r)) (sample count-prior)))] (observe (poisson l) 6) (predict :r r) (predict :l l))))

If I run it with a lot of particles with SMC sampler, it sometimes give Error during inference: org.apache.commons.math3.exception.NotStrictlyPositiveException: mean (0) (but sometimes not). If the # of particles is large (say 500,000), it will be broken nearly every time.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/probprog/anglican-examples/issues/1, or mute the thread https://github.com/notifications/unsubscribe-auth/AADZnkNFhQaQ2O7wrv3sBV2o1LZBSkm8ks5q8OOGgaJpZM4Ks54l .