本文整理汇总了Java中org.apache.mahout.math.VectorIterable类的典型用法代码示例。如果您正苦于以下问题:Java VectorIterable类的具体用法?Java VectorIterable怎么用?Java VectorIterable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VectorIterable类属于org.apache.mahout.math包,在下文中一共展示了VectorIterable类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculatePerplexity
import org.apache.mahout.math.VectorIterable; //导入依赖的package包/类
public double calculatePerplexity(VectorIterable matrix, VectorIterable docTopicCounts,
double testFraction) {
Iterator<MatrixSlice> docIterator = matrix.iterator();
Iterator<MatrixSlice> docTopicIterator = docTopicCounts.iterator();
double perplexity = 0;
double matrixNorm = 0;
while (docIterator.hasNext() && docTopicIterator.hasNext()) {
MatrixSlice docSlice = docIterator.next();
MatrixSlice topicSlice = docTopicIterator.next();
int docId = docSlice.index();
Vector document = docSlice.vector();
Vector topicDist = topicSlice.vector();
if (testFraction == 0 || docId % (1/testFraction) == 0) {
trainSync(document, topicDist, false, 10);
perplexity += readModel.perplexity(document, topicDist);
matrixNorm += document.norm(1);
}
}
return perplexity / matrixNorm;
}
示例2: sample
import org.apache.mahout.math.VectorIterable; //导入依赖的package包/类
static <M extends VectorIterable> Matrix sample(M bigMatrix,
Matrix sampleMatrix) {
log.info("Sampling a " + bigMatrix.numRows() + "x" + bigMatrix.numCols()
+ " into a " + sampleMatrix.numRows() + "x" + sampleMatrix.numCols());
int row = 0;
Iterator<MatrixSlice> sliceIterator = bigMatrix.iterateAll();
while (sliceIterator.hasNext() && row < sampleMatrix.numRows()) {
MatrixSlice slice = sliceIterator.next();
if (!PCACommon.pass(SAMPLE_RATE)) {
sampleMatrix.viewRow(row).assign(slice.vector());
row++;
}
}
return sampleMatrix;
}
示例3: train
import org.apache.mahout.math.VectorIterable; //导入依赖的package包/类
public void train(VectorIterable matrix, VectorIterable docTopicCounts) {
train(matrix, docTopicCounts, 1);
}