Distributed GPs

Distribute training and prediction across multiple controllers.

A controller class decorated with the Distributed decorator will make predictions by aggregating the predictions of several independent expert controllers.

Main Decorator

class vanguard.distribute.decorator.Distributed(n_experts=3, subset_fraction=0.1, rng=None, aggregator_class=<class 'vanguard.distribute.aggregators.RBCMAggregator'>, partitioner_class=<class 'vanguard.distribute.partitioners.KMeansPartitioner'>, partitioner_kwargs=None, **kwargs)[source]

Use multiple controller classes to aggregate predictions.

Note

Because of the way expert controllers are created, the output standard deviation must be a float or an integer, and cannot be an array.

Note

Every call to fit() creates a new partition, and regenerates the experts.

Warning

This is a TopMostDecorator.

Example:
>>> @Distributed(n_experts=10, aggregator_class=GRBCMAggregator)
... class DistributedGPController(GPController):
...     pass
Parameters:
Keyword Arguments:
  • For other possible keyword arguments, see the Decorator class.

__init__(n_experts=3, subset_fraction=0.1, rng=None, aggregator_class=<class 'vanguard.distribute.aggregators.RBCMAggregator'>, partitioner_class=<class 'vanguard.distribute.partitioners.KMeansPartitioner'>, partitioner_kwargs=None, **kwargs)[source]

Initialise the Distributed decorator.

Parameters:
property safe_updates: dict[type, set[str]]

Get a dictionary (class -> set[names]) of overrides/new methods that we consider “safe”.

verify_decorated_class(cls)[source]

Verify that a class can be decorated by this instance.

Parameters:

cls (type[GPController]) – The class to be decorated.

Raises:
Return type:

None

Aggregators

A suite of aggregators to be used with the Distributed decorator.

These are responsible for combining the predictions of several independent expert controllers.

exception vanguard.distribute.aggregators.BadPriorVarShapeError[source]
class vanguard.distribute.aggregators.BaseAggregator(means, covars, prior_var=None)[source]

Aggregate experts’ posteriors to an approximate predictive posterior.

All aggregators should inherit from this class.

Parameters:
  • means (list[Tensor]) – List with d elements, each element is an array of a single expert’s predictive mean at the evaluation points.

  • covars (list[Tensor]) – List with d elements, each \(d imes d\) element is the individual experts posterior predictive covariance at the test points.

  • prior_var (Optional[Tensor]) – Tensor with d elements, with each element being the diagonal of the test kernel with added noise.

__init__(means, covars, prior_var=None)[source]

Initialise the BaseAggregator class.

Parameters:
aggregate()[source]

Combine the predictions of the individual experts into a single PoE prediction.

Return type:

tuple[Tensor, Tensor]

Returns:

The mean and variance of the combined experts.

_beta_correction(delta_diff, delta_val)[source]

Implement the correction to experts’ weights.

Note

Delta is the difference in differential entropy between prior and posterior [Deisenroth15]. delta_diff and delta_val are the same in XBCMAggregator.

Parameters:
  • delta_diff (Tensor) – The delta used to determine if correction is applied (proxy for in-vs-out of training data).

  • delta_val (Tensor) – The delta value to be corrected. Must be the same shape as delta_diff.

Return type:

Tensor

Returns:

The corrected expert weights, the same shape as delta_diff.

class vanguard.distribute.aggregators.POEAggregator(means, covars, prior_var=None)[source]

Implements the Product-of-Experts method of [Deisenroth15]. Formulae for covariances from [Cao14].

Given the posteriors of the experts \(p_{i}(y|x) = N(\mu_{i}(x), \sigma_{i}^{2}(x))\) for \(i=1, 2, ..., M\), we define the joint posterior as a Gaussian with moments

\[\begin{split}\mu &= \sigma^{2} \sum_{i} \sigma_{i}^{-2}(x) \mu_{i}(x) \\ \sigma^{-2} &= \sum_{i} \sigma_{i}^{-2}(x)\end{split}\]
Parameters:
aggregate()[source]

Combine the predictions of the individual experts into a single PoE prediction.

Return type:

tuple[Tensor, Tensor]

Returns:

The mean and variance of the combined experts.

class vanguard.distribute.aggregators.EKPOEAggregator(means, covars, prior_var=None)[source]

Implements a correction to the Product-of-Experts method.

Given the posteriors of the experts \(p_{i}(y|x) = N(\mu_{i}(x), \sigma_{i}^{2}(x))\) for \(i=1, 2, ..., M\), we define the joint posterior as a Gaussian with moments

\[\begin{split}\mu &= M \sigma^{2} \sum_{i} \sigma_{i}^{-2}(x) \mu_{i}(x) \\ \sigma^{-2} &= \frac{1}{M} \sum_{i} \sigma_{i}^{-2}(x)\end{split}\]
Parameters:
aggregate()[source]

Combine the predictions of the individual experts into a single PoE prediction.

Return type:

tuple[Tensor, Tensor]

Returns:

The mean and variance of the combined experts.

class vanguard.distribute.aggregators.GPOEAggregator(means, covars, prior_var=None)[source]

Implements the Generalised Product-of-Experts method of [Deisenroth15].

Given the posteriors of the experts \(p_{i}(y|x) = N(\mu_{i}(x), \sigma_{i}^{2}(x))\) for \(i=1, 2, ..., M\), we define the joint posterior as a Gaussian with moments

\[\begin{split}\mu &= \sigma^{2} \sum_{i} \beta_{i} \sigma_{i}^{-2}(x) \mu_{i}(x) \\ \sigma^{-2} &= \sum_{i} \beta_{i} \sigma_{i}^{-2}(x)\end{split}\]

where \(\beta_{i}=\frac{1}{M}\).

Parameters:
aggregate()[source]

Combine the predictions of the individual experts into a single PoE prediction.

Return type:

tuple[Tensor, Tensor]

Returns:

The mean and variance of the combined experts.

class vanguard.distribute.aggregators.BCMAggregator(means, covars, prior_var=None)[source]

Implements the Bayesian Committee Machine method of [Deisenroth15].

Given the posteriors of the experts \(p_{i}(y|x) = N(\mu_{i}(x), \sigma_{i}^{2}(x))\) for \(i=1, 2, ..., M\), we define the joint posterior as a Gaussian with moments

\[\begin{split}\mu &= \sigma^{2} \sum_{i} \sigma_{i}^{-2}(x) \mu_{i}(x) \\ \sigma^{-2} &= \sum_{i} \sigma_{i}^{-2}(x) + \bigg( 1 - M \bigg) \sigma_{**}^{-2}\end{split}\]

where \(\sigma_{**}^{-2}\) is the diagonal of the covariance matrix formed by applying the kernel on all pairs of points in \(x\).

Parameters:
aggregate()[source]

Combine the predictions of the individual experts into a single BCM prediction.

Return type:

tuple[Tensor, Tensor]

Returns:

The mean and variance of the combined experts.

class vanguard.distribute.aggregators.RBCMAggregator(means, covars, prior_var=None)[source]

Implements the Robust Bayesian Committee Machine method of [Deisenroth15].

Given the posteriors of the experts \(p_{i}(y|x) = N(\mu_{i}(x), \sigma_{i}^{2}(x))\) for \(i=1, 2, ..., M\), we define the joint posterior as a Gaussian with moments

\[\begin{split}\mu &= \sigma^{2} \sum_{i} \sigma_{i}^{-2}(x) \mu_{i}(x) \\ \sigma^{-2} &= \sum_{i} \sigma_{i}^{-2}(x) + \bigg( 1 - \sum_{i} \beta_{i} \bigg) \sigma_{**}^{-2}\end{split}\]

where \(\beta_{i}=0.5(\log \sigma_{*}^{2} - \log \sigma_{i}^{2}(x))\) is the difference between the prior and the posterior, and \(\sigma_{**}^{-2}\) is the diagonal of the covariance matrix formed by applying the kernel on all pairs of points in \(x\).

Parameters:
aggregate()[source]

Combine the predictions of the individual experts into a single RBCM prediction.

Return type:

tuple[Tensor, Tensor]

Returns:

The mean and variance of the combined experts.

class vanguard.distribute.aggregators.XBCMAggregator(means, covars, prior_var=None)[source]

Implements the Corrected Bayesian Committee Machine method.

We define the joint posterior as in RBCMAggregator, but with a correction on beta. (For further details see BaseAggregator._beta_correction().)

Parameters:
aggregate()[source]

Combine the predictions of the individual experts into a single XBCM prediction.

Return type:

tuple[Tensor, Tensor]

Returns:

The mean and variance of the combined experts.

class vanguard.distribute.aggregators.GRBCMAggregator(means, covars, prior_var=None)[source]

Implements the Generalised Robust Bayesian Committee Machine method of [Liu18].

Given the posteriors of the experts \(p_{i}(y|x) = N(\mu_{i}(x), \sigma_{i}^{2}(x))\) for \(i=1, 2, ..., M\), we define the joint posterior as a Gaussian with moments

\[\begin{split}\mu &= \sigma^{2} \bigg[ \sum_{i=2}^{M} \beta_{i} \sigma_{i}^{-2}(x) \mu_{i}(x) + \bigg( 1 - \sum_{i=2}^{M} \beta_{i} \bigg) \sigma_{1}^{-2}(x) \mu_{1}(x) \bigg] \\ \sigma^{-2} &= \sum_{i=2}^{M} \beta_{i} \sigma_{i}^{-2}(x) + \bigg( 1 - \sum_{i=2}^{M} \beta_{i} \bigg) \sigma_{1}^{-2}(x)\end{split}\]

where

\[\begin{split}\beta_{i} = \begin{cases} 1, & i=2 \\ 0.5(\log \sigma_{1}^{2}(x) - \log \sigma_{i}^{2}(x)), & 3 \leq i \leq M \end{cases}\end{split}\]
Parameters:
aggregate()[source]

Combine the predictions of the individual experts into a single GRBCM prediction.

Return type:

tuple[Tensor, Tensor]

Returns:

The mean and variance of the combined experts.

class vanguard.distribute.aggregators.XGRBCMAggregator(means, covars, prior_var=None)[source]

Implements the Corrected Generalised Robust Bayesian Committee Machine method.

We define the joint posterior as in RBCMAggregator, but with a correction on beta. (For further details see BaseAggregator._beta_correction().)

Parameters:
aggregate()[source]

Combine the predictions of the individual experts into a single XGRBCM prediction.

Return type:

tuple[Tensor, Tensor]

Returns:

The mean and variance of the combined experts.

Partitioners

Partitioners are responsible for separating the training data into subsets to be assigned to each expert controller.

class vanguard.distribute.partitioners.BasePartitioner(train_x, n_experts=3, communication=False, rng=None)[source]

Generate a partition over index space using various methods. All partitioners should inherit from this class.

Parameters:
__init__(train_x, n_experts=3, communication=False, rng=None)[source]

Initialise the BasePartitioner class.

Parameters:
create_partition()[source]

Create a partition of self.train_x across self.n_experts.

Return type:

list[list[int]]

Returns:

A partition of length self.n_experts.

plot_partition(partition, cmap='Set3', **plot_kwargs)[source]

Plot a partition on a T-SNE graph.

Parameters:
Return type:

None

class vanguard.distribute.partitioners.RandomPartitioner(train_x, n_experts=3, communication=False, rng=None)[source]

Create a partition using random sampling.

Parameters:
class vanguard.distribute.partitioners.KMeansPartitioner(train_x, n_experts=3, communication=False, rng=None)[source]

Create a partition using K-Means.

Parameters:
class vanguard.distribute.partitioners.MiniBatchKMeansPartitioner(train_x, n_experts=3, communication=False, rng=None)[source]

Create a partition using Mini-batch K-Means.

Parameters:
class vanguard.distribute.partitioners.KMedoidsPartitioner(train_x, n_experts=2, communication=False, rng=None, *, kernel)[source]

Create a partition using KMedoids with similarity defined by the kernel.

Parameters:
  • train_x (Union[Tensor, ndarray[tuple[Any, ...], dtype[floating]]]) – The mean of the inputs.

  • n_experts (int) – The number of partitions in which to split the data. Defaults to 2.

  • communication (bool) – If True, A communications expert will be included. Defaults to False.

  • rng (Optional[Generator]) – Generator instance used to generate random numbers.

  • kernel (Kernel) – The kernel to use for constructing the similarity matrix in KMedoids.

Seealso:

Clusters are computed using a kmedoids.KMedoids object.

__init__(train_x, n_experts=2, communication=False, rng=None, *, kernel)[source]

Initialise the KMedoidsPartitioner class.

Parameters: