(dfn, n, rtol=1e-2, atol=1e-2)
| 90 | |
| 91 | |
| 92 | def 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 | |
| 108 | class TestQUniform(unittest.TestCase): |
no test coverage detected