in ax/modelbridge/modelbridge_utils.py [0:0]
def _roundtrip_transform(x: np.ndarray) -> np.ndarray:
"""Inner function for performing aforementioned functionality.
Args:
x: points in the transformed space (e.g. all transforms have been applied
to them)
Returns:
points in the transformed space, but rounded via the original space.
"""
# apply reverse terminal transform to turn array to ObservationFeatures
observation_features = [
ObservationFeatures(
parameters={p: float(x[i]) for i, p in enumerate(param_names)}
)
]
# reverse loop through the transforms and do untransform
for t in reversed(transforms.values()):
observation_features = t.untransform_observation_features(
observation_features
)
# forward loop through the transforms and do transform
for t in transforms.values():
observation_features = t.transform_observation_features(
observation_features
)
# parameters are guaranteed to be float compatible here, but pyre doesn't know
new_x: List[float] = [
# pyre-fixme[6]: Expected `Union[_SupportsIndex, bytearray, bytes, str,
# typing.SupportsFloat]` for 1st param but got `Union[None, bool, float,
# int, str]`.
float(observation_features[0].parameters[p])
for p in param_names
]
# turn it back into an array
return np.array(new_x)