Example usage for org.apache.mahout.math VectorWritable setWritesLaxPrecision

List of usage examples for org.apache.mahout.math VectorWritable setWritesLaxPrecision

Introduction

In this page you can find the example usage for org.apache.mahout.math VectorWritable setWritesLaxPrecision.

Prototype

public void setWritesLaxPrecision(boolean writesLaxPrecision) 

Source Link

Usage

From source file:Vectors.java

License:Apache License

public static void write(Vector vector, Path path, Configuration conf, boolean laxPrecision)
        throws IOException {
    FileSystem fs = FileSystem.get(path.toUri(), conf);
    FSDataOutputStream out = fs.create(path);
    try {/*from  w w w .ja v a2 s .co m*/
        VectorWritable vectorWritable = new VectorWritable(vector);
        vectorWritable.setWritesLaxPrecision(laxPrecision);
        vectorWritable.write(out);
    } finally {
        Closeables.closeQuietly(out);
    }
}

From source file:com.pocketx.gravity.recommender.cf.similarity.mapreduce.ToItemVectorsMapper.java

License:Apache License

@Override
protected void map(VarLongWritable rowIndex, VectorWritable vectorWritable, Context ctx)
        throws IOException, InterruptedException {
    Vector userRatings = vectorWritable.get();

    int numElementsBeforeSampling = userRatings.getNumNondefaultElements();
    userRatings = Vectors.maybeSample(userRatings, sampleSize);
    int numElementsAfterSampling = userRatings.getNumNondefaultElements();

    int column = TasteHadoopUtils.idToIndex(rowIndex.get());
    VectorWritable itemVector = new VectorWritable(new RandomAccessSparseVector(Integer.MAX_VALUE, 1));
    itemVector.setWritesLaxPrecision(true);
    ///*  w w w.j a v a  2s.c o m*/
    Iterator<Vector.Element> iterator = userRatings.nonZeroes().iterator();
    //
    while (iterator.hasNext()) {
        Vector.Element elem = iterator.next();
        itemVector.get().setQuick(column, elem.get());
        ctx.write(new IntWritable(elem.index()), itemVector);
    }

    ctx.getCounter(Elements.USER_RATINGS_USED).increment(numElementsAfterSampling);
    ctx.getCounter(Elements.USER_RATINGS_NEGLECTED)
            .increment(numElementsBeforeSampling - numElementsAfterSampling);
}

From source file:org.gpfvic.mahout.cf.taste.hadoop.item.PrefAndSimilarityColumnWritable.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    out.writeFloat(prefValue);/*w  w  w  . ja  va2s  .  c o  m*/
    VectorWritable vw = new VectorWritable(similarityColumn);
    vw.setWritesLaxPrecision(true);
    vw.write(out);
}

From source file:org.gpfvic.mahout.cf.taste.hadoop.item.VectorAndPrefsWritable.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    VectorWritable vw = new VectorWritable(vector);
    vw.setWritesLaxPrecision(true);
    vw.write(out);/*  www  . j a  v  a 2 s.  c o  m*/
    Varint.writeUnsignedVarInt(userIDs.size(), out);
    for (int i = 0; i < userIDs.size(); i++) {
        Varint.writeSignedVarLong(userIDs.get(i), out);
        out.writeFloat(values.get(i));
    }
}

From source file:org.gpfvic.mahout.cf.taste.hadoop.item.VectorOrPrefWritable.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    if (vector == null) {
        out.writeBoolean(false);/*from w w w. ja  v  a  2 s.co  m*/
        Varint.writeSignedVarLong(userID, out);
        out.writeFloat(value);
    } else {
        out.writeBoolean(true);
        VectorWritable vw = new VectorWritable(vector);
        vw.setWritesLaxPrecision(true);
        vw.write(out);
    }
}