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:LongestPathDAG.java

License:Apache License

@Override
public void compute(Vertex<LongWritable, DoubleWritable, FloatWritable> vertex,
        Iterable<DoubleWritable> messages) throws IOException {
    if (getSuperstep() == 0) {
        vertex.setValue(new DoubleWritable(0));
    }//from  w  w  w .ja  v  a 2s . c  o  m

    double maxDist = 0;
    for (DoubleWritable message : messages) {
        maxDist = Math.max(maxDist, message.get());
    }

    LOG.info("Vertex " + vertex.getId() + " got maxDist = " + maxDist + " vertex value = " + vertex.getValue());

    if (maxDist >= vertex.getValue().get()) {
        vertex.setValue(new DoubleWritable(maxDist));
        for (Edge<LongWritable, FloatWritable> edge : vertex.getEdges()) {
            double distance = maxDist + edge.getValue().get();
            LOG.info("Vertex " + vertex.getId() + " sent to " + edge.getTargetVertexId() + " = " + distance);
            sendMessage(edge.getTargetVertexId(), new DoubleWritable(distance));
        }
    }
    vertex.voteToHalt();
}

From source file:DoubleMinCombiner.java

License:Apache License

@Override
public void combine(LongWritable vertexIndex, DoubleWritable originalMessage, DoubleWritable messageToCombine) {
    originalMessage.set(Math.min(originalMessage.get(), messageToCombine.get()));
}

From source file:DoubleSumCombiner.java

License:Apache License

@Override
public void combine(LongWritable vertexIndex, DoubleWritable originalMessage, DoubleWritable messageToCombine) {
    originalMessage.set(originalMessage.get() + messageToCombine.get());
}

From source file:at.illecker.hama.hybrid.examples.summation.SummationBSP.java

License:Apache License

@Override
public void bsp(BSPPeer<Text, Text, Text, DoubleWritable, DoubleWritable> peer)
        throws IOException, SyncException, InterruptedException {

    BSPJob job = new BSPJob((HamaConfiguration) peer.getConfiguration());
    FileSystem fs = FileSystem.get(peer.getConfiguration());
    FSDataOutputStream outStream = fs/*from w ww .j a va  2 s.c o m*/
            .create(new Path(FileOutputFormat.getOutputPath(job), peer.getTaskId() + ".log"));

    outStream.writeChars("SummationBSP.bsp executed on CPU!\n");

    double intermediateSum = 0.0;
    Text key = new Text();
    Text value = new Text();

    while (peer.readNext(key, value)) {
        outStream.writeChars("SummationBSP.bsp key: " + key + " value: " + value + "\n");
        intermediateSum += Double.parseDouble(value.toString());
    }

    outStream.writeChars("SummationBSP.bsp send intermediateSum: " + intermediateSum + "\n");

    peer.send(m_masterTask, new DoubleWritable(intermediateSum));
    peer.sync();

    // Consume messages
    if (peer.getPeerName().equals(m_masterTask)) {
        outStream.writeChars("SummationBSP.bsp consume messages...\n");

        double sum = 0.0;
        int msg_count = peer.getNumCurrentMessages();

        for (int i = 0; i < msg_count; i++) {
            DoubleWritable msg = peer.getCurrentMessage();
            outStream.writeChars("SummationBSP.bsp message: " + msg.get() + "\n");
            sum += msg.get();
        }

        outStream.writeChars("SummationBSP.bsp write Sum: " + sum + "\n");
        peer.write(new Text("Sum"), new DoubleWritable(sum));
    }
    outStream.close();
}

From source file:at.illecker.hama.hybrid.examples.summation.SummationBSP.java

License:Apache License

static void printOutput(BSPJob job, BigDecimal sum) throws IOException {
    FileSystem fs = FileSystem.get(job.getConfiguration());
    FileStatus[] listStatus = fs.listStatus(FileOutputFormat.getOutputPath(job));
    for (FileStatus status : listStatus) {
        if (!status.isDir()) {
            try {
                SequenceFile.Reader reader = new SequenceFile.Reader(fs, status.getPath(),
                        job.getConfiguration());

                Text key = new Text();
                DoubleWritable value = new DoubleWritable();

                if (reader.next(key, value)) {
                    LOG.info("Output File: " + status.getPath());
                    LOG.info("key: '" + key + "' value: '" + value + "' expected: '" + sum.doubleValue() + "'");
                    Assert.assertEquals("Expected value: '" + sum.doubleValue() + "' != '" + value + "'",
                            sum.doubleValue(), value.get(), Math.pow(10, (DOUBLE_PRECISION * -1)));
                }//from w  w  w .java  2s .  co m
                reader.close();

            } catch (IOException e) {
                if (status.getLen() > 0) {
                    System.out.println("Output File " + status.getPath());
                    FSDataInputStream in = fs.open(status.getPath());
                    IOUtils.copyBytes(in, System.out, job.getConfiguration(), false);
                    in.close();
                }
            }
        }
    }
    // fs.delete(FileOutputFormat.getOutputPath(job), true);
}

From source file:at.illecker.hama.rootbeer.examples.hellorootbeer.HelloRootbeerGpuBSP.java

License:Apache License

@Override
public void cleanup(BSPPeer<NullWritable, NullWritable, Text, DoubleWritable, DoubleWritable> peer)
        throws IOException {

    if (peer.getPeerName().equals(m_masterTask)) {

        double sum = 0.0;

        DoubleWritable received;
        while ((received = peer.getCurrentMessage()) != null) {
            sum += received.get();
        }/*w w  w . j a  va2  s.  co m*/

        double expectedResult = peer.getNumPeers() * m_kernelCount * m_iterations;
        Assert.assertEquals(expectedResult, sum);

        peer.write(new Text(
                "Result of " + (peer.getNumPeers() * m_kernelCount * m_iterations) + " calculations is"),
                new DoubleWritable(sum));
    }
}

From source file:bookExamples.ch4.algorithms.PageRankVertexComputation.java

License:Apache License

@Override
public void compute(Vertex<LongWritable, DoubleWritable, NullWritable> vertex,
        Iterable<DoubleWritable> messages) throws IOException {

    if (getSuperstep() >= 1) {
        double sum = 0;
        for (DoubleWritable message : messages) {
            sum += message.get();
        }//from ww w .j a  v  a 2s.c o  m
        DoubleWritable vertexValue = new DoubleWritable(0.15f / getTotalNumVertices() + 0.85f * sum);
        vertex.setValue(vertexValue);
    }

    if (getSuperstep() < MAX_SUPERSTEPS) {
        long edges = vertex.getNumEdges();
        sendMessageToAllEdges(vertex, new DoubleWritable(vertex.getValue().get() / edges));
    } else {
        vertex.voteToHalt();
    }
}

From source file:bookExamples.ch4.algorithms.SimpleShortestPathsComputation.java

License:Apache License

@Override
public void compute(Vertex<LongWritable, DoubleWritable, FloatWritable> vertex,
        Iterable<DoubleWritable> messages) throws IOException {
    if (getSuperstep() == 0) {
        vertex.setValue(new DoubleWritable(Double.MAX_VALUE));
    }/*from  w  ww.  jav  a 2 s  .  c  o  m*/
    double minDist = isSource(vertex) ? 0d : Double.MAX_VALUE;
    for (DoubleWritable message : messages) {
        minDist = Math.min(minDist, message.get());
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Vertex " + vertex.getId() + " got minDist = " + minDist + " vertex value = "
                + vertex.getValue());
    }
    if (minDist < vertex.getValue().get()) {
        vertex.setValue(new DoubleWritable(minDist));
        for (Edge<LongWritable, FloatWritable> edge : vertex.getEdges()) {
            double distance = minDist + edge.getValue().get();
            if (LOG.isDebugEnabled()) {
                LOG.debug(
                        "Vertex " + vertex.getId() + " sent to " + edge.getTargetVertexId() + " = " + distance);
            }
            sendMessage(edge.getTargetVertexId(), new DoubleWritable(distance));
        }
    }
    vertex.voteToHalt();
}

From source file:clustering.mst.FinalReducer.java

License:Apache License

/**
 * @param inputKey similarity//from   w  w  w  .  j av a  2 s .c o  m
 * @param values   groupId1,groupId2
 *                 {@inheritDoc}
 */
@Override
public void reduce(DoubleWritable inputKey, Iterable<Text> values, Context context)
        throws IOException, InterruptedException {

    if (inputKey.get() < this.threshold) {
        for (Text val : values) {
            String[] srcDest = val.toString().split(",");

            int src = Integer.valueOf(srcDest[0]);
            int dest = Integer.valueOf(srcDest[1]);

            this.unionFind.union(src, dest);
        }
    }
}

From source file:clustering.similarity.ISimCombiner.java

License:Apache License

/**
 * @param key    docId1,docId2//from ww w .  j a v a 2s. co 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.001d) {
        this.outputValue.set(sim);
        // docId1,docId2 \t sim
        context.write(key, this.outputValue);
    }
}