SGP Class

This is a tutorial on how to use the SGP class.


In [1]:
import buqeyemodel as bq
import matplotlib.pyplot as plt
import numpy as np
import scipy as sp
%matplotlib inline

In [2]:
np.random.seed(1)
X = np.linspace(0, 1, 500)[:, None]
n_orders = 5
orders = np.arange(0, n_orders)
ls = 0.2
ratio = 0.5

data = bq.toy_data(X=X, orders=orders, ratio=ratio, ls=ls)
coeffs = bq.coefficients(partials=data, ratio=ratio)

fig, ax = plt.subplots(1, 2, figsize=(8, 4))
for i in range(n_orders):
    ax[0].plot(X.ravel(), data[i], label=i)
    ax[1].plot(X.ravel(), coeffs[i], label=i)
ax[0].set_title('Observable Orders')
ax[1].set_title('Observable Coefficients')
ax[0].set_xlabel('X')
ax[1].set_xlabel('X')
ax[0].legend();
ax[1].legend();



In [3]:
model = bq.SGP()
model.observe(X=X, y=coeffs, ls=ls)
pred, pred_dob = model.predict(Xnew=X, dob=[0.68, 0.95])

plt.plot(X, pred)
plt.plot(X, pred_dob[0].T, c='gray', ls='--', lw=0.7)
plt.plot(X, pred_dob[1].T, c='gray', ls='--', lw=0.5);



In [ ]:
dist = model.predictive(Xnew=X, corr=True)
plt.plot(X, dist.rvs(20).T);



In [ ]:
dobs = np.arange(0.1, 1, 0.1)
ref_dobs = np.arange(0.01, 1, 0.01)
ref_alphas = np.array([0.68, 0.95, 0.99])
D_CI, bands = model.credible_diagnostic(
    data=coeffs[1], dobs=dobs, ref_alphas=ref_alphas, ref_dobs=ref_dobs, ref_samples=1e4, Xnew=X)
print(bands.shape)
fig, ax = plt.subplots(1, 1)
ax.plot(dobs, D_CI)
ax.set_xlim([0, 1])
ax.set_ylim([0, 1]);
ax.fill_between(ref_dobs, y1=bands[0,:, 0], y2=bands[0,:, 1], alpha=0.5, color='gray')
ax.fill_between(ref_dobs, y1=bands[1,:, 0], y2=bands[1,:, 1], alpha=0.5, color='gray');


100000

In [ ]: