|
68 | 68 | "%config InlineBackend.figure_format = 'retina'\n",
|
69 | 69 | "RANDOM_SEED = 8927\n",
|
70 | 70 | "np.random.seed(RANDOM_SEED)\n",
|
71 |
| - "az.style.use('arviz-darkgrid')" |
| 71 | + "az.style.use(\"arviz-darkgrid\")" |
72 | 72 | ]
|
73 | 73 | },
|
74 | 74 | {
|
|
1310 | 1310 | " ηq = pm.HalfNormal(\"ηq\", sigma=5)\n",
|
1311 | 1311 | "\n",
|
1312 | 1312 | " cov1 = η ** 2 * pm.gp.cov.ExpQuad(1, ℓ)\n",
|
1313 |
| - " cov2 = η ** 2 * pm.gp.cov.ExpQuad(1, ℓ) + ηq ** 2 * pm.gp.cov.Polynomial(\n", |
1314 |
| - " 1, x0, 2, c\n", |
1315 |
| - " )\n", |
| 1313 | + " cov2 = η ** 2 * pm.gp.cov.ExpQuad(1, ℓ) + ηq ** 2 * pm.gp.cov.Polynomial(1, x0, 2, c)\n", |
1316 | 1314 | "\n",
|
1317 | 1315 | " # construct changepoint cov\n",
|
1318 | 1316 | " sc_cov1 = pm.gp.cov.ScaledCov(1, cov1, logistic, (-a, x0))\n",
|
|
1799 | 1797 | "outputs": [],
|
1800 | 1798 | "source": [
|
1801 | 1799 | "class CustomWhiteNoise(pm.gp.cov.Covariance):\n",
|
1802 |
| - " \"\"\" Custom White Noise covariance\n", |
| 1800 | + " \"\"\"Custom White Noise covariance\n", |
1803 | 1801 | " - sigma1 is applied to the first n1 points in the data\n",
|
1804 | 1802 | " - sigma2 is applied to the next n2 points in the data\n",
|
1805 |
| - " \n", |
| 1803 | + "\n", |
1806 | 1804 | " The total number of data points n = n1 + n2\n",
|
1807 | 1805 | " \"\"\"\n",
|
1808 | 1806 | "\n",
|
|
1922 | 1920 | " ℓp_decay = pm.Gamma(\"ℓp_decay\", alpha=40, beta=0.1)\n",
|
1923 | 1921 | " ℓp_smooth = pm.Normal(\"ℓp_smooth \", mu=1.0, sigma=0.05)\n",
|
1924 | 1922 | " period = 1 * 0.01 # we know the period is annual\n",
|
1925 |
| - " cov_p = (\n", |
1926 |
| - " ηp ** 2\n", |
1927 |
| - " * pm.gp.cov.Periodic(1, period, ℓp_smooth)\n", |
1928 |
| - " * pm.gp.cov.ExpQuad(1, ℓp_decay)\n", |
1929 |
| - " )\n", |
| 1923 | + " cov_p = ηp ** 2 * pm.gp.cov.Periodic(1, period, ℓp_smooth) * pm.gp.cov.ExpQuad(1, ℓp_decay)\n", |
1930 | 1924 | " gp_p = pm.gp.Marginal(cov_func=cov_p)\n",
|
1931 | 1925 | "\n",
|
1932 | 1926 | " gp = gp_c + gp_m + gp_s + gp_p\n",
|
|
1943 | 1937 | " σ2 = pm.Gamma(\"σ2\", alpha=3, beta=50)\n",
|
1944 | 1938 | " η_noise = pm.HalfNormal(\"η_noise\", sigma=1)\n",
|
1945 | 1939 | " ℓ_noise = pm.Gamma(\"ℓ_noise\", alpha=2, beta=200)\n",
|
1946 |
| - " cov_noise = η_noise ** 2 * pm.gp.cov.Matern32(1, ℓ_noise) + CustomWhiteNoise(\n", |
1947 |
| - " σ1, σ2, 111, 545\n", |
1948 |
| - " )\n", |
| 1940 | + " cov_noise = η_noise ** 2 * pm.gp.cov.Matern32(1, ℓ_noise) + CustomWhiteNoise(σ1, σ2, 111, 545)\n", |
1949 | 1941 | "\n",
|
1950 | 1942 | " y_ = gp.marginal_likelihood(\"y\", X=t_combined[:, None], y=y_n, noise=cov_noise)"
|
1951 | 1943 | ]
|
|
2141 | 2133 | ],
|
2142 | 2134 | "source": [
|
2143 | 2135 | "plt.figure(figsize=(12, 5))\n",
|
2144 |
| - "plt.plot(\n", |
2145 |
| - " tnew * 100, y_sd * ppc[\"fnew\"][0:200:5, :].T + y_mu, color=\"lightblue\", alpha=0.8\n", |
2146 |
| - ")\n", |
| 2136 | + "plt.plot(tnew * 100, y_sd * ppc[\"fnew\"][0:200:5, :].T + y_mu, color=\"lightblue\", alpha=0.8)\n", |
2147 | 2137 | "plt.plot(\n",
|
2148 | 2138 | " [-1000, -1001],\n",
|
2149 | 2139 | " [-1000, -1001],\n",
|
|
2198 | 2188 | ],
|
2199 | 2189 | "source": [
|
2200 | 2190 | "plt.figure(figsize=(12, 5))\n",
|
2201 |
| - "plt.plot(\n", |
2202 |
| - " tnew * 100, y_sd * ppc[\"fnew\"][0:200:5, :].T + y_mu, color=\"lightblue\", alpha=0.8\n", |
2203 |
| - ")\n", |
| 2191 | + "plt.plot(tnew * 100, y_sd * ppc[\"fnew\"][0:200:5, :].T + y_mu, color=\"lightblue\", alpha=0.8)\n", |
2204 | 2192 | "plt.plot(\n",
|
2205 | 2193 | " [-1000, -1001],\n",
|
2206 | 2194 | " [-1000, -1001],\n",
|
|
2325 | 2313 | "source": [
|
2326 | 2314 | "plt.figure(figsize=(12, 5))\n",
|
2327 | 2315 | "\n",
|
2328 |
| - "plt.plot(\n", |
2329 |
| - " tnew * 100, y_sd * ppc[\"fnew2\"][0:200:10, :].T + y_mu, color=\"lightblue\", alpha=0.8\n", |
2330 |
| - ")\n", |
| 2316 | + "plt.plot(tnew * 100, y_sd * ppc[\"fnew2\"][0:200:10, :].T + y_mu, color=\"lightblue\", alpha=0.8)\n", |
2331 | 2317 | "plt.plot(\n",
|
2332 | 2318 | " [-1000, -1001],\n",
|
2333 | 2319 | " [-1000, -1001],\n",
|
|
2452 | 2438 | "source": [
|
2453 | 2439 | "plt.figure(figsize=(12, 5))\n",
|
2454 | 2440 | "\n",
|
2455 |
| - "plt.plot(\n", |
2456 |
| - " tnew * 100, y_sd * ppc[\"fnew3\"][0:200:10, :].T + y_mu, color=\"lightblue\", alpha=0.8\n", |
2457 |
| - ")\n", |
| 2441 | + "plt.plot(tnew * 100, y_sd * ppc[\"fnew3\"][0:200:10, :].T + y_mu, color=\"lightblue\", alpha=0.8)\n", |
2458 | 2442 | "plt.plot(\n",
|
2459 | 2443 | " [-1000, -1001],\n",
|
2460 | 2444 | " [-1000, -1001],\n",
|
|
0 commit comments