(self, **kwargs)
| 469 | return self.LGMM1(samples, **self.kwargs) |
| 470 | |
| 471 | def work(self, **kwargs): |
| 472 | self.__dict__.update(kwargs) |
| 473 | self.worked = True |
| 474 | samples = old_div( |
| 475 | LGMM1(rng=self.rng, size=(self.n_samples,), **self.kwargs), self.q |
| 476 | ) |
| 477 | # -- we've divided the LGMM1 by self.q to get ints here |
| 478 | assert np.all(samples == samples.astype("int")) |
| 479 | min_max = int(samples.min()), int(samples.max()) |
| 480 | print("SAMPLES RANGE", min_max) |
| 481 | counts = np.bincount(samples.astype("int") - min_max[0]) |
| 482 | |
| 483 | # print samples |
| 484 | # print counts |
| 485 | xcoords = np.arange(min_max[0], min_max[1] + 0.5) * self.q |
| 486 | prob = np.exp(LGMM1_lpdf(xcoords, **self.kwargs)) |
| 487 | print(xcoords) |
| 488 | print(prob) |
| 489 | assert counts.sum() == self.n_samples |
| 490 | y = old_div(counts, float(self.n_samples)) |
| 491 | |
| 492 | if self.show: |
| 493 | plt.scatter(xcoords, y, c="r", label="empirical") |
| 494 | plt.scatter(xcoords, prob, c="b", label="predicted") |
| 495 | plt.legend() |
| 496 | plt.show() |
| 497 | # -- calculate errors on the low end, don't take a mean |
| 498 | # over all the range spanned by a few outliers. |
| 499 | err = ((prob - y) ** 2)[:20] |
| 500 | print(np.max(err)) |
| 501 | print(np.mean(err)) |
| 502 | print(np.median(err)) |
| 503 | if self.show: |
| 504 | raise nose.SkipTest() |
| 505 | else: |
| 506 | assert np.max(err) < 0.1 |
| 507 | assert np.mean(err) < 0.01 |
| 508 | assert np.median(err) < 0.01 |
| 509 | |
| 510 | def test_basic_1(self): |
| 511 | self.work(q=1) |
no test coverage detected