From b4b18d8458a4b66e87fd70276b60de15e86e8dc7 Mon Sep 17 00:00:00 2001 From: aimalz Date: Wed, 29 Mar 2017 20:18:32 -0400 Subject: [PATCH 1/4] made plot of mixture model more visible --- qp/pdf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qp/pdf.py b/qp/pdf.py index d93e05af..81ebb869 100644 --- a/qp/pdf.py +++ b/qp/pdf.py @@ -508,7 +508,7 @@ def plot(self, vb=True): x = np.linspace(min_x, max_x, 100) extrema = [min(extrema[0], min_x), max(extrema[1], max_x)] y = self.mix_mod.pdf(x) - plt.plot(x, y, color='k', linestyle=':', lw=1.0, alpha=0.5, label='Mixture Model PDF') + plt.plot(x, y, color='k', linestyle=':', lw=1.0, alpha=1.0, label='Mixture Model PDF') if vb: print 'Plotted mixture model.' From 097d25e411f75f730a1da8098af678acde87c283 Mon Sep 17 00:00:00 2001 From: aimalz Date: Thu, 30 Mar 2017 16:58:47 -0400 Subject: [PATCH 2/4] can now sample from gridded approximation --- qp/pdf.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/qp/pdf.py b/qp/pdf.py index 81ebb869..bb9ae26d 100644 --- a/qp/pdf.py +++ b/qp/pdf.py @@ -324,6 +324,17 @@ def sample(self, N=100, infty=100., using=None, vb=True): elif using == 'mix_mod': samples = self.mix_mod.rvs(size=N) + elif using == 'gridded': + interpolator = self.interpolate(using = 'gridded') + (xmin, xmax) = (min(self.gridded[0]), max(self.gridded[0])) + (ymin, ymax) = (min(self.gridded[1]), max(self.gridded[1])) + (xran, yran) = (xmax - xmin, ymax - ymin) + samples = [] + while len(samples) < N: + (x, y) = (xmin + xran * np.random.uniform(), ymin + yran * np.random.uniform()) + if y < interpolator(x): + samples.append(x) + else: if using == 'quantiles': # First find the quantiles if none exist: From 48f19ed71a799cb746e81a8e5c9e63d53185f9ea Mon Sep 17 00:00:00 2001 From: aimalz Date: Thu, 30 Mar 2017 16:59:10 -0400 Subject: [PATCH 3/4] now demo shows sampling of gridded approximation --- docs/notebooks/demo.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/notebooks/demo.ipynb b/docs/notebooks/demo.ipynb index 325c23bf..1f3a3404 100644 --- a/docs/notebooks/demo.ipynb +++ b/docs/notebooks/demo.ipynb @@ -230,6 +230,7 @@ "gridded = P.evaluate(grid, using='truth', vb=False)\n", "\n", "G = qp.PDF(gridded=gridded)\n", + "G.sample(100, vb=False)\n", "G.plot()" ] }, From 759c4e79a78fc90d3d5c4c653d0d717f790057cc Mon Sep 17 00:00:00 2001 From: aimalz Date: Thu, 30 Mar 2017 17:03:30 -0400 Subject: [PATCH 4/4] changed type for consistency --- qp/pdf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qp/pdf.py b/qp/pdf.py index bb9ae26d..bfe17185 100644 --- a/qp/pdf.py +++ b/qp/pdf.py @@ -364,7 +364,7 @@ def sample(self, N=100, infty=100., using=None, vb=True): samples.append(np.random.uniform(low=endpoints[c], high=endpoints[c+1])) if vb: print 'Sampled values: ', samples - self.samples = samples + self.samples = np.array(samples) self.last = 'samples' return self.samples