Conversation
baybe/utils/interval.py
Outdated
| or (self.lower < number < self.upper) | ||
| ) | ||
|
|
||
| def is_close(self, other: Interval, /) -> bool: |
There was a problem hiding this comment.
@Scienfitz @AdrianSosic do we want to add the possibility to pipe through **kwargs that are then piped through to np.isclose for finer control?
There was a problem hiding this comment.
we dont need this function, we can rely on attrs builint funcitonality, you merely have to tell attrs please compare the "lower" and "upper" attributes using "np.isclose", then the entire IntervalA == IntervalB comparison will be fuzzy as we need
see my comment in #767
There was a problem hiding this comment.
Also note that I could not directly use np.isclose as this caused mypy to complain, I hence added a lambda as well as bool conversion in 343d7f8
There was a problem hiding this comment.
Pull request overview
Adds a fuzzy interval-boundary comparison utility to address overly strict normalization checks (Issue #767), replacing exact Interval(0, 1) comparisons with a tolerance-based approach.
Changes:
- Added
Interval.is_close()usingnumpy.iscloseon both bounds. - Updated
NumericalTarget.is_normalizedto useInterval.is_close(Interval(0, 1))instead of strict equality. - Added validation tests for closeness behavior and documented the change in the changelog.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
baybe/utils/interval.py |
Introduces Interval.is_close() for fuzzy boundary comparison. |
baybe/targets/numerical.py |
Switches normalization detection to use the new fuzzy comparison. |
tests/validation/test_interval_validation.py |
Adds tests for Interval.is_close() behavior. |
CHANGELOG.md |
Documents the new API and the normalization-check fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
38e6696 to
c81db9e
Compare
This PR adds an
is_closefunctionality for theIntervalclass to allow fuzzy comparisons of interval boundaries.This fixed #767 by replacing the strict check for normalisation of an Interval against the
Interval(0,1)by a fuzzy match against this interval. The functionality simply uses thenp.isclosefunction to check both interval boundaries.