本文整理汇总了Java中org.apache.mahout.math.RandomAccessSparseVector.setQuick方法的典型用法代码示例。如果您正苦于以下问题:Java RandomAccessSparseVector.setQuick方法的具体用法?Java RandomAccessSparseVector.setQuick怎么用?Java RandomAccessSparseVector.setQuick使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mahout.math.RandomAccessSparseVector
的用法示例。
在下文中一共展示了RandomAccessSparseVector.setQuick方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reduce
import org.apache.mahout.math.RandomAccessSparseVector; //导入方法依赖的package包/类
@Override
protected void reduce(Text row, Iterable<VertexWritable> entries,
Context context) throws IOException, InterruptedException {
// now to assemble the vectors
RandomAccessSparseVector output = new RandomAccessSparseVector(
context.getConfiguration().getInt(EigencutsKeys.AFFINITY_DIMENSIONS, Integer.MAX_VALUE), 100);
int rownum = Integer.parseInt(row.toString());
for (VertexWritable e : entries) {
// first, are we setting a diagonal?
if (e.getCol() == rownum) {
// add to what's already present
output.setQuick(e.getCol(), output.getQuick(e.getCol()) + e.getValue());
} else {
// simply set the value
output.setQuick(e.getCol(), e.getValue());
}
}
context.write(new IntWritable(rownum), new VectorWritable(output));
}
示例2: reduce
import org.apache.mahout.math.RandomAccessSparseVector; //导入方法依赖的package包/类
@Override
protected void reduce(IntWritable row, Iterable<DistributedRowMatrix.MatrixEntryWritable> values, Context context)
throws IOException, InterruptedException {
int size = context.getConfiguration().getInt(EigencutsKeys.AFFINITY_DIMENSIONS, Integer.MAX_VALUE);
RandomAccessSparseVector out = new RandomAccessSparseVector(size, 100);
for (DistributedRowMatrix.MatrixEntryWritable element : values) {
out.setQuick(element.getCol(), element.getVal());
if (log.isDebugEnabled()) {
log.debug("(DEBUG - REDUCE) Row[{}], Column[{}], Value[{}]",
new Object[] {row.get(), element.getCol(), element.getVal()});
}
}
SequentialAccessSparseVector output = new SequentialAccessSparseVector(out);
context.write(row, new VectorWritable(output));
}
示例3: reduce
import org.apache.mahout.math.RandomAccessSparseVector; //导入方法依赖的package包/类
@Override
protected void reduce(SimilarityMatrixEntryKey key, Iterable<DistributedRowMatrix.MatrixEntryWritable> entries,
Context ctx) throws IOException, InterruptedException
{
RandomAccessSparseVector temporaryVector = new RandomAccessSparseVector(Integer.MAX_VALUE,
maxSimilaritiesPerRow);
int similaritiesSet = 0;
for (DistributedRowMatrix.MatrixEntryWritable entry : entries)
{
temporaryVector.setQuick(entry.getCol(), entry.getVal());
if (++similaritiesSet == maxSimilaritiesPerRow)
{
break;
}
}
SequentialAccessSparseVector vector = new SequentialAccessSparseVector(temporaryVector);
ctx.write(new IntWritable(key.getRow()), new VectorWritable(vector));
}
示例4: map
import org.apache.mahout.math.RandomAccessSparseVector; //导入方法依赖的package包/类
@Override
protected void map(IntWritable r, VectorWritable v, Context ctx) throws IOException, InterruptedException {
int row = r.get();
Iterator<Vector.Element> it = v.get().iterateNonZero();
while (it.hasNext()) {
Vector.Element e = it.next();
RandomAccessSparseVector tmp = new RandomAccessSparseVector(Integer.MAX_VALUE, 1);
tmp.setQuick(row, e.get());
r.set(e.index());
ctx.write(r, new VectorWritable(tmp));
}
}
示例5: writeVector
import org.apache.mahout.math.RandomAccessSparseVector; //导入方法依赖的package包/类
@Override
public void writeVector(MySparseVector vector) throws IOException {
String docIdName = String.format("%09d", ++docId); //mahout stores doc ids as Text
RandomAccessSparseVector vec = new RandomAccessSparseVector(termcount);
for (int i = 0; i < vector.indices.size(); i++)
vec.setQuick(vector.indices.get(i), vector.values.get(i));
NamedVector nv = new NamedVector(vec, docIdName);
tfidfWriter.append(new Text(docIdName), new VectorWritable(nv));
}
示例6: testRankMapCreation
import org.apache.mahout.math.RandomAccessSparseVector; //导入方法依赖的package包/类
public void testRankMapCreation() {
RandomAccessSparseVector vector = new RandomAccessSparseVector(10);
vector.setQuick(1, 10);
vector.setQuick(2, 5);
vector.setQuick(3, -2);
EvaluationUtils.RankMap rankMap = EvaluationUtils.getRankMap(vector);
assertTrue(rankMap.get(1) == 0);
assertTrue(rankMap.get(2) == 1);
assertTrue(rankMap.get(4) == 5);
assertTrue(rankMap.get(3) == 9);
}