コード例 #1
0
ファイル: test_edgeworth.py プロジェクト: hiroshi8/edgeworth
    def test_chi2_moments(self):
        # construct the expansion for \chi^2
        N, df = 6, 15
        cum = [_chi2_cumulant(n+1, df) for n in range(N)]
        ne = ExpandedNormal(cum, name='edgw_chi2')

        # compare the moments
        assert_allclose([_chi2_moment(n, df) for n in range(N)],
                        [ne.moment(n) for n in range(N)])

        # compate the pdf
        m, s = df, np.sqrt(2*df)
        x = np.linspace(m - s, m + s, 10)
        assert_allclose(ne.pdf(x), stats.chi2.pdf(x, df=df),
                atol=1e-4, rtol=1e-5)

        # pdf-cdf roundtrip
        check_pdf(ne, arg=(), msg='')

        # cdf-ppf roundtrip
        check_cdf_ppf(ne, arg=(), msg='')

        # cdf + sf == 1
        check_cdf_sf(ne, arg=(), msg='')

        # generate rvs & run a KS test
        np.random.seed(765456)
        rvs = ne.rvs(size=500)
        check_distribution_rvs(ne, args=(), alpha=0.01, rvs=rvs)
コード例 #2
0
ファイル: test_edgeworth.py プロジェクト: hiroshi8/edgeworth
 def test_normal(self):
     # with two cumulants, it's just a gaussian
     ne2 = ExpandedNormal([3, 4])
     x = np.linspace(-2., 2., 100)
     assert_allclose(ne2.pdf(x), stats.norm.pdf(x, loc=3, scale=2))