def test_cdf(self): sim_model = EconDensity() x = np.ones(shape=(2000, 1)) y = np.random.uniform(0.01, 5, size=(2000, 1)) p_sim = sim_model.cdf(x, y) p_true = stats.norm.cdf(y, loc=1, scale=2) diff = np.sum(np.abs(p_sim - p_true)) self.assertAlmostEquals(diff, 0.0, places=2)
def test_cdf_sample_consistency(self): from statsmodels.distributions.empirical_distribution import ECDF model = EconDensity() x_cond = np.asarray([0.1 for _ in range(200000)]) _, y_sample = model.simulate_conditional(x_cond) emp_cdf = ECDF(y_sample.flatten()) cdf = lambda y: model.cdf(x_cond, y) mean_cdf_diff = np.mean( np.abs(emp_cdf(y_sample).flatten() - cdf(y_sample).flatten())) self.assertLessEqual(mean_cdf_diff, 0.01)