List of usage examples for org.apache.hadoop.io DoubleWritable DoubleWritable
public DoubleWritable()
From source file:org.apache.giraph.edge.LongDoubleHashMapEdges.java
License:Apache License
@Override public Iterator<Edge<LongWritable, DoubleWritable>> iterator() { // Returns an iterator that reuses objects. return new UnmodifiableIterator<Edge<LongWritable, DoubleWritable>>() { /** Wrapped map iterator. */ private final ObjectIterator<Long2DoubleMap.Entry> mapIterator = edgeMap.long2DoubleEntrySet() .fastIterator();//from www . j av a2s . co m /** Representative edge object. */ private final ReusableEdge<LongWritable, DoubleWritable> representativeEdge = EdgeFactory .createReusable(new LongWritable(), new DoubleWritable()); @Override public boolean hasNext() { return mapIterator.hasNext(); } @Override public Edge<LongWritable, DoubleWritable> next() { Long2DoubleMap.Entry nextEntry = mapIterator.next(); representativeEdge.getTargetVertexId().set(nextEntry.getLongKey()); representativeEdge.getValue().set(nextEntry.getDoubleValue()); return representativeEdge; } }; }
From source file:org.apache.giraph.examples.linerank.IntDoubleSumCombiner.java
License:Apache License
@Override public DoubleWritable createInitialMessage() { return new DoubleWritable(); }
From source file:org.apache.giraph.examples.linerank.LineRank.java
License:Apache License
/** * v1 <- initializing v1; //from ww w . ja va 2 s .com 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 DoubleWritable createAggregatedValue() { return new DoubleWritable(); }
From source file:org.apache.giraph.types.ops.DoubleTypeOps.java
License:Apache License
@Override public DoubleWritable create() { return new DoubleWritable(); }
From source file:org.apache.giraph.writable.tuple.DoubleDoubleWritable.java
License:Apache License
/** Constructor */ public DoubleDoubleWritable() { super(new DoubleWritable(), new DoubleWritable()); }
From source file:org.apache.giraph.writable.tuple.IntDoubleWritable.java
License:Apache License
/** Constructor */ public IntDoubleWritable() { super(new IntWritable(), new DoubleWritable()); }
From source file:org.apache.giraph.writable.tuple.LongDoubleWritable.java
License:Apache License
/** Constructor */ public LongDoubleWritable() { super(new LongWritable(), new DoubleWritable()); }
From source file:org.apache.hama.examples.SpMV.java
License:Apache License
/** * SpMV produces a file, which contains result dense vector in format of pairs * of integer and double. The aim of this method is to convert SpMV output to * format usable in subsequent computation - dense vector. It can be usable * for iterative solvers. IMPORTANT: currently it is used in SpMV. It can be a * bottle neck, because all input needs to be stored in memory. * /*from ww w . j av a 2 s. com*/ * @param SpMVoutputPathString output path, which represents directory with * part files. * @param conf configuration * @return path to output vector. * @throws IOException */ public static String convertSpMVOutputToDenseVector(String SpMVoutputPathString, HamaConfiguration conf) throws IOException { List<Integer> indeces = new ArrayList<Integer>(); List<Double> values = new ArrayList<Double>(); FileSystem fs = FileSystem.get(conf); Path SpMVOutputPath = new Path(SpMVoutputPathString); Path resultOutputPath = SpMVOutputPath.getParent().suffix("/result"); FileStatus[] stats = fs.listStatus(SpMVOutputPath); for (FileStatus stat : stats) { String filePath = stat.getPath().toUri().getPath(); SequenceFile.Reader reader = null; fs.open(new Path(filePath)); try { reader = new SequenceFile.Reader(fs, new Path(filePath), conf); IntWritable key = new IntWritable(); DoubleWritable value = new DoubleWritable(); while (reader.next(key, value)) { indeces.add(key.get()); values.add(value.get()); } } catch (IOException e) { throw new RuntimeException(e); } finally { if (reader != null) reader.close(); } } DenseVectorWritable result = new DenseVectorWritable(); result.setSize(indeces.size()); for (int i = 0; i < indeces.size(); i++) result.addCell(indeces.get(i), values.get(i)); writeToFile(resultOutputPath.toString(), result, conf); return resultOutputPath.toString(); }
From source file:org.apache.hama.examples.util.WritableUtil.java
License:Apache License
/** * SpMV produces a file, which contains result dense vector in format of pairs * of integer and double. The aim of this method is to convert SpMV output to * format usable in subsequent computation - dense vector. It can be usable * for iterative solvers. IMPORTANT: currently it is used in SpMV. It can be a * bottle neck, because all input needs to be stored in memory. * //from w ww .j a va 2 s .c om * @param SpMVoutputPathString * output path, which represents directory with part files. * @param conf * configuration * @return path to output vector. * @throws IOException */ public static String convertSpMVOutputToDenseVector(String SpMVoutputPathString, Configuration conf) throws IOException { List<Integer> indeces = new ArrayList<Integer>(); List<Double> values = new ArrayList<Double>(); FileSystem fs = FileSystem.get(conf); Path SpMVOutputPath = new Path(SpMVoutputPathString); Path resultOutputPath = SpMVOutputPath.getParent().suffix("/result"); FileStatus[] stats = fs.listStatus(SpMVOutputPath); for (FileStatus stat : stats) { String filePath = stat.getPath().toUri().getPath(); SequenceFile.Reader reader = null; fs.open(new Path(filePath)); try { reader = new SequenceFile.Reader(fs, new Path(filePath), conf); IntWritable key = new IntWritable(); DoubleWritable value = new DoubleWritable(); while (reader.next(key, value)) { indeces.add(key.get()); values.add(value.get()); } } catch (IOException e) { throw new RuntimeException(e); } finally { if (reader != null) reader.close(); } } DenseVectorWritable result = new DenseVectorWritable(); result.setSize(indeces.size()); for (int i = 0; i < indeces.size(); i++) result.addCell(indeces.get(i), values.get(i)); writeToFile(resultOutputPath.toString(), result, conf); return resultOutputPath.toString(); }