question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multitask GP syntactic sugar

See original GitHub issue

Multitask GPs can be written in GPyTorch as is (see #208), but right now it is extremely ugly.

Proposed interface:

  • Introduce a MultitaskKernel model, which wraps a standard kernel function and returns the Kronecker product between an index (task) kernel and the supplied input kernel.
  • Mean functions take in an n_tasks argument, which defaults as None. If n_tasks=d, means will return an n x d output.
  • Multiple outputs (for train_y) should be expressed in an n x d matrix.

Necessary updates:

  • We introduce a syntactic sugar for GaussianRandomVariables. If the mean is an n x d matrix and the covariance is an nd x nd LazyVariable, we will figure things out
    • var, std, etc. will return n x d matrices
    • sample will return an n x d x s tensor
    • Explicitly evaluating the covariance might return an n x d x n x d tensor, or maybe a nd x nd tensor? Thoughts? (Probably won’t happen too often, but probably a good corner case to catch.)
  • inv_quad_log_det is updated to handle this new syntactic sugar.

The hadamard multitask case (one task per input) will remain essentially the same.

cc @Balandat @darbour @jacobrgardner

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
Balandatcommented, Aug 1, 2018

Here is something quick an dirty that takes the n x t mean and nt x nt covar and gets the job done at least for sampling:

class MultiOutputGaussianRandomVariable(RandomVariable):
    def __init__(self, mean, covar):
        """
        Constructs a multi-output multivariate Gaussian random variable, based on mean and covariance
        Can be multi-output multivariate, or a batch of multi-output multivariate Gaussians

        Passing a matrix mean corresponds to a multi-output multivariate Gaussian
        Passing a matrix mean corresponds to a batch of multivariate Gaussians

        Params:
        - mean (Tensor: matrix n x t, or batch matrix b x n x t) mean of Gaussian distribution
        - covar (Tensor: matrix nt x nt, or batch matrix b x nt x nt) covariance of Gaussian distribution
        """
        super(MultiOutputGaussianRandomVariable, self).__init__(mean, covar)
        if not torch.is_tensor(mean) and not isinstance(mean, LazyVariable):
            raise RuntimeError("The mean of a GaussianRandomVariable must be a Tensor or LazyVariable")

        if not torch.is_tensor(covar) and not isinstance(covar, LazyVariable):
            raise RuntimeError("The covariance of a GaussianRandomVariable must be a Tensor or LazyVariable")
            
        if mean.ndimension() not in {2, 3}:
            raise RuntimeError("mean should be a matrix or a batch matrix (batch mode)")

        if not isinstance(covar, LazyVariable):
            covar = NonLazyVariable(covar)
        
        self._mean = mean
        self._covar = covar
        self._nbatch = mean.shape[0] if mean.ndimension() == 3 else None
        self._n = mean.shape[-2]
        self._t = mean.shape[-1]

    def covar(self):
        raise NotImplementedError("Explicit construction of covar not implemented")

    def mean(self):
        return self._mean

    def representation(self):
        return self._mean, self._covar

    def sample(self, n_samples):
        samples = (
            self
            ._covar
            .zero_mean_mvn_samples(n_samples)
            .view(self._t, self._n, n_samples)
            .transpose(0, 1)
            .contiguous()
            .add(self._mean.unsqueeze(-1))
        )
        return samples

    def var(self):
        return self._covar.diag().view(self._n, self._t)
1reaction
jacobrgardnercommented, Jul 29, 2018

Maybe labels should always be n x 1 and then b x n x t means b batches of n data on t tasks?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multitask GP Regression — GPyTorch 1.9.0 documentation
Multitask regression, introduced in this paper learns similarities in the outputs simultaneously. It's useful when you are performing regression on multiple ...
Read more >
Multi-task learning models for functional data and application ...
The present document is dedicated to the analysis of functional data and the definition of multi-task models for regression and clustering.
Read more >
integrating remote invocations with asynchronism and ...
ABSTRACT. In this paper we argue that it is possible to couple the advantages of programming with the well-known abstraction of RPC with...
Read more >
Lessons from Learning Ada in 2021 - Hacker News
I have not tried out Ada's multi-tasking capability, but it has a simple TASK ... never bothered to improve and add more syntactic...
Read more >
On the relationship between multitask neural networks and ...
Our construction enables using multitask GP to perform efficient Bayesian inference for the equivalent MTDNN with infinitely-wide hidden layers.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found