twodlearn.bayesnet.gaussian_process module

class twodlearn.bayesnet.gaussian_process.BasisBase(**kargs)[source]

Bases: twodlearn.core.common.TdlModel

class Basis(value)[source]

Bases: object

matmul(mat)[source]

Evaluate basis over the given matrix.

matvec(vec)[source]

Evaluate basis over the given vectors.

basis_fn(inputs)[source]
basis_shape[source]
input_shape[source]
kernel[source]
prior[source]
tolerance[source]
units[source]
class twodlearn.bayesnet.gaussian_process.ExplicitVGP(**kargs)[source]

Bases: twodlearn.core.common.TdlModel

class EVGPInference(**kargs)[source]

Bases: twodlearn.core.common.TdlModel

property basis[source]
basis_m[source]
basis_x[source]
cov_residuals[source]
expected_residuals[source]

Kxm @ inv(Kmm) @ fm.loc

property fm[source]
inputs[source]
property kernel[source]
kmm[source]
kmx[source]
model[source]

ExplicitVGP model

property xm[source]
y_scale[source]

linear operation for y_scale

class EVGPPrediction(**kargs)[source]

Bases: twodlearn.bayesnet.gaussian_process.EVGPInference, twodlearn.bayesnet.distributions.MVN

covariance[source]
loc[source]
neg_elbo(labels, dataset_size=None)[source]
with_noise()[source]

return the posterior with noise

class VariationalLoss(**kargs)[source]

Bases: twodlearn.core.common.TdlModel

batch_size[source]
dataset_size[source]

number of samples in the entire dataset

elbo[source]
property inputs[source]
labels[source]
property model[source]
posterior[source]
value[source]

negative variational lower bound

basis[source]
batch_shape[source]

Number of output dimensions.

fm[source]

Inducing points for the model.

input_shape[source]
kernel[source]

Autoinit with arguments [‘l_scale’, ‘f_scale’]

m[source]

number of inducing points

neg_elbo(inputs, labels, dataset_size=None)[source]
predict(inputs, tolerance=None)[source]
tolerance[source]
xm[source]

inducing input points for the model

y_scale[source]

Measurement scale y sim N(g, y_scale**2 I)

class twodlearn.bayesnet.gaussian_process.GPNegLogEvidence(cov, cov_inv=None, labels=None, loc=None, name=None)[source]

Bases: twodlearn.losses.EmpiricalLoss

Negative log evidence for a Gaussian Process with training covariance cov = K(train, train).

The loss takes the following form

loss = 0.5(y^T inv(cov) y + log(|cov|) + n log(2 pi))

if conv_inv can be provided when instiating the loss to prevent computing the inverse multiple times

define_fit_loss(cov, cov_inv, labels, loc)[source]
labels[source]
class twodlearn.bayesnet.gaussian_process.GaussianProcess(xm, ym, y_scale=0.1, kernel=None, options=None, name=None, **kargs)[source]

Bases: twodlearn.core.common.TdlModel

Gaussian process with zero mean.

The covariance kernel takes by default the following form

# X1 is a matrix, whose rows represent samples
# X2 is a matrix, whose rows represent samples
K(i,j) = (f_scale**2) exp(-0.5 (x1(i)-x2(j))^T (l**-2)I (x1(i)-x2(j)) )

By default, when float values of l_scale, f_scale and y_scale are provided, a trainable variable is created. If want them fixed, you can provide a kernel with parameters as tf.Variable(value, trainable=False)

class GPPosterior(**kargs)[source]

Bases: twodlearn.bayesnet.gaussian_process.GpOutput, twodlearn.bayesnet.distributions.MVN

Compute the posterior distribution for p(f*| x*, ym, Xm) where {ym, Xm} is the training dataset of the GP model.

covariance[source]
loc[source]
with_noise()[source]

return the posterior with noise

class GpOutput(**kargs)[source]

Bases: twodlearn.core.common.OutputModel

inputs[source]
k11[source]
k12[source]
k22[source]
model[source]

GP model

property xm[source]
y_scale[source]
property ym[source]
kernel[source]
m[source]
marginal_likelihood(*args, **kargs)[source]
predict(inputs)[source]

Compute the posterior distribution for p(f*| x*, y, X) where {y, X} is the training dataset of the GP model. :param inputs: matrix with test inputs x*. :type inputs: tf.Tensor, TdlModel

Returns

TdlModel with the value of p(f*| x*, y, X).

loc: mean for f* scale: scale for f* posterior: distributions for y* and f*

Return type

GpOutput

tolerance[source]
xm[source]
y_scale[source]

y sim N(f, y_scale**2 I)

Type

Measurement scale

ym[source]
class twodlearn.bayesnet.gaussian_process.GpWithExplicitMean(gp_model, prior_scale=None, explicit_basis=None, **kargs)[source]

Bases: twodlearn.core.common.TdlModel

class EGPPosterior(**kargs)[source]

Bases: twodlearn.bayesnet.gaussian_process.EGpOutput, twodlearn.bayesnet.distributions.MVN

covariance[source]
loc[source]
class EGpOutput(**kargs)[source]

Bases: twodlearn.core.common.TdlModel

basis[source]
beta_mean[source]
beta_r[source]
property gp_model[source]
gp_output[source]
ht_k11inv_h[source]
inputs[source]
property k11[source]
property k12[source]
model[source]
property tolerance[source]
class MarginalOutput(**kargs)[source]

Bases: twodlearn.core.common.OutputModel

A[source]
basis[source]
gp_marginal[source]
property gp_model[source]
k11[source]
property prior_scale[source]
yCy[source]
explicit_basis[source]
gp_model[source]
marginal_likelihood(*args, **kargs)[source]
predict(inputs)[source]

Compute the posterior distribution for p(f*| x*, y, X) where {y, X} is the training dataset of the GP model. :param inputs: matrix with test inputs x*. :type inputs: tf.Tensor, TdlModel

Returns

TdlModel with the value of p(f*| x*, y, X).

loc: mean for f* scale: scale for f*

Return type

GpOutput

prior_scale[source]

scale of the prior

class twodlearn.bayesnet.gaussian_process.VariationalGP(m=None, input_shape=None, name=None, **kargs)[source]

Bases: twodlearn.core.common.TdlModel

class VGPElbo(**kargs)[source]

Bases: twodlearn.core.common.TdlModel

batch_size[source]
dataset_size[source]

number of samples in the entire dataset

elbo[source]
property fm[source]
fm_kl[source]
fm_prior[source]
property inputs[source]
property kernel[source]
property kmm[source]
property kmx[source]
labels[source]

output samples

loss[source]
property model[source]
posterior[source]
shape[source]
value[source]
property xm[source]
property y_scale[source]
class VGPEstimate(**kargs)[source]

Bases: twodlearn.bayesnet.gaussian_process.VGPInference, twodlearn.bayesnet.distributions.MVN

covariance[source]
loc[source]
neg_elbo(labels, dataset_size)[source]
with_noise()[source]

return the posterior with noise ~ Normal(0, Sigma_y)

class VGPInference(**kargs)[source]

Bases: twodlearn.core.common.TdlModel

property fm[source]
inputs[source]
property kernel[source]
kmm[source]
kmx[source]
property mean_fn[source]
model[source]
property xm[source]
y_scale[source]
batch_shape[source]

number of batched distributions

fm[source]

variational parameters for the GP model

input_shape[source]
kernel[source]

Autoinit with arguments [‘l_scale’, ‘f_scale’]

m[source]

number of inducing points

mean_fn[source]

Mean function of the gaussian prior.

neg_elbo(labels, inputs, dataset_size)[source]
predict(inputs, tolerance=None)[source]
tolerance[source]
xm[source]

inducing input points for the model

y_scale[source]