def test_incomplete_gamma_lower(self):
"""Test the lower 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)*gamma(a)) endfor endfor
values_table = (
(1, 1, 0.6321206), (1, 2, 0.8646647), (1, 3, 0.9502129), (1, 4, 0.9816844),
(1, 5, 0.9932621), (1, 6, 0.9975212), (1, 7, 0.9990881), (1, 8, 0.9996645),
(1, 9, 0.9998766), (1, 10, 0.9999546), (2, 1, 0.2642411), (2, 2, 0.5939942),
(2, 3, 0.8008517), (2, 4, 0.9084218), (2, 5, 0.9595723), (2, 6, 0.9826487),
(2, 7, 0.9927049), (2, 8, 0.9969808), (2, 9, 0.9987659), (2, 10, 0.9995006),
(3, 1, 0.1606028), (3, 2, 0.6466472), (3, 3, 1.1536198), (3, 4, 1.5237934),
(3, 5, 1.7506960), (3, 6, 1.8760624), (3, 7, 1.9407277), (3, 8, 1.9724921),
(3, 9, 1.9875356), (3, 10, 1.9944612), (4, 1, 0.1139289), (4, 2, 0.8572592),
(4, 3, 2.1166087), (4, 4, 3.3991793), (4, 5, 4.4098445), (4, 6, 5.0927767),
(4, 7, 5.5094075), (4, 8, 5.7457193), (4, 9, 5.8726411), (4, 10, 5.9379837),
(5, 1, 0.0878363), (5, 2, 1.2636724), (5, 3, 4.4336821), (5, 4, 8.9079136),
(5, 5, 13.4281612), (5, 6, 17.1586440), (5, 7, 19.8482014), (5, 8, 21.6088224),
(5, 9, 22.6808726), (5, 10, 23.2979355), (6, 1, 0.0713022), (6, 2, 1.9876330),
(6, 3, 10.0701530), (6, 4, 25.7843536), (6, 5, 46.0847214), (6, 6, 66.5184430),
(6, 7, 83.9150069), (6, 8, 97.0516726), (6, 9, 106.1171375), (6, 10, 111.9496845),
(7, 1, 0.0599336), (7, 2, 3.2643400), (7, 3, 24.1261454), (7, 4, 79.6852644),
(7, 5, 171.2279067), (7, 6, 283.4619967), (7, 7, 396.2080398), (7, 8, 494.3705202),
(7, 9, 571.1177953), (7, 10, 626.2981770), (8, 1, 0.0516560), (8, 2, 5.5274636),
(8, 3, 59.9986994), (8, 4, 257.7134236), (8, 5, 672.1932373), (8, 6, 1290.3420073),
(8, 7, 2022.4822690), (8, 8, 2757.0775202), (8, 9, 3407.5592999), (8, 10, 3930.0879411),
(9, 1, 0.0453682), (9, 2, 9.5738763), (9, 3, 153.3366399), (9, 4, 861.3736786),
(9, 5, 2745.5353520), (9, 6, 6159.3842425), (9, 7, 10923.0400848),
(9, 8, 16428.4911932), (9, 9, 21948.0869937), (9, 10, 26900.7105528),
(10, 1, 0.0404341), (10, 2, 16.8732215), (10, 3, 400.0708927), (10, 4, 2951.0282662),
(10, 5, 11549.7654353), (10, 6, 30454.3472871), (10, 7, 61509.6342948),
(10, 8, 102831.3889931), (10, 9, 149721.2962968), (10, 10, 196706.4652125),
)
for a, x, inc_gam_value in values_table:
self.assertAlmostEqual(incomplete_gamma_lower(a, x), inc_gam_value,
places=min(7, int(6 - log10(inc_gam_value))))
评论列表
文章目录