Skip to content

Add Spline Interpolation using basis functions #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jun 27, 2022
Merged

Add Spline Interpolation using basis functions #52

merged 14 commits into from
Jun 27, 2022

Conversation

ferrine
Copy link
Member

@ferrine ferrine commented Jun 27, 2022

GPs for time series or spatial data often require a lot of compute. Having dense grid to evaluate GP on, makes GP prohibitively large. Spline interpolation is a good way to reduce the GP domain maintaining coverage for the whole grid.

In the PR I aim to implement 1d spline interpolation for time series. Adding a simple util can ease the usage of GPs on large grids

Example API

import pymc as pm
import numpy as np
import pymc_experimental as pmx
import matplotlib.pyplot as plt
half_months = np.linspace(0, 365, 12*2)
with pm.Model(coords=dict(knots_time=half_months, time=np.arange(365))) as model:
    kernel = pm.gp.cov.ExpQuad(1, ls=365/12)
    # ready to define gp (a latent process over parameters)
    gp = pm.gp.gp.Latent(
        cov_func=kernel
    )
    y_knots = gp.prior("y_knots", half_months[:, None], dims="knots_time")
    y = pm.Deterministic(
        "y", 
        pmx.utils.spline.bspline_interpolation(y_knots, n=365, degree=3),
        dims="time"
    )
    trace = pm.sample_prior_predictive(1)
plt.scatter(half_months, trace.prior["y_knots"].sel(chain=0, draw=0))
plt.plot(np.arange(365), trace.prior["y"].sel(chain=0, draw=0))

image

@ferrine ferrine changed the title Add Spline Interpolation for GP Add Spline Interpolation using basis functions Jun 27, 2022
@twiecki
Copy link
Member

twiecki commented Jun 27, 2022

Did you borrow from @aseyboldt's BayesAlpha/BayesBeta?

@ferrine
Copy link
Member Author

ferrine commented Jun 27, 2022

Did you borrow from @aseyboldt's BayesAlpha/BayesBeta?

I added this info into Notes

@ferrine
Copy link
Member Author

ferrine commented Jun 27, 2022

I think I should also add evaluation on a non-regular grid

@ferrine
Copy link
Member Author

ferrine commented Jun 27, 2022

@ricardoV94 or @twiecki do you have any other suggestions? I'm ready to just merge

@ferrine ferrine merged commit 9743786 into main Jun 27, 2022
@ferrine ferrine deleted the spline-gp branch June 27, 2022 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants