Gaussian process object

class gp.gp.GP(K, x, y, s=0)[source]

Bases: object

Gaussian Process object.

Parameters :

K : Kernel

Kernel object

x : numpy.ndarray

\(n\) array of input locations

y : numpy.ndarray

\(n\) array of input observations

s : number (default=0)

Standard deviation of observation noise

K = None

Kernel for the gaussian process, of type Kernel

Kxox(xo)[source]

Kernel covariance matrix between new sample locations and given locations.

Parameters :

xo : numpy.ndarray

\(m\) array of new sample locations

Returns :

Kxox : numpy.ndarray

\(m\times n\) covariance matrix

Notes

This is defined as \(K(\mathbf{x^*},\mathbf{x})\), where \(\mathbf{x^*}\) are the new sample locations and \(\mathbf{x}\) are the given locations

Kxoxo(xo)[source]

Kernel covariance matrix of new sample locations.

Parameters :

xo : numpy.ndarray

\(m\) array of new sample locations

Returns :

Kxoxo : numpy.ndarray

\(m\times m\) covariance matrix

Notes

This is defined as \(K(\mathbf{x^*}, \mathbf{x^*})\), where \(\mathbf{x^*}\) are the new locations.

Kxx[source]

Kernel covariance matrix \(\mathbf{K}_{xx}\).

Returns :

Kxx : numpy.ndarray

\(n\times n\) covariance matrix

Notes

The entry at index \((i, j)\) is defined as:

\[K_{x_ix_j} = K(x_i, x_j) + s^2\delta(x_i-x_j),\]

where \(K(\cdot{})\) is the kernel function, \(s\) is the standard deviation of the observation noise, and \(\delta\) is the Dirac delta function.

Kxx_H[source]
Kxx_J[source]
Kxxo(xo)[source]

Kernel covariance matrix between given locations and new sample locations.

Parameters :

xo : numpy.ndarray

\(m\) array of new sample locations

Returns :

Kxxo : numpy.ndarray

\(n\times m\) covariance matrix

Notes

This is defined as \(K(\mathbf{x},\mathbf{x^*})\), where \(\mathbf{x}\) are the given locations and \(\mathbf{x^*}\) are the new sample locations.

Lxx[source]

Cholesky decomposition of the kernel covariance matrix.

Returns :

Lxx : numpy.ndarray

\(n\times n\) lower triangular matrix

Notes

The value is \(\mathbf{L}_{xx}\), such that \(\mathbf{K}_{xx} = \mathbf{L}_{xx}\mathbf{L}_{xx}^\top\).

copy(deep=True)[source]

Create a copy of the gaussian process object.

Parameters :

deep : bool (default=True)

Whether to return a deep or shallow copy

Returns :

gp : GP

New gaussian process object

cov(xo)[source]

Predictive covariance of the gaussian process.

Parameters :

xo : numpy.ndarray

\(m\) array of new sample locations

Returns :

cov : numpy.ndarray

\(m\times m\) array of predictive covariances

Notes

This is defined by Eq. 2.24 of [RW06]:

\[\mathbf{C}=K(\mathbf{x^*}, \mathbf{x^*}) - K(\mathbf{x^*}, \mathbf{x})\mathbf{K}_{xx}^{-1}K(\mathbf{x}, \mathbf{x^*})\]
d2lh_dtheta2[source]

Second derivative of the marginal likelihood.

Returns :

d2lh_dtheta2 : numpy.ndarray

\(n_\theta\)-length vector of derivatives, where \(n_\theta\) is the number of parameters (equivalent to len(self.params)).

Notes

This is a matrix of second partial derivatives of the likelihood with respect to its parameters \(\theta\).

dlh_dtheta[source]

Derivative of the marginal likelihood.

Returns :

dlh_dtheta : numpy.ndarray

\(n_\theta\)-length vector of derivatives, where \(n_\theta\) is the number of parameters (equivalent to len(self.params)).

Notes

This is a vector of first partial derivatives of the likelihood with respect to its parameters \(\theta\).

dloglh_dtheta[source]

Derivative of the marginal log likelihood.

Returns :

dloglh_dtheta : numpy.ndarray

\(n_\theta\)-length vector of derivatives, where \(n_\theta\) is the number of parameters (equivalent to len(self.params)).

Notes

This is a vector of first partial derivatives of the log likelihood with respect to its parameters \(\theta\). It is defined by Equation 5.9 of [RW06]:

\[\frac{\partial}{\partial\theta_i}\log{p(\mathbf{y}|\mathbf{x},\theta)}=\frac{1}{2}\mathbf{y}^\top\mathbf{K}_{xx}^{-1}\frac{\partial\mathbf{K}_{xx}}{\partial\theta_i}\mathbf{K}_{xx}^{-1}\mathbf{y}-\frac{1}{2}\mathbf{tr}\left(\mathbf{K}_{xx}^{-1}\frac{\partial\mathbf{K}_{xx}}{\partial\theta_i}\right)\]
dm_dtheta(xo)[source]

Derivative of the mean of the gaussian process with respect to its parameters, and evaluated at xo.

Parameters :

xo : numpy.ndarray

\(m\) array of new sample locations

Returns :

dm_dtheta : numpy.ndarray

\(n_p\times m\) array, where \(n_p\) is the number of parameters (see params).

Notes

The analytic form is:

\[\frac{\partial}{\partial \theta_i}m(\mathbf{x^*})=\frac{\partial K(\mathbf{x^*}, \mathbf{x})}{\partial \theta_i}\mathbf{K}_{xx}^{-1}\mathbf{y} - K(\mathbf{x^*}, \mathbf{x})\mathbf{K}_{xx}^{-1}\frac{\partial \mathbf{K}_{xx}}{\partial \theta_i}\mathbf{K}_{xx}^{-1}\mathbf{y}\]
get_param(name)[source]
inv_Kxx[source]

Inverse kernel covariance matrix, \(\mathbf{K}_{xx}^{-1}\).

Note that this inverse is provided mostly just for reference. If you actually need to use it, use the Cholesky decomposition (self.Lxx) instead.

Returns :

inv_Kxx : numpy.ndarray

\(n\times n\) matrix

inv_Kxx_y[source]

Dot product of the inverse kernel covariance matrix and of observation vector.

This uses scipy’s cholesky solver to compute the solution.

Returns :

inv_Kxx_y : numpy.ndarray

\(n\) array

Notes

This is defined as \(\mathbf{K}_{xx}^{-1}\mathbf{y}\).

lh[source]

Marginal likelihood.

Returns :

lh : numpy.float64

Marginal likelihood

Notes

This is the likelihood of observations \(\mathbf{y}\) given locations \(\mathbf{x}\) and kernel parameters \(\theta\). It is defined as:

\[p(\mathbf{y} | \mathbf{x}, \mathbf{\theta}) = \left(2\pi\right)^{-\frac{d}{2}}\left|\mathbf{K}_{xx}\right|^{-\frac{1}{2}}\exp\left(-\frac{1}{2}\mathbf{y}^\top\mathbf{K}_{xx}^{-1}\mathbf{y}\right)\]

where \(d\) is the dimensionality of \(\mathbf{x}\).

log_lh[source]

Marginal log likelihood.

Returns :

log_lh : numpy.float64

Marginal log likelihood

Notes

This is the log likelihood of observations \(\mathbf{y}\) given locations \(\mathbf{x}\) and kernel parameters \(\theta\). It is defined by Eq. 5.8 of [RW06]:

\[\log{p(\mathbf{y} | \mathbf{x}, \mathbf{\theta})} = -\frac{1}{2}\mathbf{y}^\top \mathbf{K}_{xx}^{-1}\mathbf{y} - \frac{1}{2}\log{\left|\mathbf{K}_{xx}\right|}-\frac{d}{2}\log{2\pi},\]

where \(d\) is the dimensionality of \(\mathbf{x}\).

mean(xo)[source]

Predictive mean of the gaussian process.

Parameters :

xo : numpy.ndarray

\(m\) array of new sample locations

Returns :

mean : numpy.ndarray

\(m\) array of predictive means

Notes

This is defined by Equation 2.23 of [RW06]:

\[\mathbf{m}(\mathbf{x^*})=K(\mathbf{x^*}, \mathbf{x})\mathbf{K}_{xx}^{-1}\mathbf{y}\]
params[source]

Gaussian process parameters.

Returns :

params : numpy.ndarray

Consists of the kernel’s parameters, self.K.params, and the observation noise parameter, \(s\), in that order.

plot(ax=None, xlim=None, color='k', markercolor='r')[source]

Plot the predictive mean and variance of the gaussian process.

Parameters :

ax : matplotlib.pyplot.axes.Axes (optional)

The axes on which to draw the graph. Defaults to plt.gca() if not given.

xlim : (lower x limit, upper x limit) (optional)

The limits of the x-axis. Defaults to the minimum and maximum of x if not given.

color : str (optional)

The line color to use. The default is ‘k’ (black).

markercolor : str (optional)

The marker color to use. The default is ‘r’ (red).

s[source]

Standard deviation of the observation noise for the gaussian process.

Returns :s : numpy.float64
set_param(name, val)[source]
x[source]

Vector of input locations.

Returns :

x : numpy.ndarray

\(n\) array, where \(n\) is the number of locations.

y[source]

Vector of input observations.

Returns :

y : numpy.ndarray

\(n\) array, where \(n\) is the number of observations.

Previous topic

Gaussian Processes

Next topic

Kernels

This Page