@@ -2101,14 +2101,28 @@ def test_pdf(self):
2101
2101
self .assertLess (X .pdf (99 ), X .pdf (100 ))
2102
2102
self .assertLess (X .pdf (101 ), X .pdf (100 ))
2103
2103
# Test symmetry
2104
- self .assertAlmostEqual (X .pdf (99 ), X .pdf (101 ))
2105
- self .assertAlmostEqual (X .pdf (98 ), X .pdf (102 ))
2106
- self .assertAlmostEqual (X .pdf (97 ), X .pdf (103 ))
2104
+ for i in range (50 ):
2105
+ self .assertAlmostEqual (X .pdf (100 - i ), X .pdf (100 + i ))
2107
2106
# Test vs CDF
2108
2107
dx = 2.0 ** - 10
2109
2108
for x in range (90 , 111 ):
2110
2109
est_pdf = (X .cdf (x + dx ) - X .cdf (x )) / dx
2111
2110
self .assertAlmostEqual (X .pdf (x ), est_pdf , places = 4 )
2111
+ # Test vs table of known values -- CRC 26th Edition
2112
+ Z = NormalDist ()
2113
+ for x , px in enumerate ([
2114
+ 0.3989 , 0.3989 , 0.3989 , 0.3988 , 0.3986 ,
2115
+ 0.3984 , 0.3982 , 0.3980 , 0.3977 , 0.3973 ,
2116
+ 0.3970 , 0.3965 , 0.3961 , 0.3956 , 0.3951 ,
2117
+ 0.3945 , 0.3939 , 0.3932 , 0.3925 , 0.3918 ,
2118
+ 0.3910 , 0.3902 , 0.3894 , 0.3885 , 0.3876 ,
2119
+ 0.3867 , 0.3857 , 0.3847 , 0.3836 , 0.3825 ,
2120
+ 0.3814 , 0.3802 , 0.3790 , 0.3778 , 0.3765 ,
2121
+ 0.3752 , 0.3739 , 0.3725 , 0.3712 , 0.3697 ,
2122
+ 0.3683 , 0.3668 , 0.3653 , 0.3637 , 0.3621 ,
2123
+ 0.3605 , 0.3589 , 0.3572 , 0.3555 , 0.3538 ,
2124
+ ]):
2125
+ self .assertAlmostEqual (Z .pdf (x / 100.0 ), px , places = 4 )
2112
2126
# Error case: variance is zero
2113
2127
Y = NormalDist (100 , 0 )
2114
2128
with self .assertRaises (statistics .StatisticsError ):
@@ -2127,6 +2141,18 @@ def test_cdf(self):
2127
2141
self .assertEqual (cdfs , sorted (cdfs ))
2128
2142
# Verify center
2129
2143
self .assertAlmostEqual (X .cdf (100 ), 0.50 )
2144
+ # Check against a table of known values
2145
+ # https://en.wikipedia.org/wiki/Standard_normal_table#Cumulative
2146
+ Z = NormalDist ()
2147
+ for z , cum_prob in [
2148
+ (0.00 , 0.50000 ), (0.01 , 0.50399 ), (0.02 , 0.50798 ),
2149
+ (0.14 , 0.55567 ), (0.29 , 0.61409 ), (0.33 , 0.62930 ),
2150
+ (0.54 , 0.70540 ), (0.60 , 0.72575 ), (1.17 , 0.87900 ),
2151
+ (1.60 , 0.94520 ), (2.05 , 0.97982 ), (2.89 , 0.99807 ),
2152
+ (3.52 , 0.99978 ), (3.98 , 0.99997 ), (4.07 , 0.99998 ),
2153
+ ]:
2154
+ self .assertAlmostEqual (Z .cdf (z ), cum_prob , places = 5 )
2155
+ self .assertAlmostEqual (Z .cdf (- z ), 1.0 - cum_prob , places = 5 )
2130
2156
# Error case: variance is zero
2131
2157
Y = NormalDist (100 , 0 )
2132
2158
with self .assertRaises (statistics .StatisticsError ):
0 commit comments