def test_kde_1d():
    np.random.seed(8765678)
    n_basesample = 500
    xn = np.random.randn(n_basesample)
    xnmean = xn.mean()
    xnstd = xn.std(ddof=1)
    print(xnmean, xnstd)
    gkde = stats.gaussian_kde(xn)
    xs = np.linspace((- 7), 7, 501)
    kdepdf = gkde.evaluate(xs)
    normpdf = stats.norm.pdf(xs, loc=xnmean, scale=xnstd)
    print('MSE', np.sum(((kdepdf - normpdf) ** 2)))
    print('axabserror', np.max(np.abs((kdepdf - normpdf))))
    intervall = (xs[1] - xs[0])
    assert_(((np.sum(((kdepdf - normpdf) ** 2)) * intervall) < 0.01))
    print(gkde.integrate_gaussian(0.0, 1.0))
    print(gkde.integrate_box_1d((- np.inf), 0.0))
    print(gkde.integrate_box_1d(0.0, np.inf))
    print(gkde.integrate_box_1d((- np.inf), xnmean))
    print(gkde.integrate_box_1d(xnmean, np.inf))
    assert_almost_equal(gkde.integrate_box_1d(xnmean, np.inf), 0.5, decimal=1)
    assert_almost_equal(gkde.integrate_box_1d((- np.inf), xnmean), 0.5, decimal=1)
    assert_almost_equal(gkde.integrate_box(xnmean, np.inf), 0.5, decimal=1)
    assert_almost_equal(gkde.integrate_box((- np.inf), xnmean), 0.5, decimal=1)
    assert_almost_equal(gkde.integrate_kde(gkde), ((kdepdf ** 2).sum() * intervall), decimal=2)
    assert_almost_equal(gkde.integrate_gaussian(xnmean, (xnstd ** 2)), ((kdepdf * normpdf).sum() * intervall), decimal=2)
def test_kde_1d():
    np.random.seed(8765678)
    n_basesample = 500
    xn = np.random.randn(n_basesample)
    xnmean = xn.mean()
    xnstd = xn.std(ddof=1)
    print(xnmean, xnstd)
    gkde = stats.gaussian_kde(xn)
    xs = np.linspace((- 7), 7, 501)
    kdepdf = gkde.evaluate(xs)
    normpdf = stats.norm.pdf(xs, loc=xnmean, scale=xnstd)
    print('MSE', np.sum(((kdepdf - normpdf) ** 2)))
    print('axabserror', np.max(np.abs((kdepdf - normpdf))))
    intervall = (xs[1] - xs[0])
    assert_(((np.sum(((kdepdf - normpdf) ** 2)) * intervall) < 0.01))
    print(gkde.integrate_gaussian(0.0, 1.0))
    print(gkde.integrate_box_1d((- np.inf), 0.0))
    print(gkde.integrate_box_1d(0.0, np.inf))
    print(gkde.integrate_box_1d((- np.inf), xnmean))
    print(gkde.integrate_box_1d(xnmean, np.inf))
    assert_almost_equal(gkde.integrate_box_1d(xnmean, np.inf), 0.5, decimal=1)
    assert_almost_equal(gkde.integrate_box_1d((- np.inf), xnmean), 0.5, decimal=1)
    assert_almost_equal(gkde.integrate_box(xnmean, np.inf), 0.5, decimal=1)
    assert_almost_equal(gkde.integrate_box((- np.inf), xnmean), 0.5, decimal=1)
    assert_almost_equal(gkde.integrate_kde(gkde), ((kdepdf ** 2).sum() * intervall), decimal=2)
    assert_almost_equal(gkde.integrate_gaussian(xnmean, (xnstd ** 2)), ((kdepdf * normpdf).sum() * intervall), decimal=2)