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

add EI + best observed value for TR #810

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
add EI + best observed value for TR
PiperOrigin-RevId: 549047674
  • Loading branch information
SetarehAr authored and copybara-github committed Jul 18, 2023
commit e11e7d2cacdf71e55e5ebe14f21bc3b5b5fa4746
37 changes: 34 additions & 3 deletions vizier/_src/algorithms/designers/gp/acquisitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,26 @@ def __call__(
return tfp_bo.acquisition.GaussianProcessExpectedImprovement(dist, labels)()


@struct.dataclass
class ExpectedValue(AcquisitionFunction):
"""Expected Improvement acquisition function."""

def __call__(
self,
dist: tfd.Distribution,
features: Optional[types.ModelInput] = None,
labels: Optional[types.PaddedArray] = None,
seed: Optional[jax.random.KeyArray] = None,
) -> jax.Array:
del features, seed
if labels is not None:
labels = labels.replace_fill_value(-np.inf).padded_array
return (
tfp_bo.acquisition.GaussianProcessExpectedImprovement(dist, labels)()
+ dist.mean()
)


@struct.dataclass
class PI(AcquisitionFunction):
"""Probability of Improvement acquisition function."""
Expand Down Expand Up @@ -245,6 +265,16 @@ def default_ucb_pi(cls) -> 'AcquisitionTrustRegion':
UCB(1.8), PI(), bad_acq_value=-1e12, threshold=0.3, apply_tr_after=0
)

@classmethod
def default_ucb_expected_value(cls) -> 'AcquisitionTrustRegion':
return cls(
UCB(1.8),
ExpectedValue(),
bad_acq_value=-1e12,
threshold=None,
apply_tr_after=0,
)

@classmethod
def default_ucb_lcb(cls) -> 'AcquisitionTrustRegion':
return cls(
Expand Down Expand Up @@ -289,9 +319,10 @@ def __call__(
apply_tr = False
if labels is not None:
labels_padded = labels.replace_fill_value(np.nan).padded_array
threshold = jnp.minimum(
jnp.nanmean(labels_padded), jnp.nanmedian(labels_padded)
)
# threshold = jnp.minimum(
# jnp.nanmean(labels_padded), jnp.nanmedian(labels_padded)
# )
threshold = jnp.nanmedian(labels_padded)
apply_tr = labels._original_shape[0] <= self.apply_tr_after
if self.threshold is not None:
threshold = self.threshold
Expand Down