}
public static Matrix sampledCorpus(Matrix matrix, Random random,
int numDocs, int numSamples, int numTopicsPerDoc) {
Matrix corpus = new SparseRowMatrix(numDocs, matrix.numCols());
LDASampler modelSampler = new LDASampler(matrix, random);
Vector topicVector = new DenseVector(matrix.numRows());
for(int i = 0; i < numTopicsPerDoc; i++) {
int topic = random.nextInt(topicVector.size());
topicVector.set(topic, topicVector.get(topic) + 1);
}
for(int docId = 0; docId < numDocs; docId++) {
for(int sample : modelSampler.sample(topicVector, numSamples)) {
corpus.set(docId, sample, corpus.get(docId, sample) + 1);
}
}
return corpus;
}