def test_log_pdf(xscale: Scale): normed_test_loc = 0.5 normed_test_s = 0.1 test_loc = xscale.denormalize_point(normed_test_loc) test_s = normed_test_s * xscale.width ergoLogisticMixture = LogisticMixture( components=[ Logistic( loc=xscale.denormalize_point(0.2), s=0.5 * xscale.width, scale=xscale, ), Logistic(loc=test_loc, s=test_s, scale=xscale), ], probs=[1.8629593e-29, 1.0], ) ergoLogistic = Logistic(loc=test_loc, s=test_s, scale=xscale) ## Test PDF normed_scipydist = scipy.stats.logistic(normed_test_loc, normed_test_s) for x in np.linspace(0, 1, 10): denormalized_x = xscale.denormalize_point(x) assert (normed_scipydist.pdf(x) / xscale.width == pytest.approx( float(ergoLogistic.pdf(denormalized_x)), rel=1e-3) == pytest.approx(float(ergoLogisticMixture.pdf(denormalized_x)), rel=1e-3))
def test_pdf(xscale: Scale): normed_test_loc = 0.5 normed_test_s = 0.1 test_loc = xscale.denormalize_point(normed_test_loc) test_s = normed_test_s * xscale.width ergoLogisticMixture = LogisticMixture( components=[ Logistic( loc=xscale.denormalize_point(0.2), s=0.5 * xscale.width, scale=xscale, ), Logistic(loc=test_loc, s=test_s, scale=xscale), ], probs=[1.8629593e-29, 1.0], ) ergoLogistic = Logistic(loc=test_loc, s=test_s, scale=xscale) ## Make sure it integrates to 1 _xs = xscale.denormalize_points(np.linspace(0, 1, 100)) densities_logistic = np.array([float(ergoLogistic.pdf(x)) for x in _xs]) densities_mixture = np.array( [float(ergoLogisticMixture.pdf(x)) for x in _xs]) auc_logistic = float(trapz(densities_logistic, x=_xs)) auc_mixture = float(trapz(densities_mixture, x=_xs)) assert (1 == pytest.approx(auc_logistic, abs=0.03) == pytest.approx( auc_mixture, abs=0.03)) if not isinstance(xscale, LogScale): scipydist = scipy.stats.logistic(test_loc, test_s) for x in np.linspace(xscale.denormalize_point(0), xscale.denormalize_point(1), 10): assert (scipydist.pdf(x) == pytest.approx( float(ergoLogistic.pdf(x)), rel=1e-3) == pytest.approx( float(ergoLogisticMixture.pdf(x)), rel=1e-3))