From 3fc6895fa29263ba735bc135931de68e255b5a7a Mon Sep 17 00:00:00 2001 From: Sait Cakmak Date: Mon, 16 Sep 2024 22:01:29 -0700 Subject: [PATCH] Use expm1 in Bilog outcome transform Summary: Similar to https://github.com/pytorch/botorch/pull/2540, replaces `exp(x) - 1` with the numerically more stable `expm1`. Differential Revision: D62813775 --- botorch/models/transforms/outcome.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/botorch/models/transforms/outcome.py b/botorch/models/transforms/outcome.py index ed923cde79..4eda2be865 100644 --- a/botorch/models/transforms/outcome.py +++ b/botorch/models/transforms/outcome.py @@ -790,7 +790,7 @@ def untransform( - The un-transformed outcome observations. - The un-transformed observation noise (if applicable). """ - Y_utf = Y.sign() * (Y.abs().exp() - 1.0) + Y_utf = Y.sign() * Y.abs().expm1() outputs = normalize_indices(self._outputs, d=Y.size(-1)) if outputs is not None: Y_utf = torch.stack( @@ -822,5 +822,5 @@ def untransform_posterior(self, posterior: Posterior) -> TransformedPosterior: ) return TransformedPosterior( posterior=posterior, - sample_transform=lambda x: x.sign() * (x.abs().exp() - 1.0), + sample_transform=lambda x: x.sign() * x.abs().expm1(), )