def __init__(self, transform: tp.Optional[str] = None) -> None: super().__init__(self._get_pixel_value, p.Instrumentation(p.Scalar(), p.Scalar()).set_name("standard")) self.register_initialization(transform=transform) self._image = datasets.get_data("Landscape") if transform == "gaussian": variables = list(p.TransitionChoice(list(range(x))) for x in self._image.shape) self.parametrization = p.Instrumentation(*variables).set_name("gaussian") elif transform == "square": stds = (np.array(self._image.shape) - 1.) / 2. variables2 = list(p.Scalar(init=s).set_mutation(sigma=s) for s in stds) self.parametrization = p.Instrumentation(*variables2).set_name("square") # maybe buggy, try again? elif transform is not None: raise ValueError(f"Unknown transform {transform}") self._max = float(self._image.max())
testing.printed_assert_equal(args, [0]) testing.printed_assert_equal(kwargs, {"y": 0}) arg_sum, kwarg_sum = 0, 0 for _ in range(24): args, kwargs = ifunc.parametrization.spawn_child( ).set_standardized_data(data, deterministic=False).value arg_sum += args[0] kwarg_sum += kwargs["y"] assert arg_sum != 0 assert kwarg_sum != 0 @testing.parametrized( floats=((p.Scalar(), p.Scalar(init=12.0)), True, False), array_int=((p.Scalar(), p.Array(shape=(1, )).set_integer_casting()), False, False), softmax_noisy=((p.Choice(["blue", "red"]), p.Array(shape=(1, ))), True, True), softmax_deterministic=((p.Choice(["blue", "red"], deterministic=True), p.Array(shape=(1, ))), False, False), ordered_discrete=((p.TransitionChoice([True, False]), p.Array(shape=(1, ))), False, False), ) def test_parametrization_continuous_noisy(variables: tp.Tuple[p.Parameter, ...], continuous: bool, noisy: bool) -> None: instru = p.Instrumentation(*variables) assert instru.descriptors.continuous == continuous assert instru.descriptors.deterministic != noisy
def test_deterministic_data_setter() -> None: instru = p.Instrumentation(p.Choice([0, 1, 2, 3]), y=p.Choice([0, 1, 2, 3])) ifunc = base.ExperimentFunction(_Callable(), instru) data = [0.01, 0, 0, 0, 0.01, 0, 0, 0] for _ in range(20): args, kwargs = ifunc.parametrization.spawn_child().set_standardized_data(data, deterministic=True).value testing.printed_assert_equal(args, [0]) testing.printed_assert_equal(kwargs, {"y": 0}) arg_sum, kwarg_sum = 0, 0 for _ in range(24): args, kwargs = ifunc.parametrization.spawn_child().set_standardized_data(data, deterministic=False).value arg_sum += args[0] kwarg_sum += kwargs["y"] assert arg_sum != 0 assert kwarg_sum != 0 @testing.parametrized( floats=((p.Scalar(), p.Scalar(init=12.0)), True, False), array_int=((p.Scalar(), p.Array(shape=(1,)).set_integer_casting()), False, False), softmax_noisy=((p.Choice(["blue", "red"]), p.Array(shape=(1,))), True, True), softmax_deterministic=((p.Choice(["blue", "red"], deterministic=True), p.Array(shape=(1,))), False, False), ordered_discrete=((p.TransitionChoice([True, False]), p.Array(shape=(1,))), False, False), ) def test_parametrization_continuous_noisy(variables: tp.Tuple[p.Parameter, ...], continuous: bool, noisy: bool) -> None: instru = p.Instrumentation(*variables) assert instru.descriptors.continuous == continuous assert instru.descriptors.deterministic != noisy