def test_prior(): p1 = Parameter('test_parameter', 1.0, min_value=-5.0, max_value=5.0, delta=0.2, desc='test', free=False, unit='MeV') my_prior = Uniform_prior() p1.prior = my_prior assert my_prior == p1.prior custom_prior = lambda x: x**2 with pytest.raises(NotCallableOrErrorInCall): p1.prior = custom_prior invalid_prior = lambda x, y: x * y with pytest.raises(NotCallableOrErrorInCall): p1.prior = invalid_prior # Test the set_uninformative_prior method p1.min_value = None p1.max_value = 100.0 with pytest.raises(ParameterMustHaveBounds): p1.set_uninformative_prior(Uniform_prior) p1.min_value = 0.0 p1.max_value = None with pytest.raises(ParameterMustHaveBounds): p1.set_uninformative_prior(Uniform_prior) p1.min_value = 0.0 p1.max_value = 100.0 p1.set_uninformative_prior(Uniform_prior) # Log-uniform cannot be used if minimum is 0.0 with pytest.raises(SettingOutOfBounds): p1.set_uninformative_prior(Log_uniform_prior) p1.min_value = 1.0 p1.set_uninformative_prior(Log_uniform_prior)
def test_internal_delta(): p = Parameter('test_parameter',1.0) p.min_value = None p.max_value = None p._get_internal_delta() p = Parameter('test_parameter', 1.0, min_value=0.1, max_value=5.0, delta=0.2, desc='test', free=False, unit=u.MeV, prior=Uniform_prior(), is_normalization=True, transformation=LogarithmicTransformation()) p._get_internal_delta() with pytest.raises(AssertionError): p = Parameter('test_parameter', 1.0, min_value=-1., max_value=5.0, delta=0.2, desc='test', free=False, unit=u.MeV, prior=Uniform_prior(), is_normalization=True, transformation=LogarithmicTransformation()) p = Parameter('test_parameter', 1.0, min_value=None, max_value=5.0, delta=0.2, desc='test', free=False, unit=u.MeV, prior=Uniform_prior(), is_normalization=True, transformation=LogarithmicTransformation()) p._get_internal_delta()
def test_get_randomized_value(): # Test randomization no boundaries (normal distribution) p1 = Parameter('test_parameter', 1.0) val2 = p1.get_randomized_value(0.1) assert isinstance(val2, float) # Test the randomized value with truncated normal, i.e., with boundaries p2 = Parameter('test_parameter', 1.0, min_value=-5.0, max_value=5.0, delta=0.2, desc='test', free=False, unit='MeV') val1 = p2.get_randomized_value(0.1) assert p2.min_value <= val1 <= p2.max_value # Test the same but with a large variance val1 = p2.get_randomized_value(10.0) assert p2.min_value <= val1 <= p2.max_value p2.min_value = None val1 = p2.get_randomized_value(10.0) assert val1 <= p2.max_value p2.min_value = -5.0 p2.max_value = None val1 = p2.get_randomized_value(10.0) assert val1 >= p2.min_value