@@ -28,24 +28,26 @@ First, we define the (noisy) function to be sampled. Note that the parameter
2828
2929.. jupyter-execute ::
3030
31- def noisy_peak(x, sigma=0, peak_width=0.05, offset=-0.5):
31+ def noisy_peak(seed_x, sigma=0, peak_width=0.05, offset=-0.5):
32+ seed, x = seed_x # tuple with seed and `x ` value
3233 y = x ** 3 - x + 3 * peak_width ** 2 / (peak_width ** 2 + (x - offset) ** 2)
33- noise = np.random.normal(0, sigma)
34+ rng = np.random.RandomState(seed)
35+ noise = rng.normal(scale=sigma)
3436 return y + noise
3537
3638This is how the function looks in the absence of noise:
3739
3840.. jupyter-execute ::
3941
4042 xs = np.linspace(-2, 2, 500)
41- ys = noisy_peak(xs , sigma=0)
43+ ys = [ noisy_peak((seed, xs) , sigma=0) for seed, x in enumerate(xs)]
4244 hv.Path((xs, ys))
4345
4446And an example of a single realization of the noisy function:
4547
4648.. jupyter-execute ::
4749
48- ys = [noisy_peak(x , sigma=1) for x in xs ]
50+ ys = [noisy_peak((seed, x) , sigma=1) for seed, x in enumerate(xs) ]
4951 hv.Path((xs, ys))
5052
5153To obtain an estimate of the mean value of the function at each point ``x ``, we
0 commit comments