def test_can_set_scipy_distribution(): p = Identity().set_hyperparams_space(HyperparameterSpace({ 'rand_int_scipy': randint(low=2, high=5), # scipy 'rand_int_neuraxle': RandInt(2, 5), # neuraxle 'gamma_scipy': gamma(0.2), # scipy })) assert isinstance(p.get_hyperparams_space()['rand_int_scipy'], ScipyDiscreteDistributionWrapper) assert isinstance(p.get_hyperparams_space()['gamma_scipy'], ScipyContinuousDistributionWrapper) randint_sample = p.get_hyperparams_space()['rand_int_scipy'].rvs() gamma_sample = p.get_hyperparams_space()['gamma_scipy'].rvs() assert 5 >= randint_sample >= 2 assert isinstance(gamma_sample, float)
def test_randint(): hd = RandInt(min_included=-10, max_included=10, null_default_value=0) _test_randint(hd)
assert hd.max() == len(choice_list) - 1 assert abs(hd.mean() - (len(choice_list) - 1) / 2) < 1e-6 assert abs(hd.var() - (len(choice_list)**2 - 1) / 12) < 1e-6 assert abs(hd.std() - math.sqrt((len(choice_list)**2 - 1) / 12)) < 1e-6 # Convert samples in sample index samples_index = [ get_index_in_list_with_bool(choice_list, sample) for sample in samples ] # Verify that hd mean and variance also correspond to mean and variance of sampling. assert abs((hd.mean() - np.mean(samples_index)) / hd.mean()) < 1e-1 assert abs((hd.var() - np.var(samples_index)) / hd.var()) < 1e-1 @pytest.mark.parametrize( "hd, test_method", [(RandInt(min_included=-10, max_included=10, null_default_value=0), _test_randint), (LogNormal(hard_clip_min=-5, hard_clip_max=5, log2_space_mean=0.0, log2_space_std=2.0, null_default_value=-1.0), _test_lognormal), (Normal(hard_clip_min=0.0, hard_clip_max=1.0, mean=0.5, std=0.2, null_default_value=0.0), _test_normal), (LogUniform(min_included=0.001, max_included=10), _test_loguniform), (Uniform(min_included=-10, max_included=10), _test_uniform), (Poisson( min_included=0.0, max_included=10.0, null_default_value=0.0, mu=5.0), _test_discrete_poisson),