def from_posterior(self, param, samples): smin, smax = np.min(samples), np.max(samples) width = smax - smin x = np.linspace(smin, smax, 100) y = stats.gaussian_kde(samples.T)(x) # what was never sampled should have a small probability but not 0, # so we'll extend the domain and use linear approximation of density on it x = np.concatenate([[x[0] - 3 * width], x, [x[-1] + 3 * width]]) y = np.concatenate([[0], y, [0]]) return Interpolated(param, x, y)
def from_epdf(param, ambient_counts): from scipy.stats import gaussian_kde smin, smax = np.min(ambient_counts), np.max(ambient_counts) width = smax - smin x = np.linspace(smin, smax, 200) y = gaussian_kde(ambient_counts)(x) x = np.concatenate([[-1e9,-100,0], x, [x[-1] + np.log10(10)]]) y = np.concatenate([[1e-1000,1e-200,1e-2], y, [1e-20]]) sns.scatterplot(x,y) plt.show() #return pm.Normal('x', mu=np.mean(ambient_counts), sigma=np.std(ambient_counts)) return Interpolated(param, x, y)