Cache pair-wise distances to speed up GPSampler#6244
Cache pair-wise distances to speed up GPSampler#6244nabenabe0928 merged 7 commits intooptuna:masterfrom
GPSampler#6244Conversation
|
This pull request has not seen any recent activity. |
|
@sawa3030 @kAIto47802 |
optuna/_gp/gp.py
Outdated
| else: | ||
| if X2 is None: | ||
| X2 = self._X_train | ||
| d2 = (X1[..., None, :] - X2[..., None, :, :]) ** 2 |
There was a problem hiding this comment.
I'm a bit confused about this part. Would it be more straightforward to write it as d2 = (X1[..., :, None, :] - X2[..., None, :, :]) ** 2?
There was a problem hiding this comment.
Thank you for pointing it out:)
X1[..., :, None, :] - X2[..., None, :, :] first requires X1.shape[-1] == X2.shape[-1] and len(X1.shape) >= 2 and len(X2.shape) >= 2.
The newer version loosens the requirements to X1.shape[-1] == X2.shape[-1] and len(X1.shape) >= 1 and len(X2.shape) >= 2.
It essentially makes the following line look cleaner:
# Original (x must be 2 dimensions or more, requiring [..., None, :].)
cov_fx_fX = self.kernel(x[..., None, :])[..., 0, :]
# New (x can be 1 dimension, eliminating the need of [..., None, :] and flitering afterwards.)
cov_fx_fX = self.kernel(x)
sawa3030
left a comment
There was a problem hiding this comment.
Thank you for the explanation. LGTM
|
This pull request has not seen any recent activity. |
kAIto47802
left a comment
There was a problem hiding this comment.
Thank you for the PR! Basically LGTM, leaving a minor comment.
Co-authored-by: kAIto47802 <115693559+kAIto47802@users.noreply.github.com>
Motivation
This PR speeds up
GPSamplerby skipping the pair-wise distance calculations in the kernel parameter fitting.Please note that this PR depends on:
fit_kernel_paramstoGPRegressor#6243Important
7% speedup by this PR (240 sec to 223 sec) in the benchmark below 🎉
Description of the changes