def function(self, *args: tp.Any, **kwargs: tp.Any) -> tp.Loss: out = self._func(*args, **kwargs) if isinstance(out, (bool, np.bool_)): raise errors.NevergradTypeError( "Constraint must be a positive float if unsatisfied constraint (not bool)" ) return np.maximum(0, out) # type: ignore
def __init__(self, *args: tp.Any, **kwargs: tp.Any) -> None: super().__init__() if any( isinstance(x, Parameter) for x in args + tuple(kwargs.values())): raise errors.NevergradTypeError( "Operation with Parameter instances are not supported")
def _layered_sample(self) -> Data: if not self.uniform_sampling: return super()._layered_sample() # type: ignore root = self._layers[0] if not isinstance(root, Data): raise errors.NevergradTypeError(f"BoundLayer {self} on a non-Data root {root}") shape = super()._layered_get_value().shape child = root.spawn_child() # send new val to the layer under this one for the child new_val = self.random_state.uniform(size=shape) del child.value # make sure there is no cache child._layers[self._layer_index].set_normalized_value(new_val) # type: ignore return child