MLPack: generate random data from GMM

int numGauss = 3;
int numDim = 3;
int numObs = 1000;
mlpack::gmm::GMM<> gmm(numGauss,numDim);
arma::mat covar(numDim, numDim);

gmm.Weights() = GenerateWeight(numGauss, 1.0/((double)numGauss*2.0));
// set j-th gmm's mean and covariance
for(int k = 0; k < numGauss; ++k)
{
    gmm.Means()[k] = 255.0*arma::randu&amp;lt; arma::vec &amp;gt;(numDim);
    covar = arma::eye<arma::mat>(numDim, numDim);
    covar += 0.2*arma::randu<arma::mat>(numDim, numDim);
    gmm.Covariances()[k] = arma::symmatu(covar);
}
armaData = arma::zeros(numDim, numObs);
for(int i = 0; i < numObs; ++i)
{
    armaData.col(i) = gmm.Random();
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s