def test_params(): m = Minuit(func0, x=1, y=2) m.errordef = Minuit.LEAST_SQUARES m.errors = (3, 4) m.fixed["x"] = True m.limits["y"] = (None, 10) # these are the initial param states expected = ( Param(0, "x", 1.0, 3.0, None, False, True, False, False, False, None, None), Param(1, "y", 2.0, 4.0, None, False, False, True, False, True, None, 10), ) assert m.params == expected m.migrad() m.minos() assert m.init_params == expected expected = [ Namespace(number=0, name="x", value=1.0, error=3.0, merror=(-3.0, 3.0)), Namespace(number=1, name="y", value=5.0, error=1.0, merror=(-1.0, 1.0)), ] params = m.params for i, exp in enumerate(expected): p = params[i] assert p.number == exp.number assert p.name == exp.name assert p.value == approx(exp.value, rel=1e-2) assert p.error == approx(exp.error, rel=1e-2) assert p.error == approx(exp.error, rel=1e-2)
def test_get_param_states(): m = Minuit(func3, x=1, y=2, error_x=3, error_y=4, fix_x=True, limit_y=(None, 10), pedantic=False, errordef=1, print_level=0) # these are the initial param states expected = [ Param(0, 'x', 1.0, 3.0, False, True, False, False, False, None, None), Param(1, 'y', 2.0, 4.0, False, False, True, False, True, None, 10) ] assert m.get_param_states() == expected m.migrad() assert m.get_initial_param_states() == expected expected = [ Param(0, 'x', 1.0, 3.0, False, True, False, False, False, None, None), Param(1, 'y', 5.0, 1.0, False, False, True, False, True, None, 10) ] params = m.get_param_states() for i, exp in enumerate(expected): p = params[i] assert set(p._fields) == set(exp._fields) for key in exp._fields: if key in ('value', 'error'): assert_allclose(getattr(p, key), getattr(exp, key), rtol=1e-2) else: assert getattr(p, key) == getattr(exp, key)
def test_console_frontend_with_difficult_values(): matrix = Matrix(("x", "y"), ((-1.23456, 0), (0, 0))) # fmt: off assert framed(matrix) == r""" ┌───┬───────────────┐ │ │ x y │ ├───┼───────────────┤ │ x │ -1.235 0.000 │ │ y │ 0.000 0.000 │ └───┴───────────────┘ """ # fmt: on mps = Params( [ Param( 0, "x", -1.234567e-22, 1.234567e-11, True, False, False, False, False, None, None, ) ], None, ) # fmt: off assert framed(mps) == r"""
def test_text_with_long_names(): matrix = Matrix(["super-long-name", "x"], ((1.0, 0.1), (0.1, 1.0))) # fmt: off assert framed(matrix) == r""" ┌─────────────────┬─────────────────────────────────┐ │ │ super-long-name x │ ├─────────────────┼─────────────────────────────────┤ │ super-long-name │ 1.0 0.1 │ │ x │ 0.1 1.0 │ └─────────────────┴─────────────────────────────────┘ """ mps = Params( [ Param( 0, "super-long-name", 0, 0, False, False, False, False, False, None, None, ) ], None, ) assert framed(mps) == r"""
def test_console_frontend_with_difficult_values(): matrix = Matrix(("x", "y"), ((-1.23456, 0), (0, 0))) assert r"""--------------------- | | x y | --------------------- | x | -1.235 0.000 | | y | 0.000 0.000 | ---------------------""" == str(matrix) mps = Params( [ Param( 0, "x", -1.234567e-22, 1.234567e-11, True, False, False, False, False, None, None, ) ], None, ) assert r"""------------------------------------------------------------------------------------------ | | Name | Value | Hesse Err | Minos Err- | Minos Err+ | Limit- | Limit+ | Fixed | ------------------------------------------------------------------------------------------ | 0 | x | -0 | 1.2e-11 | | | | | CONST | ------------------------------------------------------------------------------------------""" == str( mps)
def test_text_with_long_names(): matrix = Matrix(["super-long-name", "x"], ((1.0, 0.1), (0.1, 1.0))) assert r"""----------------------------------------------------- | | super-long-name x | ----------------------------------------------------- | super-long-name | 1.0 0.1 | | x | 0.1 1.0 | -----------------------------------------------------""" == str(matrix) mps = Params( [ Param( 0, "super-long-name", 0, 0, False, False, False, False, False, None, None, ) ], None, ) assert r"""----------------------------------------------------------------------------------------------------- | | Name | Value | Hesse Err | Minos Err- | Minos Err+ | Limit- | Limit+ | Fixed | ----------------------------------------------------------------------------------------------------- | 0 | super-long-name | 0 | 0 | | | | | | -----------------------------------------------------------------------------------------------------""" == str( mps)
def test_Param(): keys = "number name value error is_const is_fixed has_limits has_lower_limit has_upper_limit lower_limit upper_limit".split( ) values = 3, "foo", 1.2, 3.4, False, False, True, True, False, 42, None p = Param(*values) assert p.has_lower_limit == True assert p.has_upper_limit == False assert p["has_lower_limit"] == True assert p["lower_limit"] == 42 assert p["upper_limit"] == None assert "upper_limit" in p assert "foo" not in p assert [key for key in p] == keys assert p.keys() == tuple(keys) assert p.values() == values assert p.items() == tuple((k, v) for k, v in zip(keys, values)) assert str( p ) == "Param(number=3, name='foo', value=1.2, error=3.4, is_const=False, is_fixed=False, has_limits=True, has_lower_limit=True, has_upper_limit=False, lower_limit=42, upper_limit=None)"
def test_params(): m = Minuit( func0, x=1, y=2, error_x=3, error_y=4, fix_x=True, limit_y=(None, 10), pedantic=False, errordef=Minuit.LEAST_SQUARES, ) # these are the initial param states expected = [ Param(0, "x", 1.0, 3.0, False, True, False, False, False, None, None), Param(1, "y", 2.0, 4.0, False, False, True, False, True, None, 10), ] assert m.params == expected m.migrad() assert m.init_params == expected expected = [ Param(0, "x", 1.0, 3.0, False, True, False, False, False, None, None), Param(1, "y", 5.0, 1.0, False, False, True, False, True, None, 10), ] params = m.params for i, exp in enumerate(expected): p = params[i] assert set(p._fields) == set(exp._fields) for key in exp._fields: if key in ("value", "error"): assert_allclose(getattr(p, key), getattr(exp, key), rtol=1e-2) else: assert getattr(p, key) == getattr(exp, key)
def test_text_params_difficult_values(): mps = [ Param( 0, "x", -1.234567e-22, 1.234567e-11, None, True, False, False, False, False, None, None, ) ] assert _repr_text.params(mps) == ref("params_difficult_values")
def test_text_params_with_long_names(): mps = [ Param( 0, "super-long-name", 0, 0, None, False, False, False, False, False, None, None, ) ] assert _repr_text.params(mps) == ref("params_long_names")