File: noisybanana.py

package info (click to toggle)
python-bumps 1.0.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,200 kB
  • sloc: python: 24,517; xml: 493; ansic: 373; makefile: 211; javascript: 99; sh: 94
file content (29 lines) | stat: -rw-r--r-- 554 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
The Rosenbrock banana function

Demonstration that sampling works even when the density is unstable.
"""

from dream import *
from pylab import *
from numpy.random import lognormal


def rosen(x):
    x = asarray(x)
    s = sum(100.0 * (x[1:] - x[:-1] ** 2) ** 2 + (1 - x[:-1]) ** 2)
    return -lognormal(s, sqrt(s))  # Poisson style: variance = # counts


n = 3
sampler = Dream(
    model=LogDensity(rosen),
    population=randn(20, n, n),
    thinning=1,
    burn=20000,
    draws=20000,
)

mc = sampler.sample()
# plot_corr(mc); show()
mc.show()