コード例 #1
0
 def exp_measurements(self):
     """Return a list of four probability distributions, corresponding
     to the  experimental measurements of the four input observables."""
     return {
         obs: flavio.combine_measurements(obs)
         for obs in self.observables
     }
コード例 #2
0
 def test_exp_combo(self):
     o = Observable('test_obs')
     o.arguments = ['x']
     m = Measurement('test_obs measurement 1')
     m.add_constraint([('test_obs', 1)], MultivariateNormalDistribution([1, 2], np.eye(2)))
     # error: no measurement
     with self.assertRaises(ValueError):
         flavio.combine_measurements('test_obs', x=1, include_measurements=['bla'])
     m.add_constraint([('test_obs', 1)], NormalDistribution(2, 3))
     combo = flavio.combine_measurements('test_obs', x=1)
     self.assertEqual(combo.central_value, 2)
     self.assertEqual(combo.standard_deviation, 3)
     m2 = Measurement('test_obs measurement 2')
     m2.add_constraint([('test_obs', 1)], NormalDistribution(3, 3))
     combo = flavio.combine_measurements('test_obs', x=1)
     self.assertAlmostEqual(combo.central_value, 2.5)
     self.assertAlmostEqual(combo.standard_deviation, sqrt(9 / 2))
     Observable.del_instance('test_obs')
コード例 #3
0
 def _obstable_tree(self):
     if not self._obstable_tree_cache:
         info = tree()  # nested dict
         pull_dof = 1
         llh = self.likelihood
         for flh_name, flh in llh.fast_likelihoods.items():
             # loop over fast likelihoods: they only have a single "measurement"
             m = flh.pseudo_measurement
             ml = flh.full_measurement_likelihood
             pred = ml.get_predictions_par(llh.par_dict, self.w)
             sm_cov = flh.sm_covariance.get(force=False)
             _, exp_cov = flh.exp_covariance.get(force=False)
             inspire_dict = self._get_inspire_dict(flh.observables, ml)
             for i, obs in enumerate(flh.observables):
                 info[obs]['lh_name'] = flh_name
                 info[obs]['name'] = obs if isinstance(obs, str) else obs[0]
                 info[obs]['theory'] = pred[obs]
                 info[obs]['th. unc.'] = np.sqrt(sm_cov[i, i])
                 info[obs]['experiment'] = m.get_central(obs)
                 info[obs]['exp. unc.'] = np.sqrt(exp_cov[i, i])
                 info[obs]['exp. PDF'] = NormalDistribution(
                     m.get_central(obs), np.sqrt(exp_cov[i, i]))
                 info[obs]['inspire'] = sorted(set(inspire_dict[obs]))
                 ll_central = m.get_logprobability_single(
                     obs, m.get_central(obs))
                 ll = m.get_logprobability_single(obs, pred[obs])
                 # DeltaChi2 is -2*DeltaLogLikelihood
                 info[obs]['pull'] = pull(-2 * (ll - ll_central),
                                          dof=pull_dof)
         for lh_name, lh in llh.likelihoods.items():
             # loop over "normal" likelihoods
             ml = lh.measurement_likelihood
             pred = ml.get_predictions_par(llh.par_dict, self.w)
             inspire_dict = self._get_inspire_dict(lh.observables, ml)
             for i, obs in enumerate(lh.observables):
                 obs_dict = flavio.Observable.argument_format(obs, 'dict')
                 obs_name = obs_dict.pop('name')
                 with warnings.catch_warnings():
                     warnings.simplefilter("ignore")
                     p_comb = flavio.combine_measurements(
                         obs_name,
                         include_measurements=ml.get_measurements,
                         **obs_dict)
                 info[obs]['experiment'] = p_comb.central_value
                 info[obs]['exp. unc.'] = max(p_comb.error_left,
                                              p_comb.error_right)
                 info[obs]['exp. PDF'] = p_comb
                 info[obs]['inspire'] = sorted(set(inspire_dict[obs]))
                 info[obs]['theory'] = pred[obs]
                 info[obs]['th. unc.'] = 0
                 info[obs]['lh_name'] = lh_name
                 info[obs]['name'] = obs if isinstance(obs, str) else obs[0]
                 ll = p_comb.logpdf([pred[obs]]) - p_comb.logpdf(
                     [p_comb.central_value])
                 info[obs]['pull'] = pull(-2 * ll, dof=pull_dof)
         self._obstable_tree_cache = info
     return self._obstable_tree_cache
コード例 #4
0
ファイル: test_al.py プロジェクト: peterstangl/flavio
 def test_ae_SM(self):
     self.assertAlmostEqual(flavio.sm_prediction('a_e') / ae_SM, 1)
     pd = flavio.combine_measurements('a_e')
     ae_exp = pd.central_value
     ae_err_exp = pd.error_left
     np.random.seed(17)
     ae_err_sm = flavio.sm_uncertainty('a_e')
     # check that there is a -2.3 sigma tension, see 1804.07409 p. 13
     self.assertAlmostEqual((ae_exp - ae_SM) / sqrt(ae_err_sm**2 + ae_err_exp**2), -2.3, delta=0.5)
コード例 #5
0
 def obstable_sm(self):
     self._check_sm_cov_loaded()
     if self._obstable_sm is None:
         info = tree()  # nested dict
         for flh_name, flh in self.fast_likelihoods.items():
             # loop over fast likelihoods: they only have a single "measurement"
             m = flh.pseudo_measurement
             ml = flh.full_measurement_likelihood
             pred_sm = ml.get_predictions_par(self.par_dict_sm,
                                              flavio.WilsonCoefficients())
             sm_cov = flh.sm_covariance.get(force=False)
             _, exp_cov = flh.exp_covariance.get(force=False)
             inspire_dict = self._get_inspire_dict(flh.observables, ml)
             for i, obs in enumerate(flh.observables):
                 info[obs]['lh_name'] = flh_name
                 info[obs]['name'] = obs if isinstance(obs, str) else obs[0]
                 info[obs]['th. unc.'] = np.sqrt(sm_cov[i, i])
                 info[obs]['experiment'] = m.get_central(obs)
                 info[obs]['exp. unc.'] = np.sqrt(exp_cov[i, i])
                 info[obs]['exp. PDF'] = NormalDistribution(
                     m.get_central(obs), np.sqrt(exp_cov[i, i]))
                 info[obs]['inspire'] = sorted(set(inspire_dict[obs]))
                 info[obs]['ll_sm'] = m.get_logprobability_single(
                     obs, pred_sm[obs])
                 info[obs]['ll_central'] = m.get_logprobability_single(
                     obs, m.get_central(obs))
         for lh_name, lh in self.likelihoods.items():
             # loop over "normal" likelihoods
             ml = lh.measurement_likelihood
             pred_sm = ml.get_predictions_par(self.par_dict_sm,
                                              flavio.WilsonCoefficients())
             inspire_dict = self._get_inspire_dict(lh.observables, ml)
             for i, obs in enumerate(lh.observables):
                 obs_dict = flavio.Observable.argument_format(obs, 'dict')
                 obs_name = obs_dict.pop('name')
                 with warnings.catch_warnings():
                     warnings.simplefilter("ignore")
                     p_comb = flavio.combine_measurements(
                         obs_name,
                         include_measurements=ml.get_measurements,
                         **obs_dict)
                 info[obs]['experiment'] = p_comb.central_value
                 info[obs]['exp. unc.'] = max(p_comb.error_left,
                                              p_comb.error_right)
                 info[obs]['exp. PDF'] = p_comb
                 info[obs]['inspire'] = sorted(set(inspire_dict[obs]))
                 info[obs]['th. unc.'] = 0
                 info[obs]['lh_name'] = lh_name
                 info[obs]['name'] = obs if isinstance(obs, str) else obs[0]
                 info[obs]['ll_sm'] = p_comb.logpdf([pred_sm[obs]])
                 if info[obs]['ll_sm'] == -np.inf:
                     info[obs]['ll_sm'] = -1e100
                 info[obs]['ll_central'] = p_comb.logpdf(
                     [p_comb.central_value])
         self._obstable_sm = info
     return self._obstable_sm
コード例 #6
0
 def test_ae_SM(self):
     self.assertAlmostEqual(flavio.sm_prediction('a_e') / ae_SM, 1)
     pd = flavio.combine_measurements('a_e')
     ae_exp = pd.central_value
     ae_err_exp = pd.error_left
     np.random.seed(17)
     ae_err_sm = flavio.sm_uncertainty('a_e')
     # check that there is a -2.3 sigma tension, see 1804.07409 p. 13
     self.assertAlmostEqual(
         (ae_exp - ae_SM) / sqrt(ae_err_sm**2 + ae_err_exp**2),
         -2.3,
         delta=0.5)
コード例 #7
0
 def test_exp(self):
     self.assertAlmostEqual(flavio.combine_measurements('tau_Bc').central_value
                            / par['tau_Bc'], 1,
                            delta=0.001)