def work(self, **kwargs): self.__dict__.update(kwargs) self.worked = True samples = LGMM1(rng=self.rng, size=(self.n_samples, ), **self.LGMM1_kwargs) samples = np.sort(samples) edges = samples[::self.samples_per_bin] centers = .5 * edges[:-1] + .5 * edges[1:] print edges pdf = np.exp(LGMM1_lpdf(centers, **self.LGMM1_kwargs)) dx = edges[1:] - edges[:-1] y = 1 / dx / len(dx) if self.show: plt.scatter(centers, y) plt.plot(centers, pdf) plt.show() err = (pdf - y)**2 print np.max(err) print np.mean(err) print np.median(err) if not self.show: assert np.max(err) < .1 assert np.mean(err) < .01 assert np.median(err) < .01
def work(self, **kwargs): self.__dict__.update(kwargs) self.worked = True samples = old_div( LGMM1(rng=self.rng, size=(self.n_samples, ), **self.kwargs), self.q) # -- we've divided the LGMM1 by self.q to get ints here assert np.all(samples == samples.astype("int")) min_max = int(samples.min()), int(samples.max()) print("SAMPLES RANGE", min_max) counts = np.bincount(samples.astype("int") - min_max[0]) # print samples # print counts xcoords = np.arange(min_max[0], min_max[1] + 0.5) * self.q prob = np.exp(LGMM1_lpdf(xcoords, **self.kwargs)) print(xcoords) print(prob) assert counts.sum() == self.n_samples y = old_div(counts, float(self.n_samples)) if self.show: plt.scatter(xcoords, y, c="r", label="empirical") plt.scatter(xcoords, prob, c="b", label="predicted") plt.legend() plt.show() # -- calculate errors on the low end, don't take a mean # over all the range spanned by a few outliers. err = ((prob - y)**2)[:20] print(np.max(err)) print(np.mean(err)) print(np.median(err)) if self.show: raise nose.SkipTest() else: assert np.max(err) < 0.1 assert np.mean(err) < 0.01 assert np.median(err) < 0.01
def work(self, **kwargs): self.__dict__.update(kwargs) self.worked = True samples = LGMM1(rng=self.rng, size=(self.n_samples, ), ** self.kwargs) / self.q # -- we've divided the LGMM1 by self.q to get ints here assert np.all(samples == samples.astype('int')) min_max = int(samples.min()), int(samples.max()) print 'SAMPLES RANGE', min_max counts = np.bincount(samples.astype('int') - min_max[0]) #print samples #print counts xcoords = np.arange(min_max[0], min_max[1] + 0.5) * self.q prob = np.exp(LGMM1_lpdf(xcoords, **self.kwargs)) print xcoords print prob assert counts.sum() == self.n_samples y = counts / float(self.n_samples) if self.show: import matplotlib.pyplot as plt plt.scatter(xcoords, y, c='r', label='empirical') plt.scatter(xcoords, prob, c='b', label='predicted') plt.legend() plt.show() # -- calculate errors on the low end, don't take a mean # over all the range spanned by a few outliers. err = ((prob - y)**2)[:20] print np.max(err) print np.mean(err) print np.median(err) if self.show: raise nose.SkipTest() else: assert np.max(err) < .1 assert np.mean(err) < .01 assert np.median(err) < .01