mojolearn.SVGP#

class mojolearn.SVGP(n_inducing=32, *, inducing_points=None, kernel_variance=1.0, lengthscale=1.0, noise_variance=1.0, jitter=1e-06)[source]#

Bases: _XNeighbors

Sparse variational Gaussian process regression with inducing points.

A Gaussian process regressor with a Gaussian likelihood, a squared-exponential kernel and zero mean, in the form of GPflow’s SVGP. The variational distribution q(u) = N(q_mu, q_sqrt q_sqrt^T) is set to its optimum for the given hyperparameters (Titsias 2009), and elbo_ is the resulting bound. The hyperparameters are used as given and are not optimized (GPflow trains them by gradient steps). Inputs and outputs are float32; the fit solves the inducing-point system in extended (float-float) precision.

Parameters:
  • n_inducing (int, default 32) – Number of inducing points when inducing_points is None: that many training rows, evenly spaced (row i * n // M), at most n.

  • inducing_points (array-like of shape (M, n_features) or None, default None) – Inducing point locations.

  • kernel_variance (float, default 1.0) – Signal variance of the kernel.

  • lengthscale (float, default 1.0) – Kernel lengthscale.

  • noise_variance (float, default 1.0) – Variance of the Gaussian likelihood.

  • jitter (float, default 1e-6) – Diagonal jitter added to the inducing-point kernel matrix.

  • numeric_mode ({‘identical’, ‘deterministic’, ‘fast’} or None, default None) – Numeric mode for this estimator ('fast' is Apple only). None uses the process default.

Variables:
  • Z_ (Array of shape (M, n_features)) – Inducing points.

  • q_mu_ (Array of shape (M,)) – Mean of q(u) (non-whitened).

  • q_sqrt_ (Array of shape (M, M)) – Square root of the covariance of q(u) (non-whitened).

  • elbo_ (float) – Evidence lower bound at the optimal q(u).

  • precision_ (str) – Precision of the fit’s linear algebra, 'float-float'.

  • n_features_in_ (int) – Number of features seen in fit.

Examples

>>> import numpy as np, mojolearn
>>> rng = np.random.default_rng(0)
>>> X = rng.random((1000, 4), dtype=np.float32)
>>> y = np.sin(6 * X[:, 0]).astype(np.float32)
>>> model = mojolearn.SVGP(n_inducing=32, lengthscale=0.3, noise_variance=0.01).fit(X, y)
>>> mean, var = model.predict_y(X)
__init__(n_inducing=32, *, inducing_points=None, kernel_variance=1.0, lengthscale=1.0, noise_variance=1.0, jitter=1e-06)[source]#

Methods

fit(X, y)

Fit the variational distribution for the given hyperparameters.

get_params([deep])

numeric_mode_used()

The numeric mode this estimator runs in.

predict(X)

Predictive mean at X (the mean of predict_f()).

predict_f(X)

Mean and variance of the latent function at X.

predict_y(X)

Mean and variance of the observations at X (latent variance plus noise_variance).

set_params(**params)

Set constructor parameters.

vendor_used()

The GPU backend this estimator runs on.

fit(X, y)[source]#

Fit the variational distribution for the given hyperparameters.

Parameters:
  • X (array-like or scipy.sparse matrix of shape (n_samples, n_features)) – Training inputs.

  • y (array-like of shape (n_samples,)) – Training targets.

Returns:

self (SVGP) – The fitted model.

Raises:

ValueError – If X and y have different numbers of rows, or the inducing-point system is not positive definite (raise jitter or noise_variance).

predict_f(X)[source]#

Mean and variance of the latent function at X.

Parameters:

X (array-like of shape (n_queries, n_features)) – Query inputs.

Returns:

  • mean (Array of shape (n_queries,), float32)

  • var (Array of shape (n_queries,), float32)

predict_y(X)[source]#

Mean and variance of the observations at X (latent variance plus noise_variance).

Parameters:

X (array-like of shape (n_queries, n_features)) – Query inputs.

Returns:

  • mean (Array of shape (n_queries,), float32)

  • var (Array of shape (n_queries,), float32)

predict(X)[source]#

Predictive mean at X (the mean of predict_f()).

Parameters:

X (array-like of shape (n_queries, n_features)) – Query inputs.

Returns:

mean (Array of shape (n_queries,), float32)