def test_get_model_mfd_noncum(self): mod_mfd = get_model_mfd(self.bin_gdf) mod_mfd_res = { 6.0: 0.0814075600000007, 6.2: 0.1160290199999997, 6.4: 0.0732093600000006, 6.6: 0.04619198000000058, 6.8: 0.02914517000000005, 7.0: 0.01838935999999996, 7.2: 0.011602900000000006, 7.4: 0.007320929999999995, 7.6: 0.004619199999999999, 7.8: 0.00162429, 8.0: 0, 8.2: 0, 8.4: 0, 8.6: 0, 8.8: 0, 9.0: 0, 9.2: 0, } for k, v in mod_mfd.items(): np.testing.assert_almost_equal(v, mod_mfd_res[k])
def test_get_model_mfd_cum(self): mod_mfd = get_model_mfd(self.bin_gdf, cumulative=True) mod_mfd_res = { 6.0: 0.38953977, 6.2: 0.30813221, 6.4: 0.19210319, 6.6: 0.11889383, 6.8: 0.07270185, 7.0: 0.04355668, 7.2: 0.02516732, 7.4: 0.01356442, 7.6: 0.00624349, 7.8: 0.00162429, 8.0: 0, 8.2: 0, 8.4: 0, 8.6: 0, 8.8: 0, 9.0: 0, 9.2: 0, } for k, v in mod_mfd.items(): np.testing.assert_almost_equal(v, mod_mfd_res[k])
def m_test_function( bin_gdf, t_yrs: float, n_iters: int, prospective=False, not_modeled_likelihood: float = 0.0, critical_pct: float = 0.25, ): # get model and observed MFDs mod_mfd = get_model_mfd(bin_gdf) obs_mfd = get_obs_mfd(bin_gdf, t_yrs, prospective) # calculate log-likelihoods n_bins = len(mod_mfd.keys()) stochastic_eq_counts = { bc: np.random.poisson((rate * t_yrs), size=n_iters) for bc, rate in mod_mfd.items() } bin_log_likelihoods = { bc: [ poisson_log_likelihood( n_stoch, (mod_mfd[bc] * t_yrs), not_modeled_val=not_modeled_likelihood, ) for n_stoch in eq_counts ] for bc, eq_counts in stochastic_eq_counts.items() } stoch_geom_mean_likes = np.array([ np.exp( np.sum([bll_mag[i] for bll_mag in bin_log_likelihoods.values()]) / n_bins) for i in range(n_iters) ]) obs_geom_mean_like = np.exp( np.sum([ poisson_log_likelihood( int(obs_mfd[bc] * t_yrs), rate * t_yrs, ) for bc, rate in mod_mfd.items() ]) / n_bins) pctile = (len( stoch_geom_mean_likes[stoch_geom_mean_likes <= obs_geom_mean_like]) / n_iters) test_pass = True if pctile >= critical_pct else False test_res = "Pass" if test_pass else "Fail" test_result = { "critical_pct": critical_pct, "percentile": pctile, "test_pass": test_pass, "test_res": test_res, } return test_result