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:org.apache.giraph.examples.SimplePageRankComputation2.java

License:Apache License

@Override
public void compute(Vertex<LongWritable, DoubleWritable, DoubleWritable> vertex,
        Iterable<DoubleWritable> messages) throws IOException {
    if (getSuperstep() >= 1) {
        double sum = 0;
        for (DoubleWritable message : messages) {
            sum += message.get();
        }/* w ww  .j  a v  a2 s. c  om*/
        DoubleWritable vertexValue = new DoubleWritable((0.15f / getTotalNumVertices()) + 0.85f * sum);
        vertex.setValue(vertexValue);
        aggregate(MAX_AGG, vertexValue);
        aggregate(MIN_AGG, vertexValue);
        aggregate(SUM_AGG, new LongWritable(1));
        LOG.info(vertex.getId() + ": PageRank=" + vertexValue + " max=" + getAggregatedValue(MAX_AGG) + " min="
                + getAggregatedValue(MIN_AGG));
    }

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

From source file:org.apache.giraph.examples.SimplePageRankVertex.java

License:Apache License

@Override
public void compute(Iterable<DoubleWritable> messages) {
    if (getSuperstep() >= 1) {
        double sum = 0;
        for (DoubleWritable message : messages) {
            sum += message.get();
        }//ww w  .j ava  2s.c om
        DoubleWritable vertexValue = new DoubleWritable((0.15f / getTotalNumVertices()) + 0.85f * sum);
        setValue(vertexValue);
        aggregate(MAX_AGG, vertexValue);
        aggregate(MIN_AGG, vertexValue);
        aggregate(SUM_AGG, new LongWritable(1));
        LOG.info(getId() + ": PageRank=" + vertexValue + " max=" + getAggregatedValue(MAX_AGG) + " min="
                + getAggregatedValue(MIN_AGG));
    }

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

From source file:org.apache.giraph.examples.SimpleShortestPathsTextComputation.java

License:Apache License

@Override
public void compute(Vertex<Text, DoubleWritable, FloatWritable> vertex, Iterable<DoubleWritable> messages)
        throws IOException {
    if (getSuperstep() == 0) {
        vertex.setValue(new DoubleWritable(Double.MAX_VALUE));
    }/*from  w  w  w  . j  ava  2 s.  co  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<Text, 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:org.apache.giraph.examples.SimpleShortestPathsVertex.java

License:Apache License

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

From source file:org.apache.giraph.examples.SimpleTolPageRankComputation.java

License:Apache License

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

    // YH: We'll use a trick to match how GraphLab async performs
    // PageRank w/ error tolerance termination.
    ///*from   ww  w  .  j  av a2  s . c o  m*/
    // Unlike GraphLab async, which can directly pull from neighbours,
    // we always need to send messages to keep neighbours up-to-date.
    // However, this also wakes up neighbours, which is not desirable.
    //
    // So we use two types of messages:
    // - update + signal => do more work to help me converge
    //   (equivalent to GraphLab's scatter/signal)
    // - update only => here's my final delta, I'm done
    //   (implicit in GraphLab's gather)
    //
    // Since messages (= vertex values) are always positive, we use
    // positive for update+signal and negative for update-only.

    // NOTE: We follow GraphLab's alternative way of computing PageRank,
    // which is to not divide by |V|. To get the probability value at
    // each vertex, take its PageRank value and divide by |V|.
    double oldVal = vertex.getValue().get();
    boolean signalled = false;

    if (getLogicalSuperstep() == 0) {
        vertex.getValue().set(1.0);
        oldVal = 0.0; // so delta is > 0
        signalled = true;
    } else {
        double sum = 0;
        for (DoubleWritable message : messages) {
            if (message.get() > 0) {
                signalled = true;
            }
            sum += Math.abs(message.get());
        }

        vertex.getValue().set(0.15 + 0.85 * sum);
    }

    double delta = Math.abs(oldVal - vertex.getValue().get());
    boolean converged = delta <= MIN_TOL.get(getConf());

    // send messages only when signalled
    if (delta > 0 && signalled) {
        if (!converged) {
            // update+signal message (need more help)
            sendMessageToAllEdges(vertex, new DoubleWritable(vertex.getValue().get() / vertex.getNumEdges()));
        } else {
            // update only (I'm done)
            sendMessageToAllEdges(vertex,
                    new DoubleWritable(-1.0 * vertex.getValue().get() / vertex.getNumEdges()));
        }
    }

    // always vote to halt
    vertex.voteToHalt();
}

From source file:org.apache.giraph.examples.SumAggregator.java

License:Apache License

public void aggregate(DoubleWritable value) {
    sum += value.get();
}

From source file:org.apache.giraph.examples.SumAggregator.java

License:Apache License

public void setAggregatedValue(DoubleWritable value) {
    sum = value.get();
}

From source file:org.apache.giraph.graph.LongDoubleFloatDoubleVertex.java

License:Apache License

@Override
public void initialize(LongWritable vertexIdW, DoubleWritable vertexValueW,
        Map<LongWritable, FloatWritable> edgesW, Iterable<DoubleWritable> messagesW) {
    if (vertexIdW != null) {
        vertexId = vertexIdW.get();/*from w ww.j a  v a 2  s  .  c  om*/
    }
    if (vertexValueW != null) {
        vertexValue = vertexValueW.get();
    }
    if (edgesW != null) {
        for (Map.Entry<LongWritable, FloatWritable> entry : edgesW.entrySet()) {
            verticesWithEdgeValues.put(entry.getKey().get(), entry.getValue().get());
        }
    }
    if (messagesW != null) {
        for (DoubleWritable m : messagesW) {
            messageList.add(m.get());
        }
    }
}

From source file:org.apache.giraph.graph.LongDoubleFloatDoubleVertex.java

License:Apache License

@Override
public final void setVertexValue(DoubleWritable vertexValue) {
    this.vertexValue = vertexValue.get();
}

From source file:org.apache.giraph.graph.LongDoubleFloatDoubleVertex.java

License:Apache License

@Override
void putMessages(Iterable<DoubleWritable> messages) {
    messageList.clear();/*from  w ww .ja va 2 s. c  om*/
    for (DoubleWritable message : messages) {
        messageList.add(message.get());
    }
}