def test_gaussian_constraint_matrix(): param1 = zfit.Parameter("Param1", 5) param2 = zfit.Parameter("Param2", 6) params = [param1, param2] mu = [3., 6.1] sigma = np.array([[1, 0.3], [0.3, 0.5]]) constr = GaussianConstraint(params=params, mu=mu, sigma=sigma) constr_np = zfit.run(constr.value()) assert constr_np == pytest.approx(3.989638) assert constr.get_dependents() == set(params)
def test_gaussian_constraint(): param_vals = [5, 6, 3] mu = [3, 6.1, 4.3] sigma = [1, 0.3, 0.7] true_val = true_gauss_constr_value(param_vals, mu, sigma) params = [zfit.Parameter(f"Param{i}", val) for i, val in enumerate(param_vals)] constr = GaussianConstraint(params=params, mu=mu, sigma=sigma) constr_np = constr.value().numpy() assert constr_np == pytest.approx(true_val) assert constr.get_dependents() == set(params) param_vals[0] = 2 params[0].set_value(param_vals[0]) constr2_np = constr.value().numpy() constr2_newtensor_np = constr.value().numpy() assert constr2_newtensor_np == pytest.approx(constr2_np) true_val2 = true_gauss_constr_value(param_vals, mu, sigma) assert constr2_np == pytest.approx(true_val2)