in bayesmark/space.py [0:0]
def unwarp(self, X_w, fixed_vals={}):
"""Inverse of :func:`.warp`.
Parameters
----------
X_w : :class:`numpy:numpy.ndarray` of shape (n, m)
Warped version of input space. Must be 2D `float` :class:`numpy:numpy.ndarray`. `n` is the number of
separate points in the warped joint space. `m` is the size of the joint warped space, which can be inferred
in advance by calling :func:`.get_bounds`.
fixed_vals : dict
Subset of variables we want to keep fixed in X. Unwarp checks that the unwarped version of `X_w` matches
`fixed_vals` up to numerical error. Otherwise, an error is raised.
Returns
-------
X : list(dict(str, object)) of shape (n,)
List of `n` points in the joint space to warp. Each list element is a dictionary where each key corresponds
to a variable in the joint space.
"""
X_w = np.asarray(X_w)
check_array(X_w, "X", ndim=2, shape_endswith=(self.blocks[-1],), dtype=WARPED_DTYPE)
N = X_w.shape[0]
# Use snap_to to make sure we get exact value (no-round off) for cases where we know expected answer
X = {
param: snap_to(self.spaces[param].unwarp(xx), fixed_vals.get(param, None))
for param, xx in zip(self.param_list, np.hsplit(X_w, self.blocks[:-1]))
}
# Convert dict of arrays to list of dicts, this would not be needed if
# we used pandas but we do not want to add it as a dep. np.asscalar and
# .item() appear to be the same thing but asscalar seems more readable.
X = [{param: X[param][ii].item() for param in self.param_list} for ii in range(N)]
return X