test_math_tools.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:py-prng 作者: czechnology 项目源码 文件源码
def test_incomplete_gamma_upper(self):
        """Test the upper incomplete gamma function approximation against pre-computed values."""

        # Pre-computed values from Octave, generated with:
        #   for a=1:10 for x=1:10
        #       printf("(%d,%d,%.7f),", a, x, gammainc(x,a,'upper')*gamma(a))
        #   endfor endfor
        values_table = (
            (1, 1, 0.3678794), (1, 2, 0.1353353), (1, 3, 0.0497871), (1, 4, 0.0183156),
            (1, 5, 0.0067379), (1, 6, 0.0024788), (1, 7, 0.0009119), (1, 8, 0.0003355),
            (1, 9, 0.0001234), (1, 10, 0.0000454), (2, 1, 0.7357589), (2, 2, 0.4060058),
            (2, 3, 0.1991483), (2, 4, 0.0915782), (2, 5, 0.0404277), (2, 6, 0.0173513),
            (2, 7, 0.0072951), (2, 8, 0.0030192), (2, 9, 0.0012341), (2, 10, 0.0004994),
            (3, 1, 1.8393972), (3, 2, 1.3533528), (3, 3, 0.8463802), (3, 4, 0.4762066),
            (3, 5, 0.2493040), (3, 6, 0.1239376), (3, 7, 0.0592723), (3, 8, 0.0275079),
            (3, 9, 0.0124644), (3, 10, 0.0055388), (4, 1, 5.8860711), (4, 2, 5.1427408),
            (4, 3, 3.8833913), (4, 4, 2.6008207), (4, 5, 1.5901555), (4, 6, 0.9072233),
            (4, 7, 0.4905925), (4, 8, 0.2542807), (4, 9, 0.1273589), (4, 10, 0.0620163),
            (5, 1, 23.9121637), (5, 2, 22.7363276), (5, 3, 19.5663179), (5, 4, 15.0920864),
            (5, 5, 10.5718388), (5, 6, 6.8413560), (5, 7, 4.1517986), (5, 8, 2.3911776),
            (5, 9, 1.3191274), (5, 10, 0.7020645), (6, 1, 119.9286978), (6, 2, 118.0123670),
            (6, 3, 109.9298470), (6, 4, 94.2156464), (6, 5, 73.9152786), (6, 6, 53.4815570),
            (6, 7, 36.0849931), (6, 8, 22.9483274), (6, 9, 13.8828625), (6, 10, 8.0503155),
            (7, 1, 719.9400664), (7, 2, 716.7356600), (7, 3, 695.8738546), (7, 4, 640.3147356),
            (7, 5, 548.7720933), (7, 6, 436.5380033), (7, 7, 323.7919602), (7, 8, 225.6294798),
            (7, 9, 148.8822047), (7, 10, 93.7018230), (8, 1, 5039.9483440), (8, 2, 5034.4725364),
            (8, 3, 4980.0013006), (8, 4, 4782.2865764), (8, 5, 4367.8067627), (8, 6, 3749.6579927),
            (8, 7, 3017.5177310), (8, 8, 2282.9224798), (8, 9, 1632.4407001), (8, 10, 1109.9120589),
            (9, 1, 40319.9546318), (9, 2, 40310.4261237), (9, 3, 40166.6633601),
            (9, 4, 39458.6263214), (9, 5, 37574.4646480), (9, 6, 34160.6157575),
            (9, 7, 29396.9599152), (9, 8, 23891.5088068), (9, 9, 18371.9130063),
            (9, 10, 13419.2894472), (10, 1, 362879.9595659), (10, 2, 362863.1267785),
            (10, 3, 362479.9291073), (10, 4, 359928.9717338), (10, 5, 351330.2345647),
            (10, 6, 332425.6527129), (10, 7, 301370.3657052), (10, 8, 260048.6110069),
            (10, 9, 213158.7037032), (10, 10, 166173.5347875)
        )

        for a, x, inc_gam_value in values_table:
            self.assertAlmostEqual(incomplete_gamma_upper(a, x), inc_gam_value,
                                   places=min(7, int(6 - log10(inc_gam_value))))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号