@@ -28,24 +28,26 @@ First, we define the (noisy) function to be sampled. Note that the parameter
28
28
29
29
.. jupyter-execute ::
30
30
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
32
33
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)
34
36
return y + noise
35
37
36
38
This is how the function looks in the absence of noise:
37
39
38
40
.. jupyter-execute ::
39
41
40
42
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)]
42
44
hv.Path((xs, ys))
43
45
44
46
And an example of a single realization of the noisy function:
45
47
46
48
.. jupyter-execute ::
47
49
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) ]
49
51
hv.Path((xs, ys))
50
52
51
53
To obtain an estimate of the mean value of the function at each point ``x ``, we
0 commit comments