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:
n_experts (
int) – The number of partitions in which to split the data. Defaults to 3.subset_fraction (
float) – The proportion of the training data to be used to train the hyperparameters. Defaults to 0.1.rng (
Optional[Generator]) – Generator instance used to generate random numbers.aggregator_class (
type[BaseAggregator]) – The class to be used for aggregation. Defaults toRBCMAggregator.partitioner_class (
type[BasePartitioner]) – The class to be used for partitioning. Defaults toKMeansPartitioner. Seevanguard.distribute.partitionersfor alternative partitioners.partitioner_kwargs (
Optional[dict[str,Any]]) – Additional parameters passed to the partitioner initialisation.kwargs (
Any)
- Keyword Arguments:
For other possible keyword arguments, see the
Decoratorclass.
- __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.
- 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:
TypeError – If cls is not a subclass of the framework_class.
TopmostDecoratorError – If cls is already decorated with a
TopMostDecorator.MissingRequirementsError – If cls is missing a required decorator.
- Return type:
Aggregators¶
A suite of aggregators to be used with the Distributed decorator.
These are responsible for combining the predictions of several independent expert controllers.
- 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.
- aggregate()[source]¶
Combine the predictions of the individual experts into a single PoE prediction.
- _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_diffanddelta_valare the same inXBCMAggregator.- Parameters:
- Return type:
- 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}\]
- 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}\]
- 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}\).
- 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\).
- 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\).
- 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 seeBaseAggregator._beta_correction().)
- 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}\]
- 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 seeBaseAggregator._beta_correction().)
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:
train_x (
Union[Tensor,ndarray[tuple[Any,...],dtype[floating]],ndarray[tuple[Any,...],dtype[integer]]]) – The mean of the inputs.n_experts (
int) – The number of partitions in which to split the data. Defaults to 3.communication (
bool) – If True, A communications expert will be included. Defaults to False.rng (
Optional[Generator]) – Generator instance used to generate random numbers.
- __init__(train_x, n_experts=3, communication=False, rng=None)[source]¶
Initialise the BasePartitioner class.
- class vanguard.distribute.partitioners.RandomPartitioner(train_x, n_experts=3, communication=False, rng=None)[source]¶
Create a partition using random sampling.
- class vanguard.distribute.partitioners.KMeansPartitioner(train_x, n_experts=3, communication=False, rng=None)[source]¶
Create a partition using K-Means.
- class vanguard.distribute.partitioners.MiniBatchKMeansPartitioner(train_x, n_experts=3, communication=False, rng=None)[source]¶
Create a partition using Mini-batch K-Means.
- 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.KMedoidsobject.