Example usage for org.apache.hadoop.io DoubleWritable get

List of usage examples for org.apache.hadoop.io DoubleWritable get

Introduction

In this page you can find the example usage for org.apache.hadoop.io DoubleWritable get.

Prototype

public double get() 

Source Link

Usage

From source file:clustering.similarity.ISimReducer.java

License:Apache License

/**
 * @param key    groupId1,groupId2// w  w  w .j a  v  a 2  s  . c  o  m
 * @param values sim
 *               {@inheritDoc}
 */
@Override
public void reduce(IntIntTupleWritable key, Iterable<DoubleWritable> values, Context context)
        throws IOException, InterruptedException {
    double sim = 0.0d;
    for (DoubleWritable value : values) {
        sim += value.get();
    }
    if (sim > 0.01d) {
        this.outputValue.set(Math.abs(1.0d - sim));
        // docId1,docId2 \t sim
        context.write(key, this.outputValue);
    }
}

From source file:com.axiomine.largecollections.kryo.serializers.DoubleWritableSerializer.java

License:Apache License

public void write(Kryo kryo, Output output, DoubleWritable object) {
    output.writeDouble(object.get());
}

From source file:com.datasalt.pangool.utils.HadoopUtils.java

License:Apache License

/**
 * Reads maps of integer -> double/*w w  w  . j  av  a2  s. c o  m*/
 */
public static HashMap<Integer, Double> readIntDoubleMap(Path path, FileSystem fs) throws IOException {
    SequenceFile.Reader reader = new SequenceFile.Reader(fs, path, fs.getConf());

    IntWritable topic = new IntWritable();
    DoubleWritable value = new DoubleWritable();

    HashMap<Integer, Double> ret = new HashMap<Integer, Double>();

    while (reader.next(topic)) {
        reader.getCurrentValue(value);

        ret.put(topic.get(), value.get());
    }

    reader.close();
    return ret;
}

From source file:com.gotometrics.orderly.DoubleRowKey.java

License:Apache License

@Override
public Object deserialize(ImmutableBytesWritable w) throws IOException {
    DoubleWritable dw = (DoubleWritable) super.deserialize(w);
    if (dw == null)
        return dw;

    return Double.valueOf(dw.get());
}

From source file:com.ibm.bi.dml.runtime.matrix.sort.ReadWithZeros.java

License:Open Source License

public void readNextKeyValuePairs(DoubleWritable readKey, IntWritable readValue) throws IOException {
    try {/*from ww  w  . j a  va 2s. c o  m*/
        if (contain0s && justFound0) {
            readKey.set(keyAfterZero.get());
            readValue.set(valueAfterZero.get());
            contain0s = false;
        } else {
            readKey.readFields(currentStream);
            readValue.readFields(currentStream);
        }
    } catch (EOFException e) {
        // case in which zero is the maximum value in the matrix. 
        // The zero value from the last entry is not present in the input sorted matrix, but needs to be accounted for.
        if (contain0s && !justFound0) {
            justFound0 = true;
            readKey.set(0);
            readValue.set((int) numZeros);
        } else {
            throw e;
        }
    }

    if (contain0s && !justFound0 && readKey.get() >= 0) {
        justFound0 = true;
        keyAfterZero.set(readKey.get());
        valueAfterZero.set(readValue.get());
        readKey.set(0);
        readValue.set((int) numZeros);
    }
}

From source file:com.ibm.bi.dml.runtime.util.MapReduceTool.java

License:Open Source License

public static double[] pickValueWeight(String dir, NumItemsByEachReducerMetaData metadata, double p,
        boolean average) throws IOException {
    long[] counts = metadata.getNumItemsArray();
    long[] ranges = new long[counts.length];
    ranges[0] = counts[0];// www  .j  a  v a2s .  c om
    for (int i = 1; i < counts.length; i++)
        ranges[i] = ranges[i - 1] + counts[i];

    long total = ranges[ranges.length - 1];

    // do averaging only if it is asked for; and sum_wt is even
    average = average && (total % 2 == 0);

    int currentPart = 0;
    double cum_weight = 0;
    long pos = (long) Math.ceil(total * p);
    while (ranges[currentPart] < pos) {
        currentPart++;
        cum_weight += ranges[currentPart];
    }
    int offset;
    if (currentPart > 0)
        offset = (int) (pos - ranges[currentPart - 1] - 1);
    else
        offset = (int) pos - 1;

    FileSystem fs = FileSystem.get(_rJob);
    Path path = new Path(dir);
    FileStatus[] files = fs.listStatus(path);
    Path fileToRead = null;
    for (FileStatus file : files)
        if (file.getPath().toString().endsWith(Integer.toString(currentPart))) {
            fileToRead = file.getPath();
            break;
        }

    if (fileToRead == null)
        throw new RuntimeException("cannot read partition " + currentPart);

    FSDataInputStream currentStream = fs.open(fileToRead);
    DoubleWritable readKey = new DoubleWritable();
    IntWritable readValue = new IntWritable();

    boolean contain0s = false;
    long numZeros = 0;
    if (currentPart == metadata.getPartitionOfZero()) {
        contain0s = true;
        numZeros = metadata.getNumberOfZero();
    }
    ReadWithZeros reader = new ReadWithZeros(currentStream, contain0s, numZeros);

    int numRead = 0;
    while (numRead <= offset) {
        reader.readNextKeyValuePairs(readKey, readValue);
        numRead += readValue.get();
        cum_weight += readValue.get();
    }

    double ret = readKey.get();
    if (average) {
        if (numRead <= offset + 1) {
            reader.readNextKeyValuePairs(readKey, readValue);
            cum_weight += readValue.get();
            ret = (ret + readKey.get()) / 2;
        }
    }
    currentStream.close();
    return new double[] { ret, (average ? -1 : readValue.get()), (average ? -1 : cum_weight) };
}

From source file:com.kylinolap.cube.measure.DoubleMaxAggregator.java

License:Apache License

@Override
public void aggregate(DoubleWritable value) {
    if (max == null)
        max = new DoubleWritable(value.get());
    else if (max.get() < value.get())
        max.set(value.get());//from  ww  w . j a v  a2s  .  c  o  m
}

From source file:com.kylinolap.cube.measure.DoubleMinAggregator.java

License:Apache License

@Override
public void aggregate(DoubleWritable value) {
    if (min == null)
        min = new DoubleWritable(value.get());
    else if (min.get() > value.get())
        min.set(value.get());/*w  ww. j  av  a2 s  .c  o  m*/
}

From source file:com.kylinolap.cube.measure.DoubleSerializer.java

License:Apache License

@Override
public void serialize(DoubleWritable value, ByteBuffer out) {
    out.putDouble(value.get());
}

From source file:com.kylinolap.cube.measure.DoubleSumAggregator.java

License:Apache License

@Override
public void aggregate(DoubleWritable value) {
    sum.set(sum.get() + value.get());
}