本文整理汇总了Java中org.apache.mahout.common.Pair.of方法的典型用法代码示例。如果您正苦于以下问题:Java Pair.of方法的具体用法?Java Pair.of怎么用?Java Pair.of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mahout.common.Pair
的用法示例。
在下文中一共展示了Pair.of方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: randomMatrix
import org.apache.mahout.common.Pair; //导入方法依赖的package包/类
private static Pair<Matrix,Vector> randomMatrix(int numTopics, int numTerms, Random random) {
Matrix topicTermCounts = new DenseMatrix(numTopics, numTerms);
Vector topicSums = new DenseVector(numTopics);
if (random != null) {
for (int x = 0; x < numTopics; x++) {
for (int term = 0; term < numTerms; term++) {
topicTermCounts.viewRow(x).set(term, random.nextDouble());
}
}
}
for (int x = 0; x < numTopics; x++) {
topicSums.set(x, random == null ? 1.0 : topicTermCounts.viewRow(x).norm(1));
}
return Pair.of(topicTermCounts, topicSums);
}
示例2: loadModel
import org.apache.mahout.common.Pair; //导入方法依赖的package包/类
public static Pair<Matrix, Vector> loadModel(Configuration conf, Path... modelPaths)
throws IOException {
int numTopics = -1;
int numTerms = -1;
List<Pair<Integer, Vector>> rows = Lists.newArrayList();
for (Path modelPath : modelPaths) {
for (Pair<IntWritable, VectorWritable> row :
new SequenceFileIterable<IntWritable, VectorWritable>(modelPath, true, conf)) {
rows.add(Pair.of(row.getFirst().get(), row.getSecond().get()));
numTopics = Math.max(numTopics, row.getFirst().get());
if (numTerms < 0) {
numTerms = row.getSecond().get().size();
}
}
}
if (rows.isEmpty()) {
throw new IOException(Arrays.toString(modelPaths) + " have no vectors in it");
}
numTopics++;
Matrix model = new DenseMatrix(numTopics, numTerms);
Vector topicSums = new DenseVector(numTopics);
for (Pair<Integer, Vector> pair : rows) {
model.viewRow(pair.getFirst()).assign(pair.getSecond());
topicSums.set(pair.getFirst(), pair.getSecond().norm(1));
}
return Pair.of(model, topicSums);
}