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

Potential bug in SGPR with changepoint kernel #2097

Open
jl139277 opened this issue Dec 10, 2023 · 6 comments
Open

Potential bug in SGPR with changepoint kernel #2097

jl139277 opened this issue Dec 10, 2023 · 6 comments
Labels

Comments

@jl139277
Copy link

jl139277 commented Dec 10, 2023

Im trying to create a sparse model with changepoint kernel. The general setup I use works fine when using regular kernels:

model = gpflow.models.SGPR(
(X, Y),
kernel=kernel1,
inducing_variable=X[::100],
)

This works as expected.
When I set it up as follows I get errors:

model = gpflow.models.SGPR(
(X, Y),
kernel=gpflow.kernels.ChangePoints(
kernels=[
kernel1,
kernel2,
],
locations=[x_0],
steepness=0.01,
),
inducing_variable=X[::100],
)

Specifically:

ValueError: Dimension 1 in both shapes must be equal, but are 1000 and 10. Shapes are [10,10] and [10,100]. for '{{node concat_2}} = ConcatV2[N=2, T=DT_DOUBLE, Tidx=DT_INT32](ones_1, mul_7, concat_2/axis)' with input shapes: [10,10,1], [10,1000,0], [] and with computed input tensors: input[2] = <2>.

As far as I can tell this is a bug but I am fairly new to GPflow so I might be wrong about that. After looking around I did find this previous issue with the changepoint kernel which seemed similar. #1440

@jl139277 jl139277 changed the title SGPR and changepoint kernel yields errors in optimization Potential bug in SGPR with changepoint kernel Dec 10, 2023
@uri-granta
Copy link
Contributor

Thanks for raising an issue! Could you please include more of your example (in particular, what are X, Y, kernel1 and kernel2)? The best would be to include a short self-contained example that can be run by anyone to demonstrate the bug. (Also FYI here is how to format a code block.)

@jl139277
Copy link
Author

jl139277 commented Dec 15, 2023

Thank you for your reply and the information! Here is the additional information you requested please let me know if you need anything else.

X, Y and the kernels used did not seem to cause the issue as I could run the same model with a different kernels and inputs without issue. This minimal example replicates the error for me:

import numpy as np
import gpflow

X = np.array(
    [
        [0.865], [0.666], [0.804], [0.771], [0.147], [0.866], [0.007], [0.026],
        [0.171], [0.889], [0.243], [0.028],
    ]
)
Y = np.array(
    [
        [1.57], [3.48], [3.12], [3.91], [3.07], [1.35], [3.80], [3.82], [3.49],
        [1.30], [4.00], [3.82],
    ]
)

inducing_points = np.array([[0.125], [0.375], [0.625], [0.875]])
kernel1 = gpflow.kernels.SquaredExponential()
kernel2 = gpflow.kernels.SquaredExponential()

model = gpflow.models.SGPR(
    (X, Y),
    kernel=gpflow.kernels.ChangePoints(
        kernels=[
            kernel1,
            kernel2,
        ],
        locations=[0.5],
        steepness=0.1,
    ),
    inducing_variable=inducing_points,
)

opt = gpflow.optimizers.Scipy()
opt.minimize(model.training_loss, model.trainable_variables)

Specifically the final error reads:
ValueError: Dimension 1 in both shapes must be equal, but are 4 and 12. Shapes are [4,4] and [4,12]. for '{{node concat_2}} = ConcatV2[N=2, T=DT_DOUBLE, Tidx=DT_INT32](ones_1, mul_7, concat_2/axis)' with input shapes: [4,4,1], [4,12,1], [] and with computed input tensors: input[2] = <2>.

@uri-granta
Copy link
Contributor

Thanks. That code example actually runs fine for me without giving any errors!

Could you please include which versions of gpflow, tensorflow and python you're using? (You can get these by running pip show gpflow, pip show tensorflow and python --version.)

@jl139277
Copy link
Author

Huh, strange.
The versions I'm using are:

Python: 3.9.13,
Tensorflow: 2.15.0
Gpflow: 2.9.0

@uri-granta uri-granta added the bug label Dec 16, 2023
@uri-granta
Copy link
Contributor

Thanks! It seems to work with tensorflow 2.12 but not with 2.15. I will investigate (and ensure our tests are also run against 2.15).

@jl139277
Copy link
Author

Thank you very much mine works too now!
Incase somebody else runs into the same issue, I did have to update python to v 3.11 as well. Only changing the version of tensorflow to 2.12 left me with the same error.

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

No branches or pull requests

2 participants