# gp Package¶

## feature_kernel Module¶

class infpy.gp.feature_kernel.AttributeExtractor(attribute_name, sub_kernel)[source]

Bases: infpy.gp.kernel.Kernel

Changes the type of object a kernel can act on

For example our data might be of type X that aggregate several features:

X.vec: a numpy.array X.is_true: a boolean

We may have a kernel, Kvec, that acts on arrays and a kernel, Kbool, that acts on boolean data. We could combine them as follows:

K = SumKernel(
AttributeExtractor( 'vec', Kvec ),
AttributeExtractor( 'is_true', Kbool )
)


The AttributeExtractor will find the vec and is_true attributes of each x and pass them to the kernels Kvec and Kbool

class Derivative(k, i)[source]

Bases: object

## gaussian_process Module¶

class infpy.gp.gaussian_process.GP_LL_deriv_fn(gp, needs_to_set_params)[source]

Bases: object

$$\frac{d\textrm{LL}}{d\textrm{params}}$$ as function of kernel parameters

Relies on the parameters already having been set. I.e. __call__ ignores its arguments!

class infpy.gp.gaussian_process.GP_LL_fn(gp)[source]

Bases: object

GP LL as function of kernel parameters

class infpy.gp.gaussian_process.GaussianProcess(X, y, k)[source]

Bases: object

A Gaussian process.

Following notation in section 2.2 of Gaussian Processes for Machine Learning by Rasmussen and Williams.

calc_covariance(x1, x2=None)[source]

Calculate covariance matrix of x1 against x2

if x2 is None calculate symmetric matrix

calc_covariance_derivative(i, x1, x2=None)[source]

Calculate derivative of covariance matrix of x1 against x2 w.r.t param i

if x2 is None calculate symmetric matrix

predict(x_star)[source]

Predict the process’s values on the input values

@arg x_star: Prediction points

@return: ( mean, variance, LL ) where mean are the predicted means, variance are the predicted variances and LL is the log likelihood of the data for the given value of the parameters (i.e. not integrating over hyperparameters)

reestimate(X, y)[source]

Reestimate process given the data

set_params(params)[source]

Set the parameters of the covariance function.

infpy.gp.gaussian_process.gp_1D_X_range(xmin, xmax, step=1.0)[source]

@return: An array of points between xmin and xmax with the given step size. The shape of the array will be (N, 1) where N is the number of points as this is the format the GP code expects.

Implementation uses numpy.arange so last element of array may be > xmax.

infpy.gp.gaussian_process.gp_1D_predict(gp, num_steps=100, x_min=None, x_max=None, new_figure=True, show_y=True, show_variance=True)[source]

Predict and plot the GP’s predictions over the range provided

infpy.gp.gaussian_process.gp_learn_hyperparameters(gp, initial_guess=None, *args, **kwds)[source]

Run optimisation algorithm on GP’s kernel parameters

infpy.gp.gaussian_process.gp_loo_predict(k, X, y)[source]

Calls gp_loo_predict_i for all i and yields the return value

infpy.gp.gaussian_process.gp_loo_predict_i(k, X, y, i)[source]

Creates a gp from all x in X except the i’th and predicts its value...

Args:
k: the kernel for the gp X: the data y: the outputs i: the index to leave out
Returns:
( predicted, variance, error ) predicted: the i’th data point’s predicted value variance: uncertainty in prediction error: absolute error
infpy.gp.gaussian_process.gp_plot_prediction(predict_x, mean, variance=None)[source]

Plot a gp’s prediction using pylab including error bars if variance specified

Error bars are 2 * standard_deviation as in Gaussian Processes for Machine Learning by Rasmussen and Williams.

infpy.gp.gaussian_process.gp_plot_samples_from(gp, support, num_samples=1)[source]

Plot samples from a Gaussian process.

infpy.gp.gaussian_process.gp_sample_at(gp, x)[source]

Samples from a gaussian process

x is the value to sample at

infpy.gp.gaussian_process.gp_sample_from(gp, support)[source]

Samples from a gaussian process, gp

support: sequence of X values to sample at

returns values at support points

infpy.gp.gaussian_process.gp_title_and_show(gp)[source]

Add title and show using pylab

infpy.gp.gaussian_process.gp_zero_mean(y)[source]

Return the data shifted to make the mean zero

infpy.gp.gaussian_process.loo(z, i)[source]

Returns sequence with i’th missing

infpy.gp.gaussian_process.loo_gen(z, i)[source]

Leave one out generator (leaves i’th out)

## gp_examples Module¶

infpy.gp.gp_examples.gp_ex_fig_22()[source]

Similar to figure 2.2 in Gaussian Processes for Machine Learning by Rasmussen and Williams.

infpy.gp.gp_examples.gp_ex_fixed_period()[source]

Example of the fixed period kernel

infpy.gp.gp_examples.gp_ex_fixed_period_1()[source]

Example of the fixed period kernel

infpy.gp.gp_examples.gp_ex_output_scale()[source]

Examine how kernel parameters should change for scaled outputs

## kernel Module¶

class infpy.gp.kernel.ConstantKernel(constant=1.0, prior=<infpy.distribution.GammaDistribution object at 0x4e708d0>)[source]

Bases: infpy.gp.kernel.Kernel

A constant kernel.

class Derivative(k, i)[source]

Bases: object

class infpy.gp.kernel.ConstantSquaredKernel(constant=1.0, prior=<infpy.distribution.LogNormalDistribution object at 0x4e70a10>)[source]

Bases: infpy.gp.kernel.Kernel

class Derivative(k, i)[source]

Bases: object

class infpy.gp.kernel.EqualityKernel[source]

Bases: infpy.gp.kernel.Kernel

1 if x1 and x2 are equal, 0 otherwise

class infpy.gp.kernel.IdenticalKernel[source]

Bases: infpy.gp.kernel.Kernel

1 if x1 and x2 are identical, 0 otherwise

class infpy.gp.kernel.Kernel(params, param_priors)[source]

Bases: object

Base class for all Gaussian process kernels

derivative_wrt_param(i)[source]

Returns the derivative of the kernel with respect to the i’th parameter.

set_params(new_params)[source]

Set the parameters of the kernel

supports(p)[source]

True if all the parameters, p, are in the support of the kernel’s priors

class infpy.gp.kernel.KernelParameterFixer(hidden_k)[source]

Bases: infpy.gp.kernel.Kernel

A wrapper kernel that hides (i.e. fixes) the parameters of another kernel

To users of this class it appears as the kernel has no parameters to optimise. This can be useful when you have a mixture kernel and you only want to learn one child kernel’s parameters.

infpy.gp.kernel.kernel_init_args_helper(params=None, priors=None, dimensions=None, num_extra_params=0)[source]

A helper function to allow user to only specify some of the priors, parameters and dimensions arguments.

Parameters: params – the parameters priors – the priors over the parameters dimensions – the number of dimensions of the input values num_extra_params – the number of extra parameters (over and above one per dimension)

This function fills any unspecified arguments in with defaults.

It returns (params, priors, dimensions)

infpy.gp.kernel.noise_kernel(sigma=1.0, sigma_prior=<infpy.distribution.LogNormalDistribution object at 0x4e70c10>)[source]

## matern_kernel Module¶

class infpy.gp.matern_kernel.Matern32Kernel(params=None, priors=None, dimensions=None)[source]

Eq 4.17 in Gaussian Processes for Machine Learning by Rasmussen and Williams.

class Derivative(k, i)[source]

Bases: object

class infpy.gp.matern_kernel.Matern52Kernel(params=None, priors=None, dimensions=None)[source]

Eq 4.17 in Gaussian Processes for Machine Learning by Rasmussen and Williams.

class Derivative(k, i)[source]

Bases: object

## neural_network_kernel Module¶

class infpy.gp.neural_network_kernel.NeuralNetworkKernel(sigma)[source]

Following 4.29 in Gaussian Processes for Machine Learning by Rasmussen and Williams.

No trainable paramaters

## periodic_kernel Module¶

class infpy.gp.periodic_kernel.FixedPeriod1DKernel(fixed_period, length=1.0, prior=<infpy.distribution.LogNormalDistribution object at 0x4e7ffd0>)[source]

See 4.31 in Gaussian Processes for Machine Learning by Rasmussen and Williams.

$k(x_1, x_2) = e^\frac{-2 \sin^2( \pi (x_1 - x_2) )}{p^2}$

Could be generalised to more than one dimension or for parameterisable periods

class Derivative(k, i)[source]

Bases: object

FixedPeriod1DKernel.d(x1, x2)[source]

## piecewise_poly_kernel Module¶

class infpy.gp.piecewise_poly_kernel.PiecewisePoly0Kernel(params=None, priors=None, dimensions=None)[source]

Eq 4.21 in Gaussian Processes for Machine Learning by Rasmussen and Williams.

q=0

class Derivative(k, i)[source]

Bases: object

class infpy.gp.piecewise_poly_kernel.PiecewisePoly1Kernel(params=None, priors=None, dimensions=None)[source]

Eq 4.21 in Gaussian Processes for Machine Learning by Rasmussen and Williams.

q=1

class Derivative(k, i)[source]

Bases: object

class infpy.gp.piecewise_poly_kernel.PiecewisePolyKernel(q, params=None, priors=None, dimensions=None)[source]

Eq 4.21 in Gaussian Processes for Machine Learning by Rasmussen and Williams.

Base class for specialisations for specific values of q

Will produce a sparse covariance matrix with 0’s where r > 1

## pre_calculated_kernel Module¶

class infpy.gp.pre_calculated_kernel.PreCalculatedKernel(objects, matrix)[source]

Bases: infpy.gp.kernel.Kernel

A kernel that has been pre-computed

Following 4.19 in Gaussian Processes for Machine Learning by Rasmussen and Williams.

$k = (1 + \frac{r^2}{2\alpha})^{-\alpha}$

Alpha is not a trainable parameter. The parameters are for the length scale in the r term.

class Derivative(k, i)[source]

Bases: object

Following 4.19 in Gaussian Processes for Machine Learning by Rasmussen and Williams.

$k = (1 + \frac{r^2}{2\alpha})^{-\alpha}$

The first parameter is alpha. The rest of the parameters are for the length scale in the r term.

class Derivative(k, i)[source]

Bases: object

## real_kernel Module¶

class infpy.gp.real_kernel.RealKernel(params, param_priors, dimensions)[source]

Bases: infpy.gp.kernel.Kernel

A kernel that is defined on $$\mathbb{R}^n$$

infpy.gp.real_kernel.distance(x1, x2, params)[source]

Calculates distance between two points in $$\mathbb{R}^n$$

infpy.gp.real_kernel.distance_2(x1, x2, params)[source]

Calculates distance squared between two points in $$\mathbb{R}^n$$

$r(x_1,x_2) = |\frac{x_1 - x_2}{l}|^2$

where the parameters $$l$$ are the length scales.

infpy.gp.real_kernel.distance_2_derivative(x1, x2, params, i)[source]

Calculates derivative of distance squared between two points w.r.t. param i

infpy.gp.real_kernel.distance_derivative(x1, x2, params, i)[source]

Calculates derivative of distance between two points w.r.t. param i

## se_kernel Module¶

class infpy.gp.se_kernel.ModulatedSquaredExponentialKernel(sigma_g=1.0, sigma_u=1.0)[source]

Eq. 4.30 in Gaussian Processes for Machine Learning by Rasmussen and Williams.

No trainable parameters

class infpy.gp.se_kernel.SquaredExponentialKernel(params=None, priors=None, dimensions=None)[source]

A squared exponential kernel

$k(x_1, x_2) = k(r(x_1, x_2)) = \textrm{exp}\big(-\frac{r^2}{2}\big)$

where $$r(x_1, x_2) = |\frac{x_1 - x_2}{l}|$$

class Derivative(k, i)[source]

Bases: object

## sum_kernel Module¶

class infpy.gp.sum_kernel.IndexMixer(o1, o2)[source]

Bases: object

Mixes two indexable objects to provide one seamlessly indexable object

That is len(IndexMixer(x1,x2))=len(x1)+len(x2)

class Iter(mixer)[source]

Bases: object

next()[source]
class infpy.gp.sum_kernel.MixKernel(k1, k2)[source]

Bases: infpy.gp.kernel.Kernel

Kernel that mixes two other kernels. E.g. used as sub-class for SumKernel

class infpy.gp.sum_kernel.ProductKernel(k1, k2)[source]

The product of 2 other kernels

derivative_wrt_param(index)[source]
class infpy.gp.sum_kernel.SumKernel(k1, k2)[source]

The sum of 2 other kernels

derivative_wrt_param(index)[source]