Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
18ee50d5
Kaydet (Commit)
18ee50d5
authored
Mar 06, 2019
tarafından
Raymond Hettinger
Kaydeden (comit)
Miss Islington (bot)
Mar 06, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add more tests for pdf() and cdf() (GH-12190)
üst
4fffd380
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
3 deletions
+29
-3
test_statistics.py
Lib/test/test_statistics.py
+29
-3
No files found.
Lib/test/test_statistics.py
Dosyayı görüntüle @
18ee50d5
...
@@ -2101,14 +2101,28 @@ class TestNormalDist(unittest.TestCase):
...
@@ -2101,14 +2101,28 @@ class TestNormalDist(unittest.TestCase):
self
.
assertLess
(
X
.
pdf
(
99
),
X
.
pdf
(
100
))
self
.
assertLess
(
X
.
pdf
(
99
),
X
.
pdf
(
100
))
self
.
assertLess
(
X
.
pdf
(
101
),
X
.
pdf
(
100
))
self
.
assertLess
(
X
.
pdf
(
101
),
X
.
pdf
(
100
))
# Test symmetry
# Test symmetry
self
.
assertAlmostEqual
(
X
.
pdf
(
99
),
X
.
pdf
(
101
))
for
i
in
range
(
50
):
self
.
assertAlmostEqual
(
X
.
pdf
(
98
),
X
.
pdf
(
102
))
self
.
assertAlmostEqual
(
X
.
pdf
(
100
-
i
),
X
.
pdf
(
100
+
i
))
self
.
assertAlmostEqual
(
X
.
pdf
(
97
),
X
.
pdf
(
103
))
# Test vs CDF
# Test vs CDF
dx
=
2.0
**
-
10
dx
=
2.0
**
-
10
for
x
in
range
(
90
,
111
):
for
x
in
range
(
90
,
111
):
est_pdf
=
(
X
.
cdf
(
x
+
dx
)
-
X
.
cdf
(
x
))
/
dx
est_pdf
=
(
X
.
cdf
(
x
+
dx
)
-
X
.
cdf
(
x
))
/
dx
self
.
assertAlmostEqual
(
X
.
pdf
(
x
),
est_pdf
,
places
=
4
)
self
.
assertAlmostEqual
(
X
.
pdf
(
x
),
est_pdf
,
places
=
4
)
# Test vs table of known values -- CRC 26th Edition
Z
=
NormalDist
()
for
x
,
px
in
enumerate
([
0.3989
,
0.3989
,
0.3989
,
0.3988
,
0.3986
,
0.3984
,
0.3982
,
0.3980
,
0.3977
,
0.3973
,
0.3970
,
0.3965
,
0.3961
,
0.3956
,
0.3951
,
0.3945
,
0.3939
,
0.3932
,
0.3925
,
0.3918
,
0.3910
,
0.3902
,
0.3894
,
0.3885
,
0.3876
,
0.3867
,
0.3857
,
0.3847
,
0.3836
,
0.3825
,
0.3814
,
0.3802
,
0.3790
,
0.3778
,
0.3765
,
0.3752
,
0.3739
,
0.3725
,
0.3712
,
0.3697
,
0.3683
,
0.3668
,
0.3653
,
0.3637
,
0.3621
,
0.3605
,
0.3589
,
0.3572
,
0.3555
,
0.3538
,
]):
self
.
assertAlmostEqual
(
Z
.
pdf
(
x
/
100.0
),
px
,
places
=
4
)
# Error case: variance is zero
# Error case: variance is zero
Y
=
NormalDist
(
100
,
0
)
Y
=
NormalDist
(
100
,
0
)
with
self
.
assertRaises
(
statistics
.
StatisticsError
):
with
self
.
assertRaises
(
statistics
.
StatisticsError
):
...
@@ -2127,6 +2141,18 @@ class TestNormalDist(unittest.TestCase):
...
@@ -2127,6 +2141,18 @@ class TestNormalDist(unittest.TestCase):
self
.
assertEqual
(
cdfs
,
sorted
(
cdfs
))
self
.
assertEqual
(
cdfs
,
sorted
(
cdfs
))
# Verify center
# Verify center
self
.
assertAlmostEqual
(
X
.
cdf
(
100
),
0.50
)
self
.
assertAlmostEqual
(
X
.
cdf
(
100
),
0.50
)
# Check against a table of known values
# https://en.wikipedia.org/wiki/Standard_normal_table#Cumulative
Z
=
NormalDist
()
for
z
,
cum_prob
in
[
(
0.00
,
0.50000
),
(
0.01
,
0.50399
),
(
0.02
,
0.50798
),
(
0.14
,
0.55567
),
(
0.29
,
0.61409
),
(
0.33
,
0.62930
),
(
0.54
,
0.70540
),
(
0.60
,
0.72575
),
(
1.17
,
0.87900
),
(
1.60
,
0.94520
),
(
2.05
,
0.97982
),
(
2.89
,
0.99807
),
(
3.52
,
0.99978
),
(
3.98
,
0.99997
),
(
4.07
,
0.99998
),
]:
self
.
assertAlmostEqual
(
Z
.
cdf
(
z
),
cum_prob
,
places
=
5
)
self
.
assertAlmostEqual
(
Z
.
cdf
(
-
z
),
1.0
-
cum_prob
,
places
=
5
)
# Error case: variance is zero
# Error case: variance is zero
Y
=
NormalDist
(
100
,
0
)
Y
=
NormalDist
(
100
,
0
)
with
self
.
assertRaises
(
statistics
.
StatisticsError
):
with
self
.
assertRaises
(
statistics
.
StatisticsError
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment