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.debugger.instrumenter.test.basecompute.DerivedComputation.java

License:Apache License

@Override
protected void collect(Vertex<LongWritable, DoubleWritable, FloatWritable> vertex,
        Iterable<DoubleWritable> messages) {
    if (getSuperstep() == 0) {
        vertex.setValue(new DoubleWritable(Double.MAX_VALUE));
    }/* w ww .jav a2  s .  co m*/
    if (getSuperstep() == 8) {
        throw new RuntimeException("bug");
    }
    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());
    }
}

From source file:org.apache.giraph.edge.LongDoubleHashMapEdges.java

License:Apache License

@Override
public void setEdgeValue(LongWritable targetVertexId, DoubleWritable edgeValue) {
    if (edgeMap.containsKey(targetVertexId.get())) {
        edgeMap.put(targetVertexId.get(), edgeValue.get());
    }/*from   w ww. ja v a  2s  .c o  m*/
}

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

License:Apache License

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

    // 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 delta = 0;

    if (getLogicalSuperstep() == 0) {
        vertex.getValue().set(0.0);/*from   w ww. jav  a2s  . c  om*/
        delta = 0.15;
    }

    for (DoubleWritable message : messages) {
        delta += message.get();
    }
    vertex.getValue().set(vertex.getValue().get() + delta);

    if (getLogicalSuperstep() < MAX_SS.get(getConf()) && delta > 0) {
        sendMessageToAllEdges(vertex, new DoubleWritable(0.85 * delta / vertex.getNumEdges()));
    }

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

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

License:Apache License

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

    // 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 delta = 0;

    if (getLogicalSuperstep() == 0) {
        vertex.getValue().set(0.0);//from  www  .  jav a  2  s .co m
        delta = 0.15;
    }

    for (DoubleWritable message : messages) {
        delta += message.get();
    }

    // Termination condition based on max supersteps
    if (getLogicalSuperstep() < MAX_SS.get(getConf()) && delta > 0) {
        vertex.getValue().set(vertex.getValue().get() + delta);
        sendMessageToAllEdges(vertex, new DoubleWritable(0.85 * delta / vertex.getNumEdges()));
    }

    aggregate(MAX_AGG, new DoubleWritable(delta));

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

From source file:org.apache.giraph.examples.DeltaTolPageRankComputation.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 www. j a va  2 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 deltas are always positive, we use positive value 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 delta = 0;
    boolean signalled = false;

    if (getLogicalSuperstep() == 0) {
        vertex.getValue().set(0.0);
        delta = 0.15;
        signalled = true;
    }

    for (DoubleWritable message : messages) {
        if (message.get() > 0) {
            signalled = true;
        }
        delta += Math.abs(message.get());
    }

    vertex.getValue().set(vertex.getValue().get() + delta);
    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(0.85 * delta / vertex.getNumEdges()));
        } else {
            // update only (I'm done)
            sendMessageToAllEdges(vertex, new DoubleWritable(-0.85 * delta / vertex.getNumEdges()));
        }
    }

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

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

License:Apache License

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

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

License:Apache License

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

From source file:org.apache.giraph.examples.linerank.IntDoubleSumCombiner.java

License:Apache License

@Override
public void combine(IntWritable id, DoubleWritable left, DoubleWritable right) {
    left.set(left.get() + right.get());
}

From source file:org.apache.giraph.examples.linerank.LineRank.java

License:Apache License

/**
 * v1 <- initializing v1; /*from ww  w.  ja  v  a2  s.  c o  m*/
   while until v1 converges
   v2 <- S(G)T v1;
   v3 <- T(G)v2;
   v1 <- cv3+(1-c)r; 
 */

@Override
public void compute(Vertex<IntWritable, DoubleWritable, Directions> vertex, Iterable<DoubleWritable> messages)
        throws IOException {
    double state = 0;
    DoubleWritable sendingVal = new DoubleWritable();
    int numIncEdges = numIncidentEdges(vertex);
    if (getSuperstep() == 0L) {
        state = 1.0 / NUM_EDGES;
        vertex.getValue().set(state);
        double send = state;
        sendingVal.set(send);

    } else {
        if (getSuperstep() == MAX_SUPERSTEPS) {
            for (DoubleWritable message : messages) {
                state += message.get();
            }
            double prev = vertex.getValue().get() * numIncEdges;
            System.out.println("prev --> " + prev);
            System.out.println("current step -->" + state);
            double add = prev + state;
            System.out.println("Total-->" + add);
            vertex.getValue().set(add);
        } else {
            for (DoubleWritable message : messages) {
                state += message.get();
            }
            double normalized = state / numIncEdges;
            double firstPart = c * normalized;
            double v2 = rdf + firstPart;
            double send = v2;
            sendingVal.set(send);

            System.out.println("v2 ------------------------------------------====>" + send);

            //termination condition 
            if (getSuperstep() == 1L) {
                double prev = vertex.getValue().get();
                double delta = (Math.abs(prev - send)) * numIncEdges;
                this.aggregate(L1NORM_AGG, new DoubleWritable(delta));
            } else {
                double prev = vertex.getValue().get() * c + rdf;
                double delta = (Math.abs(prev - send)) * numIncEdges;
                this.aggregate(L1NORM_AGG, new DoubleWritable(delta));
            }
            vertex.getValue().set(normalized);
        }

    }
    System.out.println("v1------------------------->" + vertex.getValue().get());
    System.out.println("final flag------->" + flag);
    if (getSuperstep() < MAX_SUPERSTEPS - 1) {
        sendMessageToMultipleEdges(new IncidentVerticesIterator(vertex.getEdges().iterator()), sendingVal);
    }
    if (getSuperstep() == MAX_SUPERSTEPS - 1) {
        sendMessageToMultipleEdges(new IncidentAndAdjacentIterator(vertex.getEdges().iterator()), sendingVal);
    } else {
        vertex.voteToHalt();
    }

}

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

License:Apache License

public void aggregate(DoubleWritable value) {
    double val = value.get();
    if (val > max) {
        max = val;
    }//from   ww  w  .  j av  a  2s .  c  o m
}