List of usage examples for org.apache.hadoop.io DoubleWritable toString
@Override
public String toString()
From source file:HistogramBucket.java
License:Apache License
public boolean contains(double d) { for (DoubleWritable dw : splits) { if (Double.parseDouble(dw.toString()) == d) return true; }/*w w w .java2 s . co m*/ return false; }
From source file:co.nubetech.hiho.dedup.HashUtility.java
License:Apache License
public static MD5Hash getMD5Hash(DoubleWritable key) throws IOException { return MD5Hash.digest(key.toString()); }
From source file:com.pagerankcalculator.ordering.PageRankSortingReducer.java
@Override public void reduce(DoubleWritable key, Iterable<Text> values, Context context) throws IOException, InterruptedException { for (Text value : values) { if (counter < TwitterPageRank.TOP_USER_COUNT) { counter++;//from ww w.j a va 2 s.co m context.write(value, new Text(key.toString())); } else { break; } } }
From source file:com.veera.secondarysort.demo2.SsMapper.java
License:Apache License
@Override public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { String[] tokens = value.toString().split(","); String symbol = tokens[0].trim(); Long timestamp = Long.parseLong(tokens[1].trim()); Double v = Double.parseDouble(tokens[2].trim()); StockKey stockKey = new StockKey(symbol, timestamp); DoubleWritable stockValue = new DoubleWritable(v); context.write(stockKey, stockValue); _log.debug(stockKey.toString() + " => " + stockValue.toString()); }
From source file:demo.SsMapper.java
License:Apache License
@Override public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { String[] tokens = value.toString().split(","); System.out.println("Array contents " + Arrays.toString(tokens)); String symbol = tokens[0].trim(); System.out.println("Symbol " + symbol); Long timestamp = Long.parseLong(tokens[1].trim()); System.out.println("timestamp " + timestamp); Double v = Double.parseDouble(tokens[2].trim()); System.out.println("double " + v); StockKey stockKey = new StockKey(symbol, timestamp); DoubleWritable stockValue = new DoubleWritable(v); context.write(stockKey, stockValue); _log.debug(stockKey.toString() + " => " + stockValue.toString()); }
From source file:org.apache.giraph.examples.Giraphx.java
License:Apache License
public void compute_original_pagerank(Iterator<Text> msgIterator) { // Get the number of vertices that have a change in pagerank greater than tolerance LongSumAggregator prsumAggreg = (LongSumAggregator) getAggregator("prsum"); long prDiffSum = -1; if (getSuperstep() > 1) { prDiffSum = GiraphxWorkerContext.prDifferenceSum; if (getVertexId().get() == 0) { Log.info("SEREF Pagerank difference is: " + prDiffSum); }/*from w w w . j a v a 2 s. com*/ } // Halt if max superstep is reached or no vertex has a significant value change if (getSuperstep() > MAX_SUPERSTEPS || prDiffSum == 0) { voteToHalt(); return; } if (getSuperstep() == 0) { // Init pageRank value at ss=0 needsOperation = false; double init = 1.0f;// / (double)NUM_VERTICES; //tolerance = init / 100.0; setVertexValue(new Text(init + "")); } if (getSuperstep() >= 1) { double sum = 0; while (msgIterator.hasNext()) { sum += Double.parseDouble(msgIterator.next().toString()); } DoubleWritable vertexValue = new DoubleWritable((0.15f / getNumVertices()) + 0.85f * sum); double diff = Math.abs( Double.parseDouble(getVertexValue().toString()) - Double.parseDouble(vertexValue.toString())); // Log.info("SEREF: Old and new pagerank values are: " + getVertexValue() +" -> " + vertexValue); String ctr_name = "PageRank difference in superstep " + getSuperstep(); getContext().getCounter("Giraph Stats", ctr_name).increment((long) (diff / tolerance)); if (diff > tolerance) { prsumAggreg.aggregate(1); } setVertexValue(new Text(vertexValue.toString())); } if (getSuperstep() < MAX_SUPERSTEPS && prDiffSum != 0) { sendMsgToAllEdges(new Text((Double.parseDouble(getVertexValue().toString()) / getNumOutEdges()) + "")); } }
From source file:org.apache.giraph.examples.Giraphx.java
License:Apache License
private void compute_giraphx_pagerank(Iterator<Text> msgIterator) { // Get the number of vertices that have a change in pagerank greater than tolerance LongSumAggregator prsumAggreg = (LongSumAggregator) getAggregator("prsum"); long prDiffSum = -1; if (getSuperstep() > 1) { prDiffSum = GiraphxWorkerContext.prDifferenceSum; if (getVertexId().get() == 0) { Log.info("SEREF Pagerank difference is: " + prDiffSum); }/* w w w. j av a 2 s . c om*/ } if (getSuperstep() > MAX_SUPERSTEPS || prDiffSum == 0) { voteToHalt(); vertexValues.clear(); return; } if (getSuperstep() == 0) { needsOperation = false; double init = 1.0f;// / (double)NUM_VERTICES; //tolerance = init / 100.0; setVertexValue(new Text(init + "")); destEdgeIndexList.remove(getVertexId()); Text value = new Text((Double.parseDouble(getVertexValue().toString()) / getNumOutEdges()) + ""); sendMsgToAllEdges(new Text("M1:" + getVertexId() + ":" + value)); return; } double diff = -1; if (getSuperstep() >= 1) { double sum = 0; while (msgIterator.hasNext()) { // in this loop nonlocal neighbor pagerank values are read String tmp = msgIterator.next().toString(); long id = Long.parseLong(tmp.split(":")[1]); double val = Double.parseDouble(tmp.split(":")[2]); vertexValues.put(new LongWritable(id), new Text(val + "")); if (getSuperstep() == 1) { incomingEdgeIndexList.add(new LongWritable(id)); } } if (getSuperstep() == 1) { incomingEdgeIndexList.remove(getVertexId()); } else { readPagerankFromNeighbors(vertexValues, incomingEdgeIndexList); } Iterator<Entry<LongWritable, Text>> vit = vertexValues.entrySet().iterator(); while (vit.hasNext()) { Entry<LongWritable, Text> e = vit.next(); double value = Double.parseDouble(e.getValue().toString()); sum += value; } DoubleWritable vertexValue = new DoubleWritable((0.15f / getNumVertices()) + 0.85f * sum); diff = Math.abs( Double.parseDouble(getVertexValue().toString()) - Double.parseDouble(vertexValue.toString())); String ctr_name = "PageRank difference in superstep " + getSuperstep(); getContext().getCounter("Giraph Stats", ctr_name).increment((long) (diff / tolerance)); if (diff > tolerance) { prsumAggreg.aggregate(1); setVertexValue(new Text(vertexValue.toString())); } } if (getSuperstep() < MAX_SUPERSTEPS && diff > tolerance) { long edges = getNumOutEdges(); String vval = (Double.parseDouble(getVertexValue().toString()) / edges) + ""; String msg = "M1:" + getVertexId() + ":" + vval; sendMsgToDistantEdges(new Text(msg), destEdgeIndexList); } needsOperation = false; voteToHalt(); }
From source file:org.kiji.examples.wikipediarank.RankCollector.java
License:Apache License
/** {@inheritDoc} */ @Override/*from w w w.ja v a2s . c o m*/ protected void reduce(Text link, Iterable<DoubleWritable> ranks, KijiTableContext context) throws IOException { double totalRank = Heuristics.RANK_WELFARE; for (DoubleWritable rank : ranks) { totalRank += (1.0 - Heuristics.FARM_TAX) * Double.parseDouble(rank.toString()); } final EntityId eid = context.getEntityId(link.toString()); context.put(eid, "info", "score", 0, totalRank); }
From source file:top10flight.SecondReducer.java
public void reduce(DoubleWritable avgRating, Text movie, Context context) throws IOException, InterruptedException { avgR.set(Double.parseDouble(avgRating.toString())); context.write(movie, avgR);//from w w w . ja va 2s . com }
From source file:top25products.SecondReducer.java
public void reduce(DoubleWritable avgRating, Text product, Context context) throws IOException, InterruptedException { avgR.set(Double.parseDouble(avgRating.toString())); context.write(product, avgR);/*from w ww . j ava 2 s. c om*/ }