Skip to content

remove redundant PieceWiseLinearGP add ExactW Kernels#750

Merged
jduerholt merged 13 commits into
mainfrom
feature/exact_w_kernel
Jun 1, 2026
Merged

remove redundant PieceWiseLinearGP add ExactW Kernels#750
jduerholt merged 13 commits into
mainfrom
feature/exact_w_kernel

Conversation

@Jimbo994
Copy link
Copy Markdown
Collaborator

@Jimbo994 Jimbo994 commented Apr 9, 2026

Motivation

With the advent of the engineered features, we can now, in principle, get rid of the PieceWiseLinearGP because it can be fully recreated using the InterpolateFeature engineered feature. So, for future maintenance, it is better to remove the now-redundant PieceWiseLinearGP and accompanying code from, for instance, torch_tools.py and other locations.

In the meantime, I also worked on exact implementations of the WassersteinKernel. The WassersteinKernel was computed on an interpolated grid. The ExactWassersteinKernel considers the union of unique x-values and then uses the trapezoidal rule, together with identifying the sign of break points, to perform the computation exactly. Both W1 and W2 distances are supported. The W1 implementation matches the approximate WassersteinKernel at an adequately high number of interpolation points.

The union of unique x-values can become quite large when having high-dimensional problems, a large number of raw samples/restarts in the acq. func. optimization, etc. Which on moderate compute (e.g., small k8 compute), can lead to memory issues. Therefore, there is also some chunking in the code so that we loop over the union. For CPU this was also slighly faster. Thoughts on this implementation @jduerholt?

Lastly, fixed a bug in the interp1d, which could lead to gradfNone errors due to division by zero. In principle, this should never happen, as inequality constraints are set, but initial candidates provided by Botorch sometimes violate these.

Have you read the Contributing Guidelines on pull requests?

Yes

Have you updated CHANGELOG.md?

Yes

Test Plan

Removed old tests.
Created new tests for new features.
Ran tests.

@Jimbo994 Jimbo994 requested a review from jduerholt April 9, 2026 12:06
@Jimbo994 Jimbo994 changed the title Feature/exact w kernel remove redundant PieceWiseLinearGP add ExactW Kernels May 28, 2026
@Jimbo994 Jimbo994 marked this pull request as ready for review May 28, 2026 10:19
Copy link
Copy Markdown
Contributor

@jduerholt jduerholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really, really good to me. I love it. Only some minor comments.

Comment thread bofire/data_models/surrogates/trainable_botorch.py Outdated
Comment thread bofire/kernels/shape.py
Comment thread bofire/data_models/kernels/shape.py
Comment thread tests/bofire/data_models/specs/surrogates.py
@Jimbo994
Copy link
Copy Markdown
Collaborator Author

How about this @jduerholt

Copy link
Copy Markdown
Contributor

@jduerholt jduerholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks!

@jduerholt jduerholt merged commit 0f992a1 into main Jun 1, 2026
11 checks passed
@jduerholt jduerholt deleted the feature/exact_w_kernel branch June 1, 2026 19:11
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

Successfully merging this pull request may close these issues.

2 participants