MCPcopy Create free account
hub / github.com/algorithm-archivists/algorithm-archive / f

Function f

contents/metropolis/code/python/metropolis.py:4–18  ·  view source on GitHub ↗

Function proportional to target distribution, a sum of Gaussians. For testing, set normalize to True, to get target distribution exactly.

(x, normalize=False)

Source from the content-addressed store, hash-verified

2
3
4def f(x, normalize=False):
5 '''
6 Function proportional to target distribution, a sum of Gaussians.
7 For testing, set normalize to True, to get target distribution exactly.
8 '''
9 # Gaussian heights, width parameters, and mean positions respectively:
10 a = np.array([10., 3., 1.]).reshape(3, 1)
11 b = np.array([ 4., 0.2, 2.]).reshape(3, 1)
12 xs = np.array([-4., -1., 5.]).reshape(3, 1)
13
14 if normalize:
15 norm = (np.sqrt(np.pi) * (a / np.sqrt(b))).sum()
16 a /= norm
17
18 return (a * np.exp(-b * (x - xs)**2)).sum(axis=0)
19
20def g():
21 '''Random step vector.'''

Callers 2

metropolis_stepFunction · 0.70
test_metropolis_iterateFunction · 0.70

Calls

no outgoing calls

Tested by 1

test_metropolis_iterateFunction · 0.56