Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shape issues with multioutput kernels #818

Closed
kekeblom opened this issue Jul 26, 2018 · 6 comments · Fixed by #1583
Closed

Shape issues with multioutput kernels #818

kekeblom opened this issue Jul 26, 2018 · 6 comments · Fixed by #1583
Labels
Projects

Comments

@kekeblom
Copy link

I have some questions regarding the independent_interdomain_conditional function in the multioutput module.

I'm dealing with a case where I have a multiple output kernel and several independent GPs with separate inducing points. In this case the variables will have the following shapes:

Kmn: M x L x N x P
Kmm: L x M x M
Knn: N x P (or P x N x N for full_cov case)
f: M x L
q_sqrt: L x M x M

If full_cov = False and full_ouput_cov = False and white = False, Ar will have shape (L, M, N, P) as explicitly reshaped on line 311. Now on line 327 (link below) the code will crash as Lm will have rank 3 and Ar rank 4. The comment seems to be wrong as well.

A = tf.matrix_triangular_solve(Lm, Ar) # L x M x M * L x M x NP -> L x M x NP

The problem might be fixed by replacing Ar with A on that line. However, then the output will have shape (N * L, P). Shouldn't the mean and variance have shape (N, L * P) in this case?

Am I thinking about this the wrong way?

@awav
Copy link
Member

awav commented Jul 29, 2018

@kekeblom, could you post MWE?

@kekeblom
Copy link
Author

kekeblom commented Jul 30, 2018

import gpflow
import tensorflow as tf
import numpy as np
import observations
from gpflow.multioutput.conditionals import independent_interdomain_conditional

(Xtrain, Ytrain), _ = observations.mnist('/tmp/mnist')
Xtrain -= Xtrain.mean(axis=0)

Zs = [np.random.randn(32, 392) for _ in range(2)]
rbf = gpflow.kernels.RBF(392)

def compute_Kmn(Z, X):
    X1 = X[:, 0:392]
    X2 = X[:, 392:]
    return tf.stack([
        rbf.K(Z, X1),
        rbf.K(Z, X2)
    ])

def compute_Knn(X):
    X1 = X[:, 0:392]
    X2 = X[:, 392:]
    return tf.stack([
        rbf.Kdiag(X1),
        rbf.Kdiag(X2)
    ])

batch = Xtrain[0:10]
# L = 2, P = 2, N = 10, M = 32
Kmm = tf.stack([rbf.K(Z) for Z in Zs]) # L x M x M
Kmn = tf.stack([compute_Kmn(Z, batch) for Z in Zs]) # L x P x M x N
Kmn = tf.transpose(Kmn, [2, 0, 3, 1]) # -> M x L x N x P
Knn = tf.transpose(compute_Knn(batch)) # N x P
q_mu = np.zeros((32, 2))
q_sqrt = np.stack([np.eye(32) for _ in range(2)])

mean, var = independent_interdomain_conditional(Kmn, Kmm, Knn, q_mu, q_sqrt=q_sqrt, full_cov=False, full_output_cov=False)

So in this case we have two independent gps with separate inducing points. Two kernels which use different subsets of the input.

This will crash with "InvalidArgumentError: Shapes must be equal rank".

@awav

@Joshuaalbert
Copy link

Joshuaalbert commented Aug 9, 2018

@awav and @kekeblom This is a repeat (or very similar to) of #819

@st-- st-- changed the title On multioutput kernels Shape issues with multioutput kernels Mar 28, 2019
@st-- st-- added the bug label Dec 3, 2019
@st-- st-- added this to To do in Open bugs via automation Apr 9, 2020
@st-- st-- moved this from To do to Low priority in Open bugs May 7, 2020
st-- added a commit that referenced this issue Oct 2, 2020
st-- added a commit that referenced this issue Oct 2, 2020
@st--
Copy link
Member

st-- commented Oct 2, 2020

@kekeblom thanks for bringing this to our attention, and apologies for the long delay - it turned out to be a bug in our code indeed! I had to slightly edit your example to make it "work" (fail for the right reason), and fixed it in #1583.

@st-- st-- moved this from Low priority to Bugfix in progress in Open bugs Oct 2, 2020
@st-- st-- linked a pull request Oct 2, 2020 that will close this issue
@st-- st-- closed this as completed in #1583 Oct 7, 2020
Open bugs automation moved this from Bugfix in progress to Resolved Oct 7, 2020
st-- added a commit that referenced this issue Oct 7, 2020
Resolves #818

Co-authored-by: ST John <st@secondmind.ai>
@st--
Copy link
Member

st-- commented Oct 7, 2020

@kekeblom thanks again for the bug report, late but better late than never, it's finally fixed!

@kekeblom
Copy link
Author

kekeblom commented Oct 9, 2020

Kudos on having a watertight process! Most other projects would have probably dropped the ball at some point during those couple years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Open bugs
  
Resolved
Development

Successfully merging a pull request may close this issue.

4 participants