Path: blob/master/notebooks/book2/29/gp_mauna_loa.ipynb
1193 views
Gaussian process time series forecasting for Mauna Loa CO2
In the following, we'll reproduce the analysis for Figure 5.6 in Chapter 5 of Rasmussen & Williams (R&W).
Code is from https://tinygp.readthedocs.io/en/latest/tutorials/quickstart.html
Data
The data are measurements of the atmospheric CO2 concentration made at Mauna Loa, Hawaii (Keeling & Whorf 2004). Data can be found at http://scrippsco2.ucsd.edu/data/atmospheric_co2/primary_mlo_co2_record. We use the [statsmodels version](http://statsmodels.sourceforge.net/devel/datasets/generated/co2.html].
Kernel
In this figure, you can see that there is periodic (or quasi-periodic) signal with a year-long period superimposed on a long term trend. We will follow R&W and model these effects non-parametrically using a complicated covariance function. The covariance function that we’ll use is:
where
We can implement this kernel in tinygp
as follows (we'll use the R&W results as the hyperparameters for now):
Model fitting
Using our loss function defined above, we'll run a gradient based optimization routine from scipy
(you could also use a jax
-specific optimizer, but that's not necessary) to fit this model as follows:
Warning: An optimization code something like this should work on most problems but the results can be very sensitive to your choice of initialization and algorithm. If the results are nonsense, try choosing a better initial guess or try a different value of the method
parameter in op.minimize
.