MCPcopy
hub / github.com/hyperopt/hyperopt / check_d_samples

Function check_d_samples

hyperopt/tests/unit/test_rdists.py:92–105  ·  view source on GitHub ↗
(dfn, n, rtol=1e-2, atol=1e-2)

Source from the content-addressed store, hash-verified

90
91
92def check_d_samples(dfn, n, rtol=1e-2, atol=1e-2):
93 counts = defaultdict(lambda: 0)
94 # print 'sample', dfn.rvs(size=n)
95 inc = old_div(1.0, n)
96 for s in dfn.rvs(size=n):
97 counts[s] += inc
98 for ii, p in sorted(counts.items()):
99 t = np.allclose(dfn.pmf(ii), p, rtol=rtol, atol=atol)
100 if not t:
101 print(("Error in sampling frequencies", ii))
102 print("value\tpmf\tfreq")
103 for jj in sorted(counts):
104 print("{:.2f}\t{:.3f}\t{:.4f}".format(jj, dfn.pmf(jj), counts[jj]))
105 npt.assert_(t, "n = %i; pmf = %f; p = %f" % (n, dfn.pmf(ii), p))
106
107
108class TestQUniform(unittest.TestCase):

Callers 10

test_smallqMethod · 0.85
test_bigqMethod · 0.85
test_smallqMethod · 0.85
test_bigqMethod · 0.85
test_pointMethod · 0.85
test_2pointsMethod · 0.85
test_smallqMethod · 0.85
test_bigqMethod · 0.85
test_smallqMethod · 0.85
test_bigqMethod · 0.85

Calls 3

itemsMethod · 0.80
rvsMethod · 0.45
pmfMethod · 0.45

Tested by

no test coverage detected