gp Package

gp Package

Gaussian Processes for regression.

class pypr.gp.GaussianProcess(cf)

Gaussian Process class.

Methods

find_likelihood_der
fit_data
generate
regression
find_likelihood_der(X, y)

Find the negative log likelihood and its partial derivatives.

fit_data(X, y)

Fit the hyper-parameters to the data.

X Input samples (2d array, samples row-wise) y Function output (1d array)

generate(x, rn=None)

Generate samples from the GP.

Parameters :

x : np array

A 2d matrix with samples row-wise

rn : np array

Provide your own random numbers (mostly just for testing)

regression(X, y, XX, max_samples=1000)

Predict the y values for XX given the X, y, and the objects covariance function.

Parameters :

X : MxD np array

training array containing M samples of dimension D

y : 1-dimensional np array of length M

training outputs

XX : NxD np array

An array containing N samples, with D inputs

max_samples : int, optional

Due to memory considerations, the inputs are evaluated part at a time. The maximum number of samples evaluated in each interation is given by max_samples

Returns :

ys : np array of length N

output of GPR

s2 : np array of length N

corresponding variance

GaussianProcess Module

class pypr.gp.GaussianProcess.GPR(GP, X, y, max_itr=200, callback=None, print_progress=False, no_train=False, mean_tol=None)

Bases: object

Gaussian Process for regression.

Methods

df
f
find_hyperparameters
predict
df(params=None)

The partial derivatives of the function to minimize, which is the likihood in this case. This method is passed to the optimizer.

Parameters :

params : 1D np array, optional

hyper-parameters to evaluate at. It not specified, then the current values in the covariance function are used.

Returns :

der : np array

array of partial derivatives

f(params=None)

The function to minimize, which is the likihood in this case. This method is passed to the optimizer.

Parameters :

params : 1D np array, optional

hyper-parameters to evaluate at. It not specified, then the current values in the covariance function are used.

Returns :

nllikelihood : float

Negative log likihood

find_hyperparameters(max_itr=None)

Find hyperparameters for the GP.

predict(XX)

Predict the the output of the GPR for the inputs given in XX

Parameters :

XX : NxD np array

An array containing N samples, with D inputs

Returns :

res : np array

An array of length N containing the outputs of the network

class pypr.gp.GaussianProcess.GaussianProcess(cf)

Gaussian Process class.

Methods

find_likelihood_der
fit_data
generate
regression
find_likelihood_der(X, y)

Find the negative log likelihood and its partial derivatives.

fit_data(X, y)

Fit the hyper-parameters to the data.

X Input samples (2d array, samples row-wise) y Function output (1d array)

generate(x, rn=None)

Generate samples from the GP.

Parameters :

x : np array

A 2d matrix with samples row-wise

rn : np array

Provide your own random numbers (mostly just for testing)

regression(X, y, XX, max_samples=1000)

Predict the y values for XX given the X, y, and the objects covariance function.

Parameters :

X : MxD np array

training array containing M samples of dimension D

y : 1-dimensional np array of length M

training outputs

XX : NxD np array

An array containing N samples, with D inputs

max_samples : int, optional

Due to memory considerations, the inputs are evaluated part at a time. The maximum number of samples evaluated in each interation is given by max_samples

Returns :

ys : np array of length N

output of GPR

s2 : np array of length N

corresponding variance

covar_funcs Module

class pypr.gp.covar_funcs.cfCovarianceFunction

Bases: object

The base covariance function class. When creating a new covariance function, you should inherit this class.

Methods

clear_temp
derivative
eval
get_params
set_params
clear_temp()

This method clears all temporary variables used by the covariance functions. Should be called after finishing using the function, for example training.

derivative(x, param_no)

Evaluate a partial derivative of the covariance function.

Parameters :

x : NxD np array

Data to evaluate the covariance function on.

param_no : int

Parameter number to evaluate the partial derivative for.

Returns :

der : NxN np array

Returns the partial dirivatives with respect to the log of hyper- parameter number param_no. If x is a (N x D) matrix, then the returned matrix will be a (N x N) matrix.

eval(x, xs=None)

Calculate the covariance matrix.

Parameters :

x : NxD np array

The training set x is a NxD matrix, with N samples of dimensionallity D.

xs : MxD np array, optional

xs is the testset input, containing M samples. The

dimensionallity of the test set must be D.

Returns :

cov : NxN np array or a tuple

Depending if xs is specified the output will differ.

If `xs` is None, then the covariance matrix is returned. The matrix :

`x` is an (N x D) matrix, where there are N samples, and D :

dimensions. The returned matrix (array) will be a (N x N) matrix. :

`xs` is used to specify a test set. If xs (M x D) is set, a tuple :

(Kssdiag, Ks) is returned. Kssdiag is a column vector with m self :

covariances of the test set. Ks is a (N x M) matrix containing the :

cross variance between the training and test data. :

get_params()

Get the hyper-parameters.

Returns :

hp : list

Returns a list of hyperparameters. The order of the list is important.

set_params(log_parameters)

Set hyperparameters to the values given.

Parameters: log_parameters : list

Set the hyperparameters. The order of the list is important. The covariance functions’ hyperparameters are set from left to right.
class pypr.gp.covar_funcs.cfJitter(log_theta=-9.2100000000000009)

Bases: pypr.gp.covar_funcs.cfCovarianceFunction

Constant jitter, similar to noise, but cannot be changed. This can make the regression calculation better conditioned.

Methods

clear_temp
derivative
eval
get_params
set_params
derivative(x, param_no)

See help(cfCovarianceFunction.derivative)

eval(x, xs=None)

See help(cfCovarianceFunction.eval)

get_params()

Returns a list containing one element, which is the gaussian noise

set_params(log_parameters)

Set the gaussian noise hyperparameter. Must be a list with one element.

class pypr.gp.covar_funcs.cfNoise(log_theta=-2.3026)

Bases: pypr.gp.covar_funcs.cfCovarianceFunction

White noise.

Methods

clear_temp
derivative
eval
get_params
set_params
derivative(x, param_no)

See help(cfCovarianceFunction.derivative)

eval(x, xs=None)

See help(cfCovarianceFunction.eval)

get_params()

Get white noise hyperparameter

Returns :

log_hyperparameter : list

Returns a list containing one hyperparameter, which is the log of white noise variance.

set_params(log_parameters)

Set the white noise hyperparameter.

Parameters :

log_parameters : list

Set the gaussian noise hyperparameter. Must be a list with one element. The element is the log of the noise variance.

class pypr.gp.covar_funcs.cfSquaredExponentialARD(log_ell_D=[0.0], log_sqrt_sf2=0.0)

Bases: pypr.gp.covar_funcs.cfCovarianceFunction

The Squared Exponential covariance function with Automatic Relevance Determination (ARD).

Methods

clear_temp
derivative
eval
get_params
set_params
clear_temp()

This method clears all temporary variables used by the covariance function.

derivative(x, param_no)

See help(cfCovarianceFunction.derivative)

eval(x, xs=None)

See help(cfCovarianceFunction.eval)

get_params()

Get hyperparameters.

Returns :

hyperparameters : list

Returns a list of the log of the hyperparameters. The first elements in the list are the length scale hyperparameters (ARD parameters) and the last is the log square signal variance.

set_params(log_parameters)

Set the log of the hyperparameters

Parameters :

log_parameters : list

A list with D (number of dimensions) log lenght scale scalars, and a log_sqrt_sf2 at the end, log sqrt of signal variance.

class pypr.gp.covar_funcs.cfSquaredExponentialIso(log_ell=0.0, log_sqrt_sf2=0.0)

Bases: pypr.gp.covar_funcs.cfCovarianceFunction

The isotropic Squared Exponential covariance function.

Methods

clear_temp
derivative
eval
get_params
set_params
derivative(x, param_no)

See help(cfCovarianceFunction.derivative)

eval(x, xs=None)

See help(cfCovarianceFunction.eval)

get_params()

Returns a list of the log of the hyperparameters.

Returns :

log_hyperparameters : list

A list containing two elements log_ell Log lenght scale scalar log_sqrt_sf2 Log sqrt of signal variance

set_params(log_parameters)

Set the log of the hyperparameters to log_parameters.

Parameters :

log_parameters : list

Should be a list containing two float entries log_ell Log lenght scale scalar log_sqrt_sf2 Log sqrt of signal variance

class pypr.gp.covar_funcs.cfSum(a, b)

Bases: pypr.gp.covar_funcs.cfCovarianceFunction

The purpose of this class is to represent an addition of two covariance functions.

Methods

clear_temp
derivative
eval
get_params
set_params
clear_temp()

This method clears all temporary variables used by both the covariance functions in the sum.

derivative(x, param_no)

See help(cfCovarianceFunction.derivative)

eval(x, xs=None)

See help(cfCovarianceFunction.eval)

get_params()

Returns a list of the log of the hyperparameters.

set_params(log_params)

Set the log of the hyperparameters to log_parameters. The parameters in the left hand side covariance function are set to first part of the list, the right hand side covariance function to the rest.

pypr.gp.covar_funcs.sq_dist(A, B=None)

gp_unit_tests Module

class pypr.gp.gp_unit_tests.TestSequenceFunctions(methodName='runTest')

Bases: unittest.TestCase

setUp()
test_GPR_partial_derivatives()
test_cfNoise_derivative()
test_cfSquaredExponentialARD_der()
test_cfSquaredExponentialArd_eval()
test_cfSquaredExponentialIso_eval()
test_cfSquaredExponential_derivative()
test_generate()
test_init_params()
test_nllikeliness_and_der()
test_optimization()
test_regression()
test_set_params()
test_sq_dist()
test_sum_derivative()

info Module

Gaussian Processes for regression.

plot_gp Module

pypr.gp.plot_gp.plot_gpr(xs, ys, s2, axes=None, line_settings={'color': 'black', 'lw': 2.0}, shade_settings={'alpha': 0.5, 'facecolor': 'lightyellow'})

Plot the mean predicted values and 95% confidence interval, two times the standard error, as a shaded area.

Parameters :

xs: array :

an N length np array of the x* data

ys: array :

an N length np array of the y* data

s2: array :

an N length np array of the variance, var(y*), data

line_setting: dictionary, optional :

An dictionary with keywords and values to pass to the mean line of the plot. For example {‘linewidth’:2}

shade_setting: dictionary, optional :

An dictionary with keywords and values to pass to the fillbetween function.

axes: axes, optional :

The axes to put the plot. If axes is not specified then the current will be used (in pylab).

Returns :

Returns a tuple with :

line: matplotlib.lines.Line2D :

the mean line

poly: matplotlib.collections.PolyCollection :

shaded 95% confidence area

Table Of Contents

Previous topic

clustering Package

This Page