Function proportional to target distribution, a sum of Gaussians. For testing, set normalize to True, to get target distribution exactly.
(x, normalize=False)
| 2 | |
| 3 | |
| 4 | def 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 | |
| 20 | def g(): |
| 21 | '''Random step vector.''' |
no outgoing calls