コード例 #1
0
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
コード例 #2
0
ファイル: dirichlet.py プロジェクト: zehsilva/bayespy
 def random(self, *phi, plates=None):
     r"""
     Draw a random sample from the distribution.
     """
     return random.dirichlet(phi[0], size=plates)
コード例 #3
0
ファイル: dirichlet.py プロジェクト: viveksck/bayespy
 def random(self, *phi, plates=None):
     """
     Draw a random sample from the distribution.
     """
     return random.dirichlet(phi[0], size=plates)
コード例 #4
0
ファイル: dirichlet.py プロジェクト: Sandy4321/bayespy
 def random(self):
     """
     Draw a random sample from the distribution.
     """
     return random.dirichlet(self.phi[0], size=self.plates)