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

chore: rename n to num_samples #6

Merged
merged 1 commit into from
Jul 5, 2023
Merged
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
13 changes: 7 additions & 6 deletions src/autora/experimentalist/sampler/nearest_value/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
def nearest_values_sample(
samples: Union[Iterable, Sequence],
allowed_values: np.ndarray,
n: int,
num_samples: int,
):
"""
A sampler which returns the nearest values between the input samples and the allowed values,
without replacement.

Args:
samples: input conditions
allowed_samples: allowed conditions to sample from
allowed_values: allowed conditions to sample from
num_samples: number of samples

Returns:
the nearest values from `allowed_samples` to the `samples`
Expand All @@ -31,7 +32,7 @@ def nearest_values_sample(
if isinstance(samples, Iterable):
samples = np.array(list(samples))

if allowed_values.shape[0] < n:
if allowed_values.shape[0] < num_samples:
raise Exception(
"More samples requested than samples available in the set allowed of values."
)
Expand All @@ -40,17 +41,17 @@ def nearest_values_sample(
samples = np.array(list(samples))

if hasattr(samples, "shape"):
if samples.shape[0] < n:
if samples.shape[0] < num_samples:
raise Exception(
"More samples requested than samples available in the pool."
)

x_new = np.empty((n, allowed_values.shape[1]))
x_new = np.empty((num_samples, allowed_values.shape[1]))

# get index of row in x that is closest to each sample
for row, sample in enumerate(samples):

if row >= n:
if row >= num_samples:
break

dist = np.linalg.norm(allowed_values - sample, axis=1)
Expand Down