trieste.models.gpflow.utils#

Module Contents#

assert_data_is_compatible(new_data: trieste.data.Dataset, existing_data: trieste.data.Dataset)None[source]#

Checks that new data is compatible with existing data.

Parameters
  • new_data – New data.

  • existing_data – Existing data.

Raises

ValueError – if trailing dimensions of the query point or observation differ.

randomize_hyperparameters(object: gpflow.Module)None[source]#

Sets hyperparameters to random samples from their constrained domains or (if not constraints are available) their prior distributions.

Parameters

object – Any gpflow Module.

squeeze_hyperparameters(object: gpflow.Module, alpha: float = 0.01, epsilon: float = 1e-07)None[source]#

Squeezes the parameters to be strictly inside their range defined by the Sigmoid, or strictly greater than the limit defined by the Shift+Softplus. This avoids having Inf unconstrained values when the parameters are exactly at the boundary.

Parameters
  • object – Any gpflow Module.

  • alpha – the proportion of the range with which to squeeze for the Sigmoid case

  • epsilon – the value with which to offset the shift for the Softplus case.

Raises

ValueError – If alpha is not in (0,1) or epsilon <= 0

check_optimizer(optimizer: Union[trieste.models.optimizer.BatchOptimizer, trieste.models.optimizer.Optimizer])None[source]#

Check that the optimizer for the GPflow models is using a correct optimizer wrapper.

Stochastic gradient descent based methods implemented in TensorFlow would not work properly without mini-batches and hence BatchOptimizer that prepares mini-batches and calls the optimizer iteratively needs to be used. GPflow’s Scipy optimizer on the other hand should use the non-batch wrapper Optimizer.

Parameters

optimizer – An instance of the optimizer wrapper with the underlying optimizer.

Raises

ValueError – If Optimizer is not using BatchOptimizer or Scipy is using BatchOptimizer.

_covariance_between_points_for_variational_models(kernel: gpflow.kernels.Kernel, inducing_points: trieste.types.TensorType, q_sqrt: trieste.types.TensorType, query_points_1: trieste.types.TensorType, query_points_2: trieste.types.TensorType, whiten: bool)trieste.types.TensorType[source]#

Compute the posterior covariance between sets of query points.

\[\Sigma_{12} = K_{1x}BK_{x2} + K_{12} - K_{1x}K_{xx}^{-1}K_{x2}\]

where \(B = K_{xx}^{-1}(q_{sqrt}q_{sqrt}^T)K_{xx}^{-1}\) or \(B = L^{-1}(q_{sqrt}q_{sqrt}^T)(L^{-1})^T\) if we are using a whitened representation in our variational approximation. Here \(L\) is the Cholesky decomposition of \(K_{xx}\). See [Tit09] for a derivation.

Note that this function can also be applied to our VariationalGaussianProcess models by passing in the training data rather than the locations of the inducing points.

Although query_points_2 must be a rank 2 tensor, query_points_1 can have leading dimensions.

Inducing points

The input locations chosen for our variational approximation.

Q_sqrt

The Cholesky decomposition of the covariance matrix of our variational distribution.

Parameters
  • query_points_1 – Set of query points with shape […, A, D]

  • query_points_2 – Sets of query points with shape [B, D]

  • whiten – If True then use whitened representations.

Returns

Covariance matrix between the sets of query points with shape […, L, A, B] (L being the number of latent GPs = number of output dimensions)

_compute_kernel_blocks(kernel: gpflow.kernels.Kernel, inducing_points: trieste.types.TensorType, query_points_1: trieste.types.TensorType, query_points_2: trieste.types.TensorType, num_latent: int)tuple[trieste.types.TensorType, trieste.types.TensorType, trieste.types.TensorType, trieste.types.TensorType][source]#

Return all the prior covariances required to calculate posterior covariances for each latent Gaussian process, as specified by the num_latent input.

This function returns the covariance between: inducing_points and query_points_1; inducing_points and query_points_2; query_points_1 and query_points_2; inducing_points and inducing_points.

The calculations are performed differently depending on the type of kernel (single output, separate independent multi-output or shared independent multi-output) and inducing variables (simple set, SharedIndependent or SeparateIndependent).

Note that num_latents is only used when we use a single kernel for a multi-output model.

_whiten_points(model: trieste.models.gpflow.interface.GPflowPredictor, inducing_points: trieste.types.TensorType)Tuple[trieste.types.TensorType, trieste.types.TensorType][source]#

GPFlow’s VGP and SVGP can use whitened representation, i.e. q_mu and q_sqrt parametrize q(v), and u = f(X) = L v, where L = cholesky(K(X, X)) Hence we need to back-transform from f_mu and f_cov to obtain the updated new_q_mu and new_q_sqrt.

Parameters

model – The whitened model.

Para inducing_points

The new inducing point locations.

Returns

The updated q_mu and q_sqrt with shapes [N, L] and [L, N, N], respectively.