Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The branching model has non-deterministic error #1

Open
xukai92 opened this issue Nov 8, 2016 · 1 comment
Open

The branching model has non-deterministic error #1

xukai92 opened this issue Nov 8, 2016 · 1 comment

Comments

@xukai92
Copy link

xukai92 commented Nov 8, 2016

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
Copy link

fwood commented Nov 10, 2016

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: [email protected]
Office: IEB 20.03

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

Assistant: Maddy Crudge
Email: [email protected]
+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 [email protected] 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
#1, or mute the
thread
https://github.com/notifications/unsubscribe-auth/AADZnkNFhQaQ2O7wrv3sBV2o1LZBSkm8ks5q8OOGgaJpZM4Ks54l
.

dtolpin added a commit that referenced this issue Jul 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants