def generate_data(N, D, K, seed=1, spread=3): """ Generate data from a mixture of Gaussians model """ np.random.seed(seed) mu = spread*np.random.randn(K, D) # Lambda is actually precision matrix (inverse covariance) Lambda = random.covariance(D, size=K, nu=2*D) pi = random.dirichlet(5*np.ones(K)) y = np.zeros((N,D)) for n in range(N): ind = nodes.Categorical(pi).random() y[n] = nodes.Gaussian(mu[ind], Lambda[ind]).random() np.savetxt('mog-data-%02d.csv' % seed, y, delimiter=',', fmt='%f') return y
def random(self, *phi, plates=None): r""" Draw a random sample from the distribution. """ return random.dirichlet(phi[0], size=plates)
def random(self, *phi, plates=None): """ Draw a random sample from the distribution. """ return random.dirichlet(phi[0], size=plates)
def random(self): """ Draw a random sample from the distribution. """ return random.dirichlet(self.phi[0], size=self.plates)