Path: blob/master/incubator/sampling_source.py
411 views
import numpy as np1from scipy.stats import norm, expon234class Distribution:5def __init__(self):6return NotImplementedError("Please implement init.")78def pdf(self, x):9"""Evaluate total probability of data x."""10return np.prod(self.dist.pdf(x))1112def logpdf(self, x):13"""Evaluate total log probability of data x."""14return np.sum(self.dist.logpdf(x))1516def draws(self, n):17"""Draw n samples from the distribution"""18return self.dist.rvs(n)192021class Normal(Distribution):22def __init__(self, mu, sigma):23self.mu = mu24self.sigma = sigma25self.dist = norm(mu, sigma)262728class Exponential(Distribution):29def __init__(self, lam):30self.lam = lam31self.dist = expon(scale=lam)323334