Skip to content

Commit dd542e6

Browse files
committed
Update mean and cov figure size
1 parent 951934a commit dd542e6

File tree

2 files changed

+158
-331
lines changed

2 files changed

+158
-331
lines changed

examples/gaussian_processes/GP-MeansAndCovs.ipynb

+119-302
Large diffs are not rendered by default.

myst_nbs/gaussian_processes/GP-MeansAndCovs.myst.md

+39-29
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@ jupytext:
66
format_version: 0.13
77
jupytext_version: 1.13.7
88
kernelspec:
9-
display_name: Python 3
9+
display_name: Python 3 (ipykernel)
1010
language: python
1111
name: python3
1212
---
1313

14+
(notebook_name)=
15+
# Mean and Covariance Functions
16+
17+
:::{post} Aug 31, 2021
18+
:tags: GP
19+
:category: intermediate
20+
:author: Bill Engels
21+
:::
22+
1423
```{code-cell} ipython3
1524
---
1625
papermill:
@@ -44,13 +53,14 @@ papermill:
4453
tags: []
4554
---
4655
RANDOM_SEED = 8927
56+
FIGSIZE = (10, 4)
4757
np.random.seed(RANDOM_SEED)
4858
az.style.use("arviz-darkgrid")
4959
```
5060

5161
+++ {"papermill": {"duration": 0.037844, "end_time": "2020-12-22T18:36:31.751886", "exception": false, "start_time": "2020-12-22T18:36:31.714042", "status": "completed"}, "tags": []}
5262

53-
# Mean and Covariance Functions
63+
#
5464

5565
A large set of mean and covariance functions are available in PyMC3. It is relatively easy to define custom mean and covariance functions. Since PyMC3 uses Theano, their gradients do not need to be defined by the user.
5666

@@ -204,7 +214,7 @@ cov += pm.gp.cov.WhiteNoise(1e-6)
204214
X = np.linspace(0, 2, 200)[:, None]
205215
K = cov(X).eval()
206216
207-
plt.figure(figsize=(14, 4))
217+
plt.figure(figsize=FIGSIZE)
208218
209219
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=K.shape[0]).random(size=3).T)
210220
plt.title("Samples from the GP prior")
@@ -313,7 +323,7 @@ cov = pm.gp.cov.WhiteNoise(sigma)
313323
X = np.linspace(0, 2, 200)[:, None]
314324
K = cov(X).eval()
315325
316-
plt.figure(figsize=(14, 4))
326+
plt.figure(figsize=FIGSIZE)
317327
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
318328
plt.title("Samples from the GP prior")
319329
plt.ylabel("y")
@@ -346,7 +356,7 @@ cov += pm.gp.cov.WhiteNoise(1e-6)
346356
X = np.linspace(0, 2, 200)[:, None]
347357
K = cov(X).eval()
348358
349-
plt.figure(figsize=(14, 4))
359+
plt.figure(figsize=FIGSIZE)
350360
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
351361
plt.title("Samples from the GP prior")
352362
plt.ylabel("y")
@@ -379,7 +389,7 @@ cov = tau * pm.gp.cov.RatQuad(1, ls, alpha)
379389
X = np.linspace(0, 2, 200)[:, None]
380390
K = cov(X).eval()
381391
382-
plt.figure(figsize=(14, 4))
392+
plt.figure(figsize=FIGSIZE)
383393
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
384394
plt.title("Samples from the GP prior")
385395
plt.ylabel("y")
@@ -410,7 +420,7 @@ cov = pm.gp.cov.Exponential(1, ls_inv=inverse_lengthscale)
410420
X = np.linspace(0, 2, 200)[:, None]
411421
K = cov(X).eval()
412422
413-
plt.figure(figsize=(14, 4))
423+
plt.figure(figsize=FIGSIZE)
414424
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
415425
plt.title("Samples from the GP prior")
416426
plt.ylabel("y")
@@ -444,7 +454,7 @@ cov = tau * pm.gp.cov.Matern52(1, ls)
444454
X = np.linspace(0, 2, 200)[:, None]
445455
K = cov(X).eval()
446456
447-
plt.figure(figsize=(14, 4))
457+
plt.figure(figsize=FIGSIZE)
448458
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
449459
plt.title("Samples from the GP prior")
450460
plt.ylabel("y")
@@ -477,7 +487,7 @@ cov = tau * pm.gp.cov.Matern32(1, ls)
477487
X = np.linspace(0, 2, 200)[:, None]
478488
K = cov(X).eval()
479489
480-
plt.figure(figsize=(14, 4))
490+
plt.figure(figsize=FIGSIZE)
481491
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
482492
plt.title("Samples from the GP prior")
483493
plt.ylabel("y")
@@ -507,7 +517,7 @@ cov = tau * pm.gp.cov.Matern12(1, ls)
507517
X = np.linspace(0, 2, 200)[:, None]
508518
K = cov(X).eval()
509519
510-
plt.figure(figsize=(14, 4))
520+
plt.figure(figsize=FIGSIZE)
511521
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
512522
plt.title("Samples from the GP prior")
513523
plt.ylabel("y")
@@ -540,7 +550,7 @@ cov += pm.gp.cov.WhiteNoise(1e-4)
540550
X = np.linspace(0, 2, 200)[:, None]
541551
K = cov(X).eval()
542552
543-
plt.figure(figsize=(14, 4))
553+
plt.figure(figsize=FIGSIZE)
544554
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
545555
plt.title("Samples from the GP prior")
546556
plt.ylabel("y")
@@ -574,7 +584,7 @@ cov += pm.gp.cov.WhiteNoise(1e-6)
574584
X = np.linspace(0, 2, 200)[:, None]
575585
K = cov(X).eval()
576586
577-
plt.figure(figsize=(14, 4))
587+
plt.figure(figsize=FIGSIZE)
578588
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
579589
plt.title("Samples from the GP prior")
580590
plt.ylabel("y")
@@ -610,7 +620,7 @@ cov += pm.gp.cov.WhiteNoise(1e-6)
610620
X = np.linspace(0, 2, 200)[:, None]
611621
K = cov(X).eval()
612622
613-
plt.figure(figsize=(14, 4))
623+
plt.figure(figsize=FIGSIZE)
614624
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
615625
plt.title("Samples from the GP prior")
616626
plt.ylabel("y")
@@ -644,7 +654,7 @@ cov = pm.gp.cov.Matern32(1, 0.5) * K_cos
644654
X = np.linspace(0, 2, 200)[:, None]
645655
K = cov(X).eval()
646656
647-
plt.figure(figsize=(14, 4))
657+
plt.figure(figsize=FIGSIZE)
648658
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
649659
plt.title("Samples from the GP prior")
650660
plt.ylabel("y")
@@ -685,14 +695,14 @@ cov += pm.gp.cov.WhiteNoise(1e-6)
685695
X = np.linspace(0, 2, 400)[:, None]
686696
wf = warp_func(X.flatten(), a, b, c).eval()
687697
688-
plt.figure(figsize=(14, 4))
698+
plt.figure(figsize=FIGSIZE)
689699
plt.plot(X, wf)
690700
plt.xlabel("X")
691701
plt.ylabel("warp_func(X)")
692702
plt.title("The warping function used")
693703
694704
K = cov(X).eval()
695-
plt.figure(figsize=(14, 4))
705+
plt.figure(figsize=FIGSIZE)
696706
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
697707
plt.title("Samples from the GP prior")
698708
plt.ylabel("y")
@@ -742,7 +752,7 @@ cov = pm.gp.cov.WarpedInput(1, cov_func=cov_exp, warp_func=mapping, args=(T,))
742752
cov += pm.gp.cov.WhiteNoise(1e-6)
743753
744754
K = cov(X).eval()
745-
plt.figure(figsize=(14, 4))
755+
plt.figure(figsize=FIGSIZE)
746756
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
747757
plt.title("Samples from the GP prior")
748758
plt.ylabel("y")
@@ -772,7 +782,7 @@ cov = pm.gp.cov.Periodic(1, period=period, ls=ls)
772782
cov += pm.gp.cov.WhiteNoise(1e-6)
773783
774784
K = cov(X).eval()
775-
plt.figure(figsize=(14, 4))
785+
plt.figure(figsize=FIGSIZE)
776786
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
777787
for p in np.arange(0, 2, period):
778788
plt.axvline(p, color="black")
@@ -822,7 +832,7 @@ tau = 4
822832
cov = pm.gp.cov.Circular(1, period=period, tau=tau)
823833
824834
K = cov(X).eval()
825-
plt.figure(figsize=(14, 4))
835+
plt.figure(figsize=FIGSIZE)
826836
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
827837
for p in np.arange(0, 2, period):
828838
plt.axvline(p, color="black")
@@ -851,7 +861,7 @@ tau = 40
851861
cov = pm.gp.cov.Circular(1, period=period, tau=tau)
852862
853863
K = cov(X).eval()
854-
plt.figure(figsize=(14, 4))
864+
plt.figure(figsize=FIGSIZE)
855865
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
856866
for p in np.arange(0, 2, period):
857867
plt.axvline(p, color="black")
@@ -896,14 +906,14 @@ cov = pm.gp.cov.Gibbs(1, tanh_func, args=(ls1, ls2, w, x0))
896906
cov += pm.gp.cov.WhiteNoise(1e-6)
897907
898908
wf = tanh_func(X, ls1, ls2, w, x0).eval()
899-
plt.figure(figsize=(14, 4))
909+
plt.figure(figsize=FIGSIZE)
900910
plt.plot(X, wf)
901911
plt.ylabel("lengthscale")
902912
plt.xlabel("X")
903913
plt.title("Lengthscale as a function of X")
904914
905915
K = cov(X).eval()
906-
plt.figure(figsize=(14, 4))
916+
plt.figure(figsize=FIGSIZE)
907917
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
908918
plt.title("Samples from the GP prior")
909919
plt.ylabel("y")
@@ -950,14 +960,14 @@ cov += pm.gp.cov.WhiteNoise(1e-5)
950960
X = np.linspace(0, 10, 400)[:, None]
951961
lfunc = logistic(X.flatten(), a, b, c, d).eval()
952962
953-
plt.figure(figsize=(14, 4))
963+
plt.figure(figsize=FIGSIZE)
954964
plt.plot(X, lfunc)
955965
plt.xlabel("X")
956966
plt.ylabel(r"$\phi(x)$")
957967
plt.title("The scaling function")
958968
959969
K = cov(X).eval()
960-
plt.figure(figsize=(14, 4))
970+
plt.figure(figsize=FIGSIZE)
961971
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
962972
plt.title("Samples from the GP prior")
963973
plt.ylabel("y")
@@ -1008,7 +1018,7 @@ cov = cov1 + cov2
10081018
cov += pm.gp.cov.WhiteNoise(1e-5)
10091019
10101020
X = np.linspace(0, 10, 400)
1011-
plt.figure(figsize=(14, 4))
1021+
plt.figure(figsize=FIGSIZE)
10121022
plt.fill_between(
10131023
X,
10141024
np.zeros(400),
@@ -1026,7 +1036,7 @@ plt.ylabel(r"$\phi(x)$")
10261036
plt.title("The two scaling functions")
10271037
10281038
K = cov(X[:, None]).eval()
1029-
plt.figure(figsize=(14, 4))
1039+
plt.figure(figsize=FIGSIZE)
10301040
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
10311041
plt.title("Samples from the GP prior")
10321042
plt.ylabel("y")
@@ -1073,7 +1083,7 @@ cov += pm.gp.cov.WhiteNoise(1e-6)
10731083
X = np.linspace(0, 2, 200)[:, None]
10741084
K = cov(X).eval()
10751085
1076-
plt.figure(figsize=(14, 4))
1086+
plt.figure(figsize=FIGSIZE)
10771087
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
10781088
plt.title("Samples from the GP prior")
10791089
plt.ylabel("y")
@@ -1108,7 +1118,7 @@ cov += pm.gp.cov.WhiteNoise(1e-6)
11081118
X = np.linspace(0, 2, 200)[:, None]
11091119
K = cov(X).eval()
11101120
1111-
plt.figure(figsize=(14, 4))
1121+
plt.figure(figsize=FIGSIZE)
11121122
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
11131123
plt.title("Samples from the GP prior")
11141124
plt.ylabel("y")
@@ -1141,7 +1151,7 @@ cov += pm.gp.cov.WhiteNoise(1e-6)
11411151
X = np.linspace(0, 2, 200)[:, None]
11421152
K = cov(X).eval()
11431153
1144-
plt.figure(figsize=(14, 4))
1154+
plt.figure(figsize=FIGSIZE)
11451155
plt.plot(X, pm.MvNormal.dist(mu=np.zeros(len(K)), cov=K, shape=len(K)).random(size=3).T)
11461156
plt.title("Samples from the GP prior")
11471157
plt.ylabel("y")

0 commit comments

Comments
 (0)