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

Sequential calls to predict using VFE and SVGP models #1030

Closed
tadejkrivec opened this issue Aug 21, 2019 · 3 comments
Closed

Sequential calls to predict using VFE and SVGP models #1030

tadejkrivec opened this issue Aug 21, 2019 · 3 comments

Comments

@tadejkrivec
Copy link
Contributor

I already posted this under another issue. I have an example where I have to call predict sequentially. Why would SVGP predictions be faster then SGPR in that case? Isn't the time complexity with prediction the same for all sparse models or am I missing something? This is the code I ran for testing it:

from numpy.random import randn
import gpflow

sgpr = gpflow.models.SGPR(X=randn(70000,8), Y=randn(70000,1), kern=gpflow.kernels.SquaredExponential(8), Z=randn(200,8))
sgpr.predict_y(randn(1,8))
%timeit -n 100 -r 7 sgpr.predict_y(randn(1,8))
>>> 128 ms ± 696 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

svgp = gpflow.models.SVGP(X=randn(70000,8), Y=randn(70000,1), kern=gpflow.kernels.SquaredExponential(8), likelihood=gpflow.likelihoods.Gaussian(), Z=randn(200,8))
svgp.predict_y(randn(1,8))
%timeit -n 100 -r 7 svgp.predict_y(randn(1,8))
>>> 6.61 ms ± 913 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
@st--
Copy link
Member

st-- commented Dec 3, 2019

@tadejkrivec sorry for the late answer, I believe it's because of the lack of storing the pre-computed matrices -- the SGPR model in predict_y still operates on the 70000-row X and Y vectors (computing exactly) each time, whereas SVGP has stored that information ("approximately") in the q(u) distribution which is much smaller. "Time complexity" just means whether it's O(NM^2 + M^3), doesn't say anything about the prefactor... Really, this would be long better on stackoverflow.com (tag gpflow: https://stackoverflow.com/questions/tagged/gpflow), if you would be up for posting your question again there I'll add my answer there and future users can come across it too. Thanks!

@tadejkrivec
Copy link
Contributor Author

I've posted the question on Stackoverflow. I did figure that on my own. My workaround is a custom implementation for prediction where I precompute the part of the graph dependent on the training dataset and then reuse it in a loop.

@st--
Copy link
Member

st-- commented Dec 4, 2019 via email

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

No branches or pull requests

2 participants