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

Parallelism2 #10

Open
wants to merge 1 commit into
base: parallelism
Choose a base branch
from
Open
Show file tree
Hide file tree
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
20 changes: 14 additions & 6 deletions src/tranquilo/acceptance_decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
state,
history,
*,
search_radius_factor,
speculative_sampling_radius_factor,
wrapped_criterion,
min_improvement,
Expand Down Expand Up @@ -147,7 +148,8 @@
if n_unallocated_evals > 0:
speculative_xs = _generate_speculative_sample(
new_center=candidate_x,
radius_factor=speculative_sampling_radius_factor,
sample_radius_factor=speculative_sampling_radius_factor,
search_radius_factor=search_radius_factor,
trustregion=state.trustregion,
sample_points=sample_points,
n_points=n_unallocated_evals,
Expand Down Expand Up @@ -437,7 +439,8 @@
n_points,
history,
line_search_xs,
radius_factor,
search_radius_factor,
sample_radius_factor,
rng,
):
"""Generative a speculative sample.
Expand All @@ -448,16 +451,21 @@
sample_points (callable): Function to sample points.
n_points (int): Number of points to sample.
history (History): Tranquilo history.
radius_factor (float): Factor to multiply the trust region radius by to get the
radius of the region from which to draw the speculative sample.
search_radius_factor (float): Factor to multiply the trust region radius by to
get the radius of the search region.
sample_radius_factor (float): Factor to multiply the trust region radius by to
get the radius of the region from which to draw the speculative sample.
rng (np.random.Generator): Random number generator.

Returns:
np.ndarray: Speculative sample.

"""
search_region = trustregion._replace(
center=new_center, radius=radius_factor * trustregion.radius
center=new_center, radius=search_radius_factor * trustregion.radius
)
sample_region = trustregion._replace(
center=new_center, radius=sample_radius_factor * trustregion.radius
)

old_indices = history.get_x_indices_in_region(search_region)
Expand All @@ -465,12 +473,12 @@
old_xs = history.get_xs(old_indices)

if line_search_xs is not None:
model_xs = np.row_stack([old_xs, line_search_xs])

Check warning on line 476 in src/tranquilo/acceptance_decision.py

View check run for this annotation

Codecov / codecov/patch

src/tranquilo/acceptance_decision.py#L476

Added line #L476 was not covered by tests
else:
model_xs = old_xs

new_xs = sample_points(
search_region,
sample_region,
n_points=n_points,
existing_xs=model_xs,
rng=rng,
Expand Down
3 changes: 2 additions & 1 deletion tests/test_acceptance_decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ def test_generate_speculative_sample():
sample_points=get_sampler("random_hull"),
n_points=3,
history=history,
radius_factor=1.0,
search_radius_factor=5.0,
sample_radius_factor=1.0,
line_search_xs=None,
rng=np.random.default_rng(1234),
)
Expand Down
Loading