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

Prepare for future batching #385

Merged

Conversation

Thomas-Christie
Copy link
Contributor

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

Checklist

  • I've formatted the new code by running poetry run pre-commit run --all-files --show-diff-on-failure before committing.
  • I've added tests for new code.
  • I've added docstrings for the new code.

Description

In the future certain utility functions will be "batched" utility functions which quantify the utility of querying a batch of points rather than a single point. These utility functions may in turn be optimised differently.

Therefore, I propose we have a SinglePointUtilityFunction type for non-batched utility functions, which has type annotation [N D] -> [N 1], and in the future we may add BatchUtilityFunction which has type annotation [N B D] -> [N 1]. Distinguishing between these makes it easy for users to see which utility functions support batching.

Also refactored UtilityDrivenDecisionMaker to enable for Thompson sampling to be used in a batched context, and updated unit tests to reflect this. Finally, added a new notebook to serve as an introduction to the decision_making module.

Issue Number: N/A

In the future certain utility functions will be "batched" utility
functions which quantify the utility of querying a *batch* of points
rather than a single point. These utility functions may in turn be
optimised differently.

Therefore, I propose we have a `SinglePointUtilityFunction` type for
non-batched utility functions, which has type annotation `[N  D] -> [N
1]`, and in the future we may add `BatchUtilityFunction` which has type
  annotation `[N B D] -> [N 1]`. Distinguishing between these makes it
  easy for users to see which utility functions support batching.

  Also refactored UtilityDrivenDecisionMaker to enable for Thompson
  sampling to be used in a batched context, and updated unit tests to
  reflect this. Finally, added a new notebook to serve as an
  introduction to the `decision_making` module.
Comment on lines +261 to +268
Note that in general `SinglePointUtilityFunction`s are only capable of
generating one point to be queried at each iteration of the decision making loop
(i.e. `self.batch_size` must be 1). However, Thompson sampling can be used in a
batched setting by drawing a batch of different samples from the GP posterior.
This is done by calling `build_utility_function` with different keys
sequentilly, and optimising each of these individual samples in sequence in
order to obtain `self.batch_size` points to query next.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is nice and clear

maximizers = jnp.concatenate(maximizers)
return maximizers
else:
raise NotImplementedError(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this keeps it tidy for now

maximizers = []
if isinstance(self.utility_function_builder, ThompsonSampling) or (
(not isinstance(self.utility_function_builder, ThompsonSampling))
and (self.batch_size == 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this still not work with batch_size=1? This logic is a little tricky to understand

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's restricting batch size to be 1 for non-TS acquisition functions if someone happens to implement one for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it. Maybe you can make the logic clearer so people like me dont get confused?

Copy link
Contributor

@henrymoss henrymoss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Thomas-Christie Thomas-Christie merged commit b225ecf into JaxGaussianProcesses:tchristie/bo Sep 8, 2023
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants