-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Support combined kernels #597
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
Support combined kernels #597
Conversation
📝 WalkthroughWalkthroughThe changes modify the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #597 +/- ##
=======================================
Coverage 97.89% 97.89%
=======================================
Files 10 10
Lines 1185 1188 +3
=======================================
+ Hits 1160 1163 +3
Misses 25 25 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
tests/test_parameter.py (1)
249-260: Consider adding assertions to validate kernel behavior.The test successfully validates that combined kernels can be wrapped and fitted without errors. However, it could be more thorough by adding assertions similar to the existing
test_wrapped_kernel_fittest (line 246), which verifies that the kernel's parameters changed after fitting.🔎 Suggested assertion to validate the kernel behavior
gp.fit(space.params, space.target) + + # Verify that hyperparameters were optimized (not just using initial values) + assert gp.kernel_.k1.length_scale != 1e5 + assert gp.kernel_.k2.noise_level != 1.0bayes_opt/parameter.py (1)
492-495: Document why shallow copy and__new__are necessary for combined kernels.The implementation uses
__new__and__dict__.update()to preserve the internal state of combined kernels (e.g.,Matern + WhiteKernel), which cannot be reconstructed fromget_params()alone. This approach is necessary and works correctly with sklearn kernels, which have simple attribute structures that are safe to shallow-copy after initialization.Add a comment explaining that this pattern is specifically required to support combined kernels and that the shallow copy is safe because sklearn kernels do not modify their attributes after construction.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
bayes_opt/parameter.pytests/test_parameter.py
🧰 Additional context used
🧬 Code graph analysis (1)
tests/test_parameter.py (2)
bayes_opt/target_space.py (3)
kernel_transform(340-347)params(149-156)target(159-166)bayes_opt/parameter.py (5)
wrap_kernel(457-495)kernel_transform(115-126)kernel_transform(222-234)kernel_transform(308-320)kernel_transform(434-449)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: Python 3.10 - numpy >=1.25,<2
- GitHub Check: Python 3.12 - numpy >=1.25,<2
- GitHub Check: Python 3.12 - numpy >=2
- GitHub Check: Python 3.11 - numpy >=2
- GitHub Check: Python 3.11 - numpy >=1.25,<2
- GitHub Check: Python 3.9 - numpy >=1.25,<2
- GitHub Check: Python 3.13 - numpy >=2
- GitHub Check: Python 3.10 - numpy >=2
- GitHub Check: Python 3.9 - numpy >=2
The previous method of constructing the
WrappedKerneldidn't allow for combined kernels, this PR fixes that.Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.