|
1
|
|
|
# Copyright (c) 2014, Salesforce.com, Inc. All rights reserved. |
|
2
|
|
|
# Copyright (c) 2015, Gamelan Labs, Inc. |
|
3
|
|
|
# Copyright (c) 2016, Google, Inc. |
|
4
|
|
|
# Copyright (c) 2016, Gamelan Labs, Inc. |
|
5
|
|
|
# |
|
6
|
|
|
# Redistribution and use in source and binary forms, with or without |
|
7
|
|
|
# modification, are permitted provided that the following conditions |
|
8
|
|
|
# are met: |
|
9
|
|
|
# |
|
10
|
|
|
# - Redistributions of source code must retain the above copyright |
|
11
|
|
|
# notice, this list of conditions and the following disclaimer. |
|
12
|
|
|
# - Redistributions in binary form must reproduce the above copyright |
|
13
|
|
|
# notice, this list of conditions and the following disclaimer in the |
|
14
|
|
|
# documentation and/or other materials provided with the distribution. |
|
15
|
|
|
# - Neither the name of Salesforce.com nor the names of its contributors |
|
16
|
|
|
# may be used to endorse or promote products derived from this |
|
17
|
|
|
# software without specific prior written permission. |
|
18
|
|
|
# |
|
19
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
20
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
21
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
22
|
|
|
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
23
|
|
|
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
24
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
25
|
|
|
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
|
26
|
|
|
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
27
|
|
|
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
|
28
|
|
|
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
|
29
|
|
|
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
30
|
|
|
from __future__ import division |
|
31
|
|
|
try: |
|
32
|
|
|
from itertools import izip as zip |
|
33
|
|
|
except ImportError: |
|
34
|
|
|
pass |
|
35
|
|
|
from itertools import product |
|
36
|
|
|
import random |
|
37
|
|
|
from unittest import skip |
|
38
|
|
|
from unittest import TestCase |
|
39
|
|
|
|
|
40
|
|
|
import numpy |
|
41
|
|
|
import scipy.stats |
|
42
|
|
|
from numpy import pi |
|
43
|
|
|
from numpy.testing import rand |
|
44
|
|
|
|
|
45
|
|
|
from goftests import get_dim |
|
46
|
|
|
from goftests import multinomial_goodness_of_fit |
|
47
|
|
|
from goftests import discrete_goodness_of_fit |
|
48
|
|
|
from goftests import auto_density_goodness_of_fit |
|
49
|
|
|
from goftests import mixed_density_goodness_of_fit |
|
50
|
|
|
from goftests import split_discrete_continuous |
|
51
|
|
|
from goftests import volume_of_sphere |
|
52
|
|
|
from goftests import chi2sf |
|
53
|
|
|
|
|
54
|
|
|
NUM_BASE_SAMPLES = 250 |
|
55
|
|
|
|
|
56
|
|
|
NUM_SAMPLES_SCALE = 1000 |
|
57
|
|
|
|
|
58
|
|
|
TEST_FAILURE_RATE = 5e-4 |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
class TestMultinomialGoodnessOfFit(TestCase): |
|
62
|
|
|
|
|
63
|
|
|
def test_multinomial_goodness_of_fit(self): |
|
64
|
|
|
random.seed(0) |
|
65
|
|
|
numpy.random.seed(0) |
|
66
|
|
|
for dim in range(2, 20): |
|
67
|
|
|
sample_count = int(1e5) |
|
68
|
|
|
probs = numpy.random.dirichlet([1] * dim) |
|
69
|
|
|
|
|
70
|
|
|
counts = numpy.random.multinomial(sample_count, probs) |
|
71
|
|
|
p_good = multinomial_goodness_of_fit(probs, counts, sample_count) |
|
72
|
|
|
self.assertGreater(p_good, TEST_FAILURE_RATE) |
|
73
|
|
|
|
|
74
|
|
|
unif = [1 / dim] * dim |
|
75
|
|
|
unif_counts = numpy.random.multinomial(sample_count, unif) |
|
76
|
|
|
p_bad = multinomial_goodness_of_fit(probs, unif_counts, |
|
77
|
|
|
sample_count) |
|
78
|
|
|
self.assertLess(p_bad, TEST_FAILURE_RATE) |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
class TestVolumeOfSphere(TestCase): |
|
82
|
|
|
|
|
83
|
|
|
def test_volume_of_sphere(self): |
|
84
|
|
|
for r in [0.1, 1.0, 10.0]: |
|
85
|
|
|
self.assertAlmostEqual(volume_of_sphere(1, r), 2 * r) |
|
86
|
|
|
self.assertAlmostEqual(volume_of_sphere(2, r), pi * r ** 2) |
|
87
|
|
|
self.assertAlmostEqual(volume_of_sphere(3, r), 4 / 3 * pi * r ** 3) |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
SPLIT_EXAMPLES = [ |
|
91
|
|
|
(False, False, []), |
|
92
|
|
|
(0, 0, []), |
|
93
|
|
|
('abc', 'abc', []), |
|
94
|
|
|
(0.0, None, [0.0]), |
|
95
|
|
|
((), (), []), |
|
96
|
|
|
([], (), []), |
|
97
|
|
|
((0, ), (0, ), []), |
|
98
|
|
|
([0], (0, ), []), |
|
99
|
|
|
((0.0, ), (None, ), [0.0]), |
|
100
|
|
|
([0.0], (None, ), [0.0]), |
|
101
|
|
|
([True, 1, 'xyz', 3.14, [None, (), ([2.71],)]], |
|
102
|
|
|
(True, 1, 'xyz', None, (None, (), ((None,),))), |
|
103
|
|
|
[3.14, 2.71]), |
|
104
|
|
|
(numpy.zeros(3), (None, None, None), [0.0, 0.0, 0.0]), |
|
105
|
|
|
] |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
class TestSplitDiscreteContinuous(TestCase): |
|
109
|
|
|
|
|
110
|
|
|
def test_split_continuous_discrete(self): |
|
111
|
|
|
for mixed, discrete, continuous in SPLIT_EXAMPLES: |
|
112
|
|
|
d, c = split_discrete_continuous(mixed) |
|
113
|
|
|
self.assertEqual(d, discrete) |
|
114
|
|
|
self.assertAlmostEqual(c, continuous) |
|
115
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
class TestChi2CDF(TestCase): |
|
118
|
|
|
|
|
119
|
|
|
def test_chi2cdf(self): |
|
120
|
|
|
xlist = numpy.linspace(0, 100, 500) |
|
121
|
|
|
slist = numpy.arange(1, 41, 1.5) |
|
122
|
|
|
for s, x in product(slist, xlist): |
|
123
|
|
|
self.assertAlmostEqual(scipy.stats.chi2.sf(x, s), chi2sf(x, s)) |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
class DistributionTestBase(object): |
|
127
|
|
|
"""Abstract base class for probability distribution unit tests. |
|
128
|
|
|
|
|
129
|
|
|
This class supplies two test methods, :meth:`.test_goodness_of_fit` |
|
130
|
|
|
and :meth:`.test_mixed_density_goodness_of_fit` for testing the |
|
131
|
|
|
goodness of fit functions. |
|
132
|
|
|
|
|
133
|
|
|
Subclasses must override and implement one class attribute and two |
|
134
|
|
|
instance methods. The :attr:`.dist` class attribute must be set to |
|
135
|
|
|
one of SciPy probability distribution constructors in |
|
136
|
|
|
:mod:`scipy.stats`. The :meth:`.goodness_of_fit` method must return |
|
137
|
|
|
the result of calling one of the goodness of fit functions being |
|
138
|
|
|
tested. The :meth:`.probabilites` method must return an object |
|
139
|
|
|
representing the probabilities for each sample; the output depends |
|
140
|
|
|
on the format of the inputs to the :meth:`.goodness_of_fit` method. |
|
141
|
|
|
|
|
142
|
|
|
Subclasses may also set the :attr:`.params` attribute, which is a |
|
143
|
|
|
list of tuples that will be provided as arguments to the underlying |
|
144
|
|
|
SciPy distribution constructor as specified in :attr:`.dist`. If not |
|
145
|
|
|
specified, random arguments will be provided. |
|
146
|
|
|
|
|
147
|
|
|
If samples drawn from :attr:`.dist` must be modified in some way |
|
148
|
|
|
before the PDF or PMF can be computed, then subclasses may override |
|
149
|
|
|
the :meth:`._sample_postprocessing` method. |
|
150
|
|
|
|
|
151
|
|
|
""" |
|
152
|
|
|
|
|
153
|
|
|
#: The SciPy distribution constructor to test. |
|
154
|
|
|
dist = None |
|
155
|
|
|
|
|
156
|
|
|
#: An optional list of arguments to the distribution constructor. |
|
157
|
|
|
#: |
|
158
|
|
|
#: Each tuple in this list will be provided as the positional |
|
159
|
|
|
#: arguments to the distribution constructor specified in |
|
160
|
|
|
#: :attr:`.dist`. If not specified, random arguments will be |
|
161
|
|
|
#: provided. |
|
162
|
|
|
params = None |
|
163
|
|
|
|
|
164
|
|
|
def setUp(self): |
|
165
|
|
|
random.seed(0) |
|
166
|
|
|
numpy.random.seed(0) |
|
167
|
|
|
|
|
168
|
|
|
def _sample_postprocessing(self, sample): |
|
169
|
|
|
"""Modify a sample drawn from the distribution. |
|
170
|
|
|
|
|
171
|
|
|
This method returns a modified version of `sample`, but that |
|
172
|
|
|
modification may be arbitrary. This modified sample is the one |
|
173
|
|
|
for which the PDF and the goodness-of-fit are computed. |
|
174
|
|
|
|
|
175
|
|
|
By default, this is a no-op, but subclasses may wish to override |
|
176
|
|
|
this method to modify sample in some way. |
|
177
|
|
|
|
|
178
|
|
View Code Duplication |
""" |
|
|
|
|
|
|
179
|
|
|
return sample |
|
180
|
|
|
|
|
181
|
|
|
def dist_params(self): |
|
182
|
|
|
# If there are no parameters, then we provide a random one. |
|
183
|
|
|
if self.params is None: |
|
184
|
|
|
params = [tuple(1 + rand(self.dist.numargs))] |
|
185
|
|
|
else: |
|
186
|
|
|
params = self.params |
|
187
|
|
|
return params |
|
188
|
|
View Code Duplication |
|
|
|
|
|
|
|
189
|
|
|
def test_mixed_density_goodness_of_fit(self): |
|
190
|
|
|
for param in self.dist_params(): |
|
191
|
|
|
dim = get_dim(self.dist.rvs(*param, size=2)[0]) |
|
192
|
|
|
sample_count = NUM_BASE_SAMPLES + NUM_SAMPLES_SCALE * dim |
|
193
|
|
|
samples = self.dist.rvs(*param, size=sample_count) |
|
194
|
|
|
samples = list(map(self._sample_postprocessing, samples)) |
|
195
|
|
|
probabilities = [self.pdf(sample, *param) for sample in samples] |
|
196
|
|
|
gof = mixed_density_goodness_of_fit(samples, probabilities) |
|
197
|
|
|
self.assertGreater(gof, TEST_FAILURE_RATE) |
|
198
|
|
|
|
|
199
|
|
|
def test_good_fit(self): |
|
200
|
|
|
for param in self.dist_params(): |
|
201
|
|
|
dim = get_dim(self.dist.rvs(*param, size=2)[0]) |
|
202
|
|
|
sample_count = NUM_BASE_SAMPLES + NUM_SAMPLES_SCALE * dim |
|
203
|
|
|
samples = self.dist.rvs(*param, size=sample_count) |
|
204
|
|
|
samples = list(map(self._sample_postprocessing, samples)) |
|
205
|
|
|
probabilities = [self.pdf(sample, *param) for sample in samples] |
|
206
|
|
|
gof = self.goodness_of_fit(samples, probabilities) |
|
207
|
|
|
self.assertGreater(gof, TEST_FAILURE_RATE) |
|
208
|
|
|
|
|
209
|
|
|
def goodness_of_fit(self, samples, probabilities): |
|
210
|
|
|
raise NotImplementedError |
|
211
|
|
|
|
|
212
|
|
|
|
|
213
|
|
|
class ContinuousTestBase(DistributionTestBase): |
|
214
|
|
|
"""Abstract base class for testing continuous probability distributions. |
|
215
|
|
|
|
|
216
|
|
|
Concrete subclasses must set the :attr:`.dist` attribute to be the |
|
217
|
|
|
constructor for a continuous probability distribution. |
|
218
|
|
|
|
|
219
|
|
|
""" |
|
220
|
|
|
|
|
221
|
|
|
def goodness_of_fit(self, samples, probabilities): |
|
222
|
|
|
gof = auto_density_goodness_of_fit(samples, probabilities) |
|
223
|
|
|
return gof |
|
224
|
|
|
|
|
225
|
|
|
def pdf(self, *args, **kw): |
|
226
|
|
|
return self.dist.pdf(*args, **kw) |
|
227
|
|
|
|
|
228
|
|
|
|
|
229
|
|
|
class DiscreteTestBase(DistributionTestBase): |
|
230
|
|
|
"""Abstract base class for testing discrete probability distributions. |
|
231
|
|
|
|
|
232
|
|
|
Concrete subclasses must set the :attr:`.dist` attribute to be the |
|
233
|
|
|
constructor for a discrete probability distribution. |
|
234
|
|
|
|
|
235
|
|
|
""" |
|
236
|
|
|
|
|
237
|
|
|
def goodness_of_fit(self, samples, probabilities): |
|
238
|
|
|
probs_dict = dict(zip(samples, probabilities)) |
|
239
|
|
|
gof = discrete_goodness_of_fit(samples, probs_dict) |
|
240
|
|
|
return gof |
|
241
|
|
|
|
|
242
|
|
|
def pdf(self, *args, **kw): |
|
243
|
|
|
return self.dist.pmf(*args, **kw) |
|
244
|
|
|
|
|
245
|
|
|
|
|
246
|
|
|
# |
|
247
|
|
|
# Multivariate probability distributions. |
|
248
|
|
|
# |
|
249
|
|
|
|
|
250
|
|
|
class TestMultivariateNormal(ContinuousTestBase, TestCase): |
|
251
|
|
|
|
|
252
|
|
|
dist = scipy.stats.multivariate_normal |
|
253
|
|
|
|
|
254
|
|
|
params = [ |
|
255
|
|
|
(numpy.ones(1), numpy.eye(1)), |
|
256
|
|
|
(numpy.ones(2), numpy.eye(2)), |
|
257
|
|
|
(numpy.ones(3), numpy.eye(3)), |
|
258
|
|
|
] |
|
259
|
|
|
|
|
260
|
|
|
|
|
261
|
|
|
class TestDirichlet(ContinuousTestBase, TestCase): |
|
262
|
|
|
|
|
263
|
|
|
dist = scipy.stats.dirichlet |
|
264
|
|
|
|
|
265
|
|
|
params = [ |
|
266
|
|
|
([2.0, 2.5],), |
|
267
|
|
|
([2.0, 2.5, 3.0],), |
|
268
|
|
|
([2.0, 2.5, 3.0, 3.5],), |
|
269
|
|
|
] |
|
270
|
|
|
|
|
271
|
|
|
def _sample_postprocessing(self, value): |
|
272
|
|
|
"""Project onto all but the last dimension.""" |
|
273
|
|
|
return value[:-1] |
|
274
|
|
|
|
|
275
|
|
|
|
|
276
|
|
|
# |
|
277
|
|
|
# Discrete probability distributions. |
|
278
|
|
|
# |
|
279
|
|
|
|
|
280
|
|
|
class TestBernoulli(DiscreteTestBase, TestCase): |
|
281
|
|
|
|
|
282
|
|
|
dist = scipy.stats.bernoulli |
|
283
|
|
|
|
|
284
|
|
|
params = [(0.2, )] |
|
285
|
|
|
|
|
286
|
|
|
|
|
287
|
|
|
class TestBinomial(DiscreteTestBase, TestCase): |
|
288
|
|
|
|
|
289
|
|
|
dist = scipy.stats.binom |
|
290
|
|
|
|
|
291
|
|
|
params = [(40, 0.4)] |
|
292
|
|
|
|
|
293
|
|
|
|
|
294
|
|
|
@skip('') |
|
295
|
|
|
class TestBoltzmann(DiscreteTestBase, TestCase): |
|
296
|
|
|
|
|
297
|
|
|
dist = scipy.stats.boltzmann |
|
298
|
|
|
|
|
299
|
|
|
|
|
300
|
|
|
class TestDiscreteLaplacian(DiscreteTestBase, TestCase): |
|
301
|
|
|
|
|
302
|
|
|
dist = scipy.stats.dlaplace |
|
303
|
|
|
|
|
304
|
|
|
params = [(0.8, )] |
|
305
|
|
|
|
|
306
|
|
|
|
|
307
|
|
|
class TestGeometric(DiscreteTestBase, TestCase): |
|
308
|
|
|
|
|
309
|
|
|
dist = scipy.stats.geom |
|
310
|
|
|
|
|
311
|
|
|
params = [(0.1, )] |
|
312
|
|
|
|
|
313
|
|
|
|
|
314
|
|
|
class TestHypergeometric(DiscreteTestBase, TestCase): |
|
315
|
|
|
|
|
316
|
|
|
dist = scipy.stats.hypergeom |
|
317
|
|
|
|
|
318
|
|
|
params = [(40, 14, 24)] |
|
319
|
|
|
|
|
320
|
|
|
|
|
321
|
|
|
class TestLogSeries(DiscreteTestBase, TestCase): |
|
322
|
|
|
|
|
323
|
|
|
dist = scipy.stats.logser |
|
324
|
|
|
|
|
325
|
|
|
params = [(0.9, )] |
|
326
|
|
|
|
|
327
|
|
|
|
|
328
|
|
|
class TestNegativeBinomial(DiscreteTestBase, TestCase): |
|
329
|
|
|
|
|
330
|
|
|
dist = scipy.stats.nbinom |
|
331
|
|
|
|
|
332
|
|
|
params = [(40, 0.4)] |
|
333
|
|
|
|
|
334
|
|
|
|
|
335
|
|
|
class TestPlanck(DiscreteTestBase, TestCase): |
|
336
|
|
|
|
|
337
|
|
|
dist = scipy.stats.planck |
|
338
|
|
|
|
|
339
|
|
|
params = [(0.51, )] |
|
340
|
|
|
|
|
341
|
|
|
|
|
342
|
|
|
class TestPoisson(DiscreteTestBase, TestCase): |
|
343
|
|
|
|
|
344
|
|
|
dist = scipy.stats.poisson |
|
345
|
|
|
|
|
346
|
|
|
params = [(20, )] |
|
347
|
|
|
|
|
348
|
|
|
|
|
349
|
|
|
@skip('too sparse') |
|
350
|
|
|
class TestRandInt(DiscreteTestBase, TestCase): |
|
351
|
|
|
|
|
352
|
|
|
dist = scipy.stats.randint |
|
353
|
|
|
|
|
354
|
|
|
|
|
355
|
|
|
class TestSkellam(DiscreteTestBase, TestCase): |
|
356
|
|
|
|
|
357
|
|
|
dist = scipy.stats.skellam |
|
358
|
|
|
|
|
359
|
|
|
|
|
360
|
|
|
@skip('bug?') |
|
361
|
|
|
class TestZipf(DiscreteTestBase, TestCase): |
|
362
|
|
|
|
|
363
|
|
|
dist = scipy.stats.zipf |
|
364
|
|
|
|
|
365
|
|
|
params = [(1.2, )] |
|
366
|
|
|
|
|
367
|
|
|
# |
|
368
|
|
|
# Continuous probability distributions. |
|
369
|
|
|
# |
|
370
|
|
|
|
|
371
|
|
|
|
|
372
|
|
|
@skip('') |
|
373
|
|
|
class TestAlpha(ContinuousTestBase, TestCase): |
|
374
|
|
|
|
|
375
|
|
|
dist = scipy.stats.alpha |
|
376
|
|
|
|
|
377
|
|
|
|
|
378
|
|
|
class TestAnglit(ContinuousTestBase, TestCase): |
|
379
|
|
|
|
|
380
|
|
|
dist = scipy.stats.anglit |
|
381
|
|
|
|
|
382
|
|
|
|
|
383
|
|
|
class TestArcsine(ContinuousTestBase, TestCase): |
|
384
|
|
|
|
|
385
|
|
|
dist = scipy.stats.arcsine |
|
386
|
|
|
|
|
387
|
|
|
|
|
388
|
|
|
class TestBeta(ContinuousTestBase, TestCase): |
|
389
|
|
|
|
|
390
|
|
|
dist = scipy.stats.beta |
|
391
|
|
|
|
|
392
|
|
|
params = [ |
|
393
|
|
|
(0.5, 0.5), |
|
394
|
|
|
(0.5, 1.5), |
|
395
|
|
|
(0.5, 2.5), |
|
396
|
|
|
] |
|
397
|
|
|
|
|
398
|
|
|
|
|
399
|
|
|
class TestBetaPrime(ContinuousTestBase, TestCase): |
|
400
|
|
|
|
|
401
|
|
|
dist = scipy.stats.betaprime |
|
402
|
|
|
|
|
403
|
|
|
|
|
404
|
|
|
class TestBradford(ContinuousTestBase, TestCase): |
|
405
|
|
|
|
|
406
|
|
|
dist = scipy.stats.bradford |
|
407
|
|
|
|
|
408
|
|
|
|
|
409
|
|
|
class TestBurr(ContinuousTestBase, TestCase): |
|
410
|
|
|
|
|
411
|
|
|
dist = scipy.stats.burr |
|
412
|
|
|
|
|
413
|
|
|
|
|
414
|
|
|
class TestCauchy(ContinuousTestBase, TestCase): |
|
415
|
|
|
|
|
416
|
|
|
dist = scipy.stats.cauchy |
|
417
|
|
|
|
|
418
|
|
|
|
|
419
|
|
|
class TestChi(ContinuousTestBase, TestCase): |
|
420
|
|
|
|
|
421
|
|
|
dist = scipy.stats.chi |
|
422
|
|
|
|
|
423
|
|
|
|
|
424
|
|
|
class TestChiSquared(ContinuousTestBase, TestCase): |
|
425
|
|
|
|
|
426
|
|
|
dist = scipy.stats.chi2 |
|
427
|
|
|
|
|
428
|
|
|
|
|
429
|
|
|
class TestCosine(ContinuousTestBase, TestCase): |
|
430
|
|
|
|
|
431
|
|
|
dist = scipy.stats.cosine |
|
432
|
|
|
|
|
433
|
|
|
|
|
434
|
|
|
class TestDoubleGamma(ContinuousTestBase, TestCase): |
|
435
|
|
|
|
|
436
|
|
|
dist = scipy.stats.dgamma |
|
437
|
|
|
|
|
438
|
|
|
|
|
439
|
|
|
class TestDoubleWeibull(ContinuousTestBase, TestCase): |
|
440
|
|
|
|
|
441
|
|
|
dist = scipy.stats.dweibull |
|
442
|
|
|
|
|
443
|
|
|
|
|
444
|
|
|
class TestErlang(ContinuousTestBase, TestCase): |
|
445
|
|
|
|
|
446
|
|
|
dist = scipy.stats.erlang |
|
447
|
|
|
|
|
448
|
|
|
params = [(7, )] |
|
449
|
|
|
|
|
450
|
|
|
|
|
451
|
|
|
class TestExponential(ContinuousTestBase, TestCase): |
|
452
|
|
|
|
|
453
|
|
|
dist = scipy.stats.expon |
|
454
|
|
|
|
|
455
|
|
|
params = [(7, )] |
|
456
|
|
|
|
|
457
|
|
|
|
|
458
|
|
|
class TestExponentiallyModifiedNormal(ContinuousTestBase, TestCase): |
|
459
|
|
|
|
|
460
|
|
|
dist = scipy.stats.exponnorm |
|
461
|
|
|
|
|
462
|
|
|
|
|
463
|
|
|
class TestExponentiatedWeibull(ContinuousTestBase, TestCase): |
|
464
|
|
|
|
|
465
|
|
|
dist = scipy.stats.exponweib |
|
466
|
|
|
|
|
467
|
|
|
|
|
468
|
|
|
class TestExponentialPower(ContinuousTestBase, TestCase): |
|
469
|
|
|
|
|
470
|
|
|
dist = scipy.stats.exponpow |
|
471
|
|
|
|
|
472
|
|
|
|
|
473
|
|
|
class TestF(ContinuousTestBase, TestCase): |
|
474
|
|
|
|
|
475
|
|
|
dist = scipy.stats.f |
|
476
|
|
|
|
|
477
|
|
|
|
|
478
|
|
|
class TestFatigueLife(ContinuousTestBase, TestCase): |
|
479
|
|
|
|
|
480
|
|
|
dist = scipy.stats.fatiguelife |
|
481
|
|
|
|
|
482
|
|
|
|
|
483
|
|
|
class TestFisk(ContinuousTestBase, TestCase): |
|
484
|
|
|
|
|
485
|
|
|
dist = scipy.stats.fisk |
|
486
|
|
|
|
|
487
|
|
|
|
|
488
|
|
|
class TestFoldedCauchy(ContinuousTestBase, TestCase): |
|
489
|
|
|
|
|
490
|
|
|
dist = scipy.stats.foldcauchy |
|
491
|
|
|
|
|
492
|
|
|
|
|
493
|
|
|
class TestFoldedNormal(ContinuousTestBase, TestCase): |
|
494
|
|
|
|
|
495
|
|
|
dist = scipy.stats.foldnorm |
|
496
|
|
|
|
|
497
|
|
|
|
|
498
|
|
|
class TestFrechetRight(ContinuousTestBase, TestCase): |
|
499
|
|
|
|
|
500
|
|
|
dist = scipy.stats.frechet_r |
|
501
|
|
|
|
|
502
|
|
|
|
|
503
|
|
|
class TestFrechetLeft(ContinuousTestBase, TestCase): |
|
504
|
|
|
|
|
505
|
|
|
dist = scipy.stats.frechet_l |
|
506
|
|
|
|
|
507
|
|
|
|
|
508
|
|
|
class TestGeneralizedLogistic(ContinuousTestBase, TestCase): |
|
509
|
|
|
|
|
510
|
|
|
dist = scipy.stats.genlogistic |
|
511
|
|
|
|
|
512
|
|
|
|
|
513
|
|
|
class TestGeneralizedNormal(ContinuousTestBase, TestCase): |
|
514
|
|
|
|
|
515
|
|
|
dist = scipy.stats.gennorm |
|
516
|
|
|
|
|
517
|
|
|
|
|
518
|
|
|
class TestGeneralizedPareto(ContinuousTestBase, TestCase): |
|
519
|
|
|
|
|
520
|
|
|
dist = scipy.stats.genpareto |
|
521
|
|
|
|
|
522
|
|
|
|
|
523
|
|
|
class TestGeneralizedExponential(ContinuousTestBase, TestCase): |
|
524
|
|
|
|
|
525
|
|
|
dist = scipy.stats.genexpon |
|
526
|
|
|
|
|
527
|
|
|
|
|
528
|
|
|
class TestGeneralizedExtreme(ContinuousTestBase, TestCase): |
|
529
|
|
|
|
|
530
|
|
|
dist = scipy.stats.genextreme |
|
531
|
|
|
|
|
532
|
|
|
|
|
533
|
|
|
@skip('very slow') |
|
534
|
|
|
class TestGaussHypergeometric(ContinuousTestBase, TestCase): |
|
535
|
|
|
|
|
536
|
|
|
dist = scipy.stats.gausshyper |
|
537
|
|
|
|
|
538
|
|
|
|
|
539
|
|
|
class TestGamma(ContinuousTestBase, TestCase): |
|
540
|
|
|
|
|
541
|
|
|
dist = scipy.stats.gamma |
|
542
|
|
|
|
|
543
|
|
|
|
|
544
|
|
|
class TestGeneralizedGamma(ContinuousTestBase, TestCase): |
|
545
|
|
|
|
|
546
|
|
|
dist = scipy.stats.gengamma |
|
547
|
|
|
|
|
548
|
|
|
|
|
549
|
|
|
class TestGeneralizedHalfLogistic(ContinuousTestBase, TestCase): |
|
550
|
|
|
|
|
551
|
|
|
dist = scipy.stats.genhalflogistic |
|
552
|
|
|
|
|
553
|
|
|
|
|
554
|
|
|
class TestGilbrat(ContinuousTestBase, TestCase): |
|
555
|
|
|
|
|
556
|
|
|
dist = scipy.stats.gilbrat |
|
557
|
|
|
|
|
558
|
|
|
|
|
559
|
|
|
class TestGompertz(ContinuousTestBase, TestCase): |
|
560
|
|
|
|
|
561
|
|
|
dist = scipy.stats.gompertz |
|
562
|
|
|
|
|
563
|
|
|
|
|
564
|
|
|
class TestGumbelRight(ContinuousTestBase, TestCase): |
|
565
|
|
|
|
|
566
|
|
|
dist = scipy.stats.gumbel_r |
|
567
|
|
|
|
|
568
|
|
|
|
|
569
|
|
|
class TestGumbelLeft(ContinuousTestBase, TestCase): |
|
570
|
|
|
|
|
571
|
|
|
dist = scipy.stats.gumbel_l |
|
572
|
|
|
|
|
573
|
|
|
|
|
574
|
|
|
class TestHalfCauchy(ContinuousTestBase, TestCase): |
|
575
|
|
|
|
|
576
|
|
|
dist = scipy.stats.halfcauchy |
|
577
|
|
|
|
|
578
|
|
|
|
|
579
|
|
|
class TestHalfLogistic(ContinuousTestBase, TestCase): |
|
580
|
|
|
|
|
581
|
|
|
dist = scipy.stats.halflogistic |
|
582
|
|
|
|
|
583
|
|
|
|
|
584
|
|
|
class TestHalfNormal(ContinuousTestBase, TestCase): |
|
585
|
|
|
|
|
586
|
|
|
dist = scipy.stats.halfnorm |
|
587
|
|
|
|
|
588
|
|
|
|
|
589
|
|
|
class TestHalfGeneralizedNormal(ContinuousTestBase, TestCase): |
|
590
|
|
|
|
|
591
|
|
|
dist = scipy.stats.halfgennorm |
|
592
|
|
|
|
|
593
|
|
|
|
|
594
|
|
|
class TestHyperbolicSecant(ContinuousTestBase, TestCase): |
|
595
|
|
|
|
|
596
|
|
|
dist = scipy.stats.hypsecant |
|
597
|
|
|
|
|
598
|
|
|
|
|
599
|
|
|
class TestInverseGamma(ContinuousTestBase, TestCase): |
|
600
|
|
|
|
|
601
|
|
|
dist = scipy.stats.invgamma |
|
602
|
|
|
|
|
603
|
|
|
|
|
604
|
|
|
class TestInverseGauss(ContinuousTestBase, TestCase): |
|
605
|
|
|
|
|
606
|
|
|
dist = scipy.stats.invgauss |
|
607
|
|
|
|
|
608
|
|
|
|
|
609
|
|
|
class TestInverseWeibull(ContinuousTestBase, TestCase): |
|
610
|
|
|
|
|
611
|
|
|
dist = scipy.stats.invweibull |
|
612
|
|
|
|
|
613
|
|
|
|
|
614
|
|
|
class TestJohnsonSB(ContinuousTestBase, TestCase): |
|
615
|
|
|
|
|
616
|
|
|
dist = scipy.stats.johnsonsb |
|
617
|
|
|
|
|
618
|
|
|
|
|
619
|
|
|
class TestJohnsonSU(ContinuousTestBase, TestCase): |
|
620
|
|
|
|
|
621
|
|
|
dist = scipy.stats.johnsonsu |
|
622
|
|
|
|
|
623
|
|
|
|
|
624
|
|
|
@skip('???') |
|
625
|
|
|
class TestKolmogorovSmirnovOneSided(ContinuousTestBase, TestCase): |
|
626
|
|
|
|
|
627
|
|
|
dist = scipy.stats.ksone |
|
628
|
|
|
|
|
629
|
|
|
|
|
630
|
|
|
class TestKolmogorovSmirnovTwoSided(ContinuousTestBase, TestCase): |
|
631
|
|
|
|
|
632
|
|
|
dist = scipy.stats.kstwobign |
|
633
|
|
|
|
|
634
|
|
|
|
|
635
|
|
|
class TestLaplace(ContinuousTestBase, TestCase): |
|
636
|
|
|
|
|
637
|
|
|
dist = scipy.stats.laplace |
|
638
|
|
|
|
|
639
|
|
|
|
|
640
|
|
|
class TestLevy(ContinuousTestBase, TestCase): |
|
641
|
|
|
|
|
642
|
|
|
dist = scipy.stats.levy |
|
643
|
|
|
|
|
644
|
|
|
|
|
645
|
|
|
class TestLeftSkewedLevy(ContinuousTestBase, TestCase): |
|
646
|
|
|
|
|
647
|
|
|
dist = scipy.stats.levy_l |
|
648
|
|
|
|
|
649
|
|
|
|
|
650
|
|
|
@skip('???') |
|
651
|
|
|
class TestLevyStable(ContinuousTestBase, TestCase): |
|
652
|
|
|
|
|
653
|
|
|
dist = scipy.stats.levy_stable |
|
654
|
|
|
|
|
655
|
|
|
|
|
656
|
|
|
class TestLogistic(ContinuousTestBase, TestCase): |
|
657
|
|
|
|
|
658
|
|
|
dist = scipy.stats.logistic |
|
659
|
|
|
|
|
660
|
|
|
|
|
661
|
|
|
class TestLogGamma(ContinuousTestBase, TestCase): |
|
662
|
|
|
|
|
663
|
|
|
dist = scipy.stats.loggamma |
|
664
|
|
|
|
|
665
|
|
|
|
|
666
|
|
|
class TestLogLaplace(ContinuousTestBase, TestCase): |
|
667
|
|
|
|
|
668
|
|
|
dist = scipy.stats.loglaplace |
|
669
|
|
|
|
|
670
|
|
|
|
|
671
|
|
|
class TestLogNormal(ContinuousTestBase, TestCase): |
|
672
|
|
|
|
|
673
|
|
|
dist = scipy.stats.lognorm |
|
674
|
|
|
|
|
675
|
|
|
|
|
676
|
|
|
class TestLomax(ContinuousTestBase, TestCase): |
|
677
|
|
|
|
|
678
|
|
|
dist = scipy.stats.lomax |
|
679
|
|
|
|
|
680
|
|
|
|
|
681
|
|
|
class TestMaxwell(ContinuousTestBase, TestCase): |
|
682
|
|
|
|
|
683
|
|
|
dist = scipy.stats.maxwell |
|
684
|
|
|
|
|
685
|
|
|
|
|
686
|
|
|
class TestMielke(ContinuousTestBase, TestCase): |
|
687
|
|
|
|
|
688
|
|
|
dist = scipy.stats.mielke |
|
689
|
|
|
|
|
690
|
|
|
|
|
691
|
|
|
class TestNakagami(ContinuousTestBase, TestCase): |
|
692
|
|
|
|
|
693
|
|
|
dist = scipy.stats.nakagami |
|
694
|
|
|
|
|
695
|
|
|
|
|
696
|
|
|
class TestNonCentralChiSquared(ContinuousTestBase, TestCase): |
|
697
|
|
|
|
|
698
|
|
|
dist = scipy.stats.ncx2 |
|
699
|
|
|
|
|
700
|
|
|
|
|
701
|
|
|
class TestNonCentralF(ContinuousTestBase, TestCase): |
|
702
|
|
|
|
|
703
|
|
|
dist = scipy.stats.ncf |
|
704
|
|
|
|
|
705
|
|
|
params = [(27, 27, 0.415784417992)] |
|
706
|
|
|
|
|
707
|
|
|
|
|
708
|
|
|
class TestNonCentralT(ContinuousTestBase, TestCase): |
|
709
|
|
|
|
|
710
|
|
|
dist = scipy.stats.nct |
|
711
|
|
|
|
|
712
|
|
|
|
|
713
|
|
|
class TestNormal(ContinuousTestBase, TestCase): |
|
714
|
|
|
|
|
715
|
|
|
dist = scipy.stats.norm |
|
716
|
|
|
|
|
717
|
|
|
|
|
718
|
|
|
class TestPareto(ContinuousTestBase, TestCase): |
|
719
|
|
|
|
|
720
|
|
|
dist = scipy.stats.pareto |
|
721
|
|
|
|
|
722
|
|
|
|
|
723
|
|
|
class TestPearson3(ContinuousTestBase, TestCase): |
|
724
|
|
|
|
|
725
|
|
|
dist = scipy.stats.pearson3 |
|
726
|
|
|
|
|
727
|
|
|
|
|
728
|
|
|
class TestPowerLaw(ContinuousTestBase, TestCase): |
|
729
|
|
|
|
|
730
|
|
|
dist = scipy.stats.powerlaw |
|
731
|
|
|
|
|
732
|
|
|
|
|
733
|
|
|
class TestPowerNormal(ContinuousTestBase, TestCase): |
|
734
|
|
|
|
|
735
|
|
|
dist = scipy.stats.powernorm |
|
736
|
|
|
|
|
737
|
|
|
|
|
738
|
|
|
class TestRDistributed(ContinuousTestBase, TestCase): |
|
739
|
|
|
|
|
740
|
|
|
dist = scipy.stats.rdist |
|
741
|
|
|
|
|
742
|
|
|
|
|
743
|
|
|
class TestReciprocal(ContinuousTestBase, TestCase): |
|
744
|
|
|
|
|
745
|
|
|
dist = scipy.stats.reciprocal |
|
746
|
|
|
|
|
747
|
|
|
params = [tuple(numpy.array([0, 1]) + rand(1)[0])] |
|
748
|
|
|
|
|
749
|
|
|
|
|
750
|
|
|
class TestRayleigh(ContinuousTestBase, TestCase): |
|
751
|
|
|
|
|
752
|
|
|
dist = scipy.stats.rayleigh |
|
753
|
|
|
|
|
754
|
|
|
|
|
755
|
|
|
class TestRice(ContinuousTestBase, TestCase): |
|
756
|
|
|
|
|
757
|
|
|
dist = scipy.stats.rice |
|
758
|
|
|
|
|
759
|
|
|
|
|
760
|
|
|
class TestReciprocalInverseGaussian(ContinuousTestBase, TestCase): |
|
761
|
|
|
|
|
762
|
|
|
dist = scipy.stats.recipinvgauss |
|
763
|
|
|
|
|
764
|
|
|
|
|
765
|
|
|
class TestSemicircular(ContinuousTestBase, TestCase): |
|
766
|
|
|
|
|
767
|
|
|
dist = scipy.stats.semicircular |
|
768
|
|
|
|
|
769
|
|
|
|
|
770
|
|
|
class TestT(ContinuousTestBase, TestCase): |
|
771
|
|
|
|
|
772
|
|
|
dist = scipy.stats.t |
|
773
|
|
|
|
|
774
|
|
|
|
|
775
|
|
|
class TestTrapz(ContinuousTestBase, TestCase): |
|
776
|
|
|
|
|
777
|
|
|
dist = scipy.stats.trapz |
|
778
|
|
|
|
|
779
|
|
|
params = [(1 / 3, 2 / 3)] |
|
780
|
|
|
|
|
781
|
|
|
|
|
782
|
|
|
class TestTriangular(ContinuousTestBase, TestCase): |
|
783
|
|
|
|
|
784
|
|
|
dist = scipy.stats.triang |
|
785
|
|
|
|
|
786
|
|
|
params = [tuple(rand(1))] |
|
787
|
|
|
|
|
788
|
|
|
|
|
789
|
|
|
class TestTruncatedExponential(ContinuousTestBase, TestCase): |
|
790
|
|
|
|
|
791
|
|
|
dist = scipy.stats.truncexpon |
|
792
|
|
|
|
|
793
|
|
|
|
|
794
|
|
|
class TestTruncatedNormal(ContinuousTestBase, TestCase): |
|
795
|
|
|
|
|
796
|
|
|
dist = scipy.stats.truncnorm |
|
797
|
|
|
|
|
798
|
|
|
params = [(0.1, 2.0)] |
|
799
|
|
|
|
|
800
|
|
|
|
|
801
|
|
|
class TestTukeyLambda(ContinuousTestBase, TestCase): |
|
802
|
|
|
|
|
803
|
|
|
dist = scipy.stats.tukeylambda |
|
804
|
|
|
|
|
805
|
|
|
|
|
806
|
|
|
class TestUniform(ContinuousTestBase, TestCase): |
|
807
|
|
|
|
|
808
|
|
|
dist = scipy.stats.uniform |
|
809
|
|
|
|
|
810
|
|
|
|
|
811
|
|
|
class TestVonMises(ContinuousTestBase, TestCase): |
|
812
|
|
|
|
|
813
|
|
|
dist = scipy.stats.vonmises |
|
814
|
|
|
|
|
815
|
|
|
params = [tuple(1.0 + rand(1))] |
|
816
|
|
|
|
|
817
|
|
|
|
|
818
|
|
|
class TestVonMisesLine(ContinuousTestBase, TestCase): |
|
819
|
|
|
|
|
820
|
|
|
dist = scipy.stats.vonmises_line |
|
821
|
|
|
|
|
822
|
|
|
|
|
823
|
|
|
class TestWald(ContinuousTestBase, TestCase): |
|
824
|
|
|
|
|
825
|
|
|
dist = scipy.stats.wald |
|
826
|
|
|
|
|
827
|
|
|
|
|
828
|
|
|
class TestWeibullMin(ContinuousTestBase, TestCase): |
|
829
|
|
|
|
|
830
|
|
|
dist = scipy.stats.weibull_min |
|
831
|
|
|
|
|
832
|
|
|
|
|
833
|
|
|
class TestWeibullMax(ContinuousTestBase, TestCase): |
|
834
|
|
|
|
|
835
|
|
|
dist = scipy.stats.weibull_max |
|
836
|
|
|
|
|
837
|
|
|
|
|
838
|
|
|
class TestWrappedCauchy(ContinuousTestBase, TestCase): |
|
839
|
|
|
|
|
840
|
|
|
dist = scipy.stats.wrapcauchy |
|
841
|
|
|
|
|
842
|
|
|
params = [(0.5,)] |
|
843
|
|
|
|