本文整理汇总了Java中org.apache.mahout.math.Vector.norm方法的典型用法代码示例。如果您正苦于以下问题:Java Vector.norm方法的具体用法?Java Vector.norm怎么用?Java Vector.norm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mahout.math.Vector
的用法示例。
在下文中一共展示了Vector.norm方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculatePerplexity
import org.apache.mahout.math.Vector; //导入方法依赖的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: postInitCorpus
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
private void postInitCorpus() {
totalCorpusWeight = 0;
int numNonZero = 0;
for (int i=0; i<numDocuments; i++) {
Vector v = corpusWeights.viewRow(i);
double norm;
if (v != null && (norm = v.norm(1)) != 0) {
numNonZero += v.getNumNondefaultElements();
totalCorpusWeight += norm;
}
}
String s = "Initializing corpus with %d docs, %d terms, %d nonzero entries, total termWeight %f";
log.info(String.format(s, numDocuments, numTerms, numNonZero, totalCorpusWeight));
}
示例3: apply
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
@Override
public double apply(Vector f) {
return f.norm(1);// sum
}