GithubHelp home page GithubHelp logo

sourangshughosh / abstractgps.jl Goto Github PK

View Code? Open in Web Editor NEW
3.0 0.0 0.0 1008 KB

AbstractGPs.jl is a package that defines a low-level API for working with Gaussian processes (GPs), and basic functionality for working with them in the simplest cases. As such it is aimed more at developers and researchers who are interested in using it as a building block than end-users of GPs.

License: Apache License 2.0

Julia 100.00%
gaussianprocess bayesianupdating bayesian-inference kernelfunctions posterior-probability

abstractgps.jl's Introduction

AbstractGPs

AbstractGPs.jl is a package that defines a low-level API for working with Gaussian processes (GPs), and basic functionality for working with them in the simplest cases. As such it is aimed more at developers and researchers who are interested in using it as a building block than end-users of GPs.

GP

Features

Setup

using AbstractGPs, KernelFunctions, Random
rng = MersenneTwister(0)

# Construct a zero-mean Gaussian process with a matern-3/2 kernel.
f = GP(Matern32Kernel())

# Specify some input and target locations.
x = randn(rng, 10)
y = randn(rng, 10)

Finite dimensional projection

Look at the finite-dimensional projection of f at x, under zero-mean observation noise with variance 0.1.

fx = f(x, 0.1)

Sample from GP from the prior at x under noise.

y_sampled = rand(rng, fx)

Compute the log marginal probability of y.

logpdf(fx, y)

Construct the posterior process implied by conditioning f at x on y.

f_posterior = posterior(fx, y)

A posterior process follows the AbstractGP interface, so the same functions which work on the posterior as on the prior.

rand(rng, f_posterior(x))
logpdf(f_posterior(x), y)

Compute the VFE approximation to the log marginal probability of y.

Here, z is a set of pseudo-points.

z = randn(rng, 4)
u = f(z)

Evidence Lower BOund (ELBO)

We provide a ready implentation of elbo w.r.t to the pseudo points. We can perform Variational Inference on pseudo-points by maximizing the ELBO term w.r.t pseudo-points z and any kernel parameters. For more information, see examples.

elbo(fx, y, u)

Construct the approximate posterior process implied by the VFE approximation.

The optimal pseudo-points obtained above can be used to create a approximate/sparse posterior. This can be used like a regular posterior in many cases.

f_approx_posterior = approx_posterior(VFE(), fx, y, u)

An approximate posterior process is yet another AbstractGP, so you can do things with it like

marginals(f_approx_posterior(x))

Sequential Conditioning

Sequential conditioning allows you to compute your posterior in an online fashion. We do this in an efficient manner by updating the cholesky factorisation of the covariance matrix and avoiding recomputing it from original covariance matrix.

# Define GP prior
f = GP(SqExponentialKernel())

Exact Posterior

# Generate posterior with the first batch of data on the prior f1.
p_fx = posterior(f(x[1:3], 0.1), y[1:3])

# Generate posterior with the second batch of data considering posterior p_fx1 as the prior.
p_p_fx = posterior(p_fx(x[4:10], 0.1), y[4:10])

Approximate Posterior

Adding observations in an sequential fashion
Z1 = rand(rng, 4)
Z2 = rand(rng, 3)
p_fx = approx_posterior(VFE(), f(x[1:7], 0.1), y[1:7], f(Z))
u_p_fx = update_approx_posterior(p_fx1, f(x[8:10], 0.1), y[8:10])
Adding pseudo-points in an sequential fashion
p_fx1 = approx_posterior(VFE(), f(X, 0.1), y, f(Z1))
u_p_fx1 = update_approx_posterior(p_fx1, f(Z2))

abstractgps.jl's People

Contributors

sourangshughosh avatar

Stargazers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.