def test_underscore_diff_rate(xes: fd.ERSource): x = xes._differential_rate(data_tensor=xes.data_tensor[0], ptensor=xes.ptensor_from_kwargs()) assert isinstance(x, tf.Tensor) assert x.dtype == fd.float_type() y = xes._differential_rate(data_tensor=xes.data_tensor[0], ptensor=xes.ptensor_from_kwargs(elife=100e3)) np.testing.assert_array_less(-fd.tf_to_np(tf.abs(x - y)), 0)
def test_detector_response(xes: fd.ERSource): r = xes.detector_response('photon', xes.data_tensor[0], xes.ptensor_from_kwargs()).numpy() assert r.shape == (n_events, xes.dimsizes['photon_detected']) # r is p(S1 | detected quanta) as a function of detected quanta # so the sum over r isn't meaningful (as long as we're frequentists) # Maximum likelihood est. of detected quanta is correct max_is = r.argmax(axis=1) domain = xes.domain('photon_detected').numpy() found_mle = np_lookup_axis1(domain, max_is) np.testing.assert_array_less( np.abs(xes.data['photon_detected_mle'] - found_mle), 0.5)
def test_detection_prob(xes: fd.ERSource): r = xes.detection_p('electron', xes.data_tensor[0], xes.ptensor_from_kwargs()).numpy() assert r.shape == (n_events, xes.dimsizes['electron_detected'], xes.dimsizes['electron_produced']) # Sum of probability over detected electrons must be # A) in [0, 1] for any value of electrons_produced # (it would be 1 everywhere if we considered # infinitely many electrons_detected values) # TODO: this holds to 1e-4... is that enough? rs = r.sum(axis=1) np.testing.assert_array_less(rs, 1 + 1e-4) np.testing.assert_array_less(1 - rs, 1 + 1e-4) # B) 1 at the MLE of electrons_produced, # where all reasonably probable electrons_detected values # should be probed mle_is = np.round(xes.data['electron_produced_mle'] - xes.data['electron_produced_min']).values.astype(np.int) np.testing.assert_almost_equal(np_lookup_axis1(rs, mle_is), np.ones(n_events), decimal=2)
def test_nphnel(xes: fd.ERSource): """Test (nph, nel) rate matrix""" r = xes.rate_nphnel(xes.data_tensor[0], xes.ptensor_from_kwargs()).numpy() assert r.shape == (n_events, xes.dimsizes['photon_produced'], xes.dimsizes['electron_produced'])