def _norm(distribution_unnormalized): """ Integrate distribution over all values Use min of K+/Pi- system mass as momentum is undefined below this """ return bmfi.trapezoid(distribution_unnormalized, mass_k_plus + mass_pi_minus, integration_max, integration_dt)
def integrate_decay_rate(coeffs): """ Integrate previously angle integrated decay rate function over q^2 for particular amplitude coefficients """ return bmfi.trapezoid( lambda q2: decay_rate_angle_integrated(coeffs, q2), q2_min, q2_max, integration_dt )
def test_trapezoid_supports_float64(self): """ Check that trapezoid() supports integrals that return tf.float64 """ actual = bmfi.trapezoid( lambda x: tf.cast(x + 3.0, dtype=tf.float64), -5.0, 5.0, 0.1, ) self.assertEqual(tf.float64, actual.dtype, 'Check returned dtype is float64') # Check within tolerance as we're using bins nt.assert_allclose(30.0, actual.numpy(), atol=1e-4, rtol=0.001)
def test_trapezoid(self): """ Check that trapezoid() returns expected values. Uses 10_000 bins for each. """ # Check for different lists of coefficients for name, integral, start, stop, expected in self.test_integrals: with self.subTest(name=name): actual = bmfi.trapezoid( integral, start, stop, (stop - start) / 1e4, ) # Check within tolerance as we're using bins nt.assert_allclose(expected, actual.numpy(), atol=1e-4, rtol=0.001)
def test_trapezoid_supports_complex64(self): """ Check that trapezoid() supports integrals that return tf.complex64 """ actual = bmfi.trapezoid( lambda x: tf.complex(x + 3.0, x + 4.0), -5.0, 5.0, 0.1, ) self.assertEqual(tf.complex64, actual.dtype, 'Check returned dtype is complex64') # Check within tolerance as we're using bins nt.assert_allclose(30.0, tf.math.real(actual).numpy(), atol=1e-4, rtol=0.001) nt.assert_allclose(40.0, tf.math.imag(actual).numpy(), atol=1e-4, rtol=0.001)
def _integrate_distribution_around_k892(distribution): """Integrate distribution between +/- 100 MeV of K892 mass""" return bmfi.trapezoid(distribution, mass_k892 - 0.1, mass_k892 + 0.1, integration_dt)