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

WIP: Add learner1D.all_intervals_between #390

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions adaptive/learner/learner1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,29 @@ def __setstate__(self, state):
self.losses_combined.update(losses_combined)


def all_intervals_between(
learner: Learner1D,
x_min: float | None = None,
x_max: float | None = None,
real: bool = True,
) -> list[list[float]]:
"""Returns all intervals between the given bounds."""
neighbors = learner.neighbors if real else learner.neighbors_combined
if x_min is None:
x_left = learner.bounds[0]
elif x_min in neighbors:
x_left = x_min
else:
_, x_left = learner._find_neighbors(x_min, neighbors)
if x_max is None:
x_right = learner.bounds[1]
elif x_max in neighbors:
x_right = x_max
else:
x_right, _ = learner._find_neighbors(x_max, neighbors)
return [ival for x, ival in neighbors.items() if x > x_left and x < x_right]


def loss_manager(x_scale: float) -> dict[Interval, float]:
def sort_key(ival, loss):
loss, ival = finite_loss(ival, loss, x_scale)
Expand Down