List of usage examples for org.apache.hadoop.io DoubleWritable get
public double get()
From source file:org.pentaho.hadoop.mapreduce.converter.converters.DoubleWritableToLongConverter.java
License:Apache License
@Override public Long convert(ValueMetaInterface meta, DoubleWritable obj) throws TypeConversionException { return Long.valueOf((long) obj.get()); }
From source file:org.shaf.core.util.IOUtilsTest.java
License:Apache License
/** * Test writing of {@code double} value. *///from ww w .ja va2 s. c o m @Test public void testWriteDouble() { byte[] buf = null; double value = 123.456; try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(baos);) { IOUtils.writeObject(value, out); buf = baos.toByteArray(); } catch (IOException exc) { fail(exc.getMessage()); } try (ByteArrayInputStream bais = new ByteArrayInputStream(buf); DataInputStream in = new DataInputStream(bais);) { DoubleWritable probe = new DoubleWritable(); probe.readFields(in); assertEquals(value, probe.get(), 0.0001); } catch (IOException exc) { fail(exc.getMessage()); } }
From source file:org.sleuthkit.hadoop.scoring.IIFScoreReducer.java
License:Open Source License
@Override public void reduce(Writable key, Iterable<DoubleWritable> values, Context context) { JSONObject outputRecord = new JSONObject(); double iif = 0; for (DoubleWritable iifu : values) { context.getCounter(iifCounter.COUNT).increment(1); iif = iif + iifu.get(); }/*from w w w . j a v a 2 s .c om*/ double confidence = iif / (Math.log((double) totalImages) * (double) filesInImage); try { outputRecord.put("id", new String(Hex.encodeHex(((BytesWritable) key).getBytes()))); outputRecord.put("c", confidence); outputRecord.put("iif", iif); output.put(outputRecord); } catch (JSONException ex) { ex.printStackTrace(); } }
From source file:org.smartfrog.services.hadoop.benchmark.citerank.CheckConvergenceReducer.java
License:Open Source License
@Override public void reduce(Text key, Iterator<DoubleWritable> values, OutputCollector<Text, DoubleWritable> output, Reporter report) throws IOException { double tolerance = 0; while (values.hasNext()) { DoubleWritable value = values.next(); tolerance += value.get(); }//from w w w .j a v a 2 s . c om output.collect(key, new DoubleWritable(tolerance)); }
From source file:org.smartfrog.services.hadoop.benchmark.citerank.DanglingPagesReducer.java
License:Open Source License
@Override public void reduce(Text key, Iterator<DoubleWritable> values, OutputCollector<Text, DoubleWritable> output, Reporter report) throws IOException { double sum = 0; while (values.hasNext()) { DoubleWritable value = values.next(); sum += value.get(); }//from w w w.j a va 2 s .c o m output.collect(key, new DoubleWritable(sum)); }
From source file:org.smartfrog.services.hadoop.benchmark.citerank.SortRanksReducer.java
License:Open Source License
@Override public void reduce(DoubleWritable key, Iterator<Text> values, OutputCollector<Text, Text> output, Reporter report) throws IOException { while (values.hasNext()) { Text value = values.next(); output.collect(value, new Text(CiteRank.FORMATTER.format(key.get()))); }/* w w w . j a v a 2 s. co m*/ }
From source file:org.trend.hgraph.mapreduce.pagerank.CalculateIntermediatePageRankMapper.java
License:Apache License
@Override protected void map(final Text key, final DoubleWritable value, final Context context) throws IOException, InterruptedException { String rowKey = Bytes.toString(key.getBytes()).trim(); double pageRank = value.get(); // write current pageRank to tmp Utils.writePageRank(vertexTable, rowKey, tmpPageRankCq, pageRank); Configuration conf = context.getConfiguration(); List<String> outgoingRowKeys = null; context.getCounter(Counters.VERTEX_COUNT).increment(1); outgoingRowKeys = getOutgoingRowKeys(conf, vertexTable, edgeTable, rowKey, context.getCounter(Counters.GET_OUTGOING_VERTICES_TIME_CONSUMED)); dispatchPageRank(outgoingRowKeys, pageRank, conf, edgeTable, context.getCounter(Counters.DISPATCH_PR_TIME_CONSUMED), context.getCounter(Counters.OUTGOING_EDGE_COUNT), new ContextWriterStrategy() { @Override/*from w ww. j av a 2 s . c o m*/ public void write(String key, double value) throws IOException, InterruptedException { context.write(new Text(key), new DoubleWritable(value)); } }); }
From source file:org.trend.hgraph.mapreduce.pagerank.CalculatePageRankReducer.java
License:Apache License
@Override protected void reduce(Text key, Iterable<DoubleWritable> incomingPageRanks, Context context) throws IOException, InterruptedException { String rowkey = Bytes.toString(key.getBytes()).trim(); double incomingPageRankSum = 0.0D; StopWatch sw = new StopWatch(); sw.start();/*from w w w . jav a 2 s . com*/ for (DoubleWritable incomingPageRank : incomingPageRanks) { incomingPageRankSum = incomingPageRankSum + incomingPageRank.get(); } // calculate new pageRank here double newPageRank = (dampingFactor * incomingPageRankSum) + ((1.0D - dampingFactor) / verticesTotalCnt); sw.stop(); context.getCounter(Counters.CAL_NEW_PR_TIME_CONSUMED).increment(sw.getTime()); sw.reset(); sw.start(); double oldPageRank = Utils.getPageRank(vertexTable, rowkey, Constants.PAGE_RANK_CQ_TMP_NAME); if (!pageRankEquals(oldPageRank, newPageRank, pageRankCompareScale)) { // collect pageRank changing count with counter context.getCounter(Counters.CHANGED_PAGE_RANK_COUNT).increment(1); } sw.stop(); context.getCounter(Counters.CMP_OLD_NEW_PR_TIME_CONSUMED).increment(sw.getTime()); context.write(key, new DoubleWritable(newPageRank)); }
From source file:putmerge_bycategory.NYSEReducer.java
@Override protected void reduce(Text key, Iterable<DoubleWritable> values, Context context) throws IOException, InterruptedException { double totalStockPrice = 0.0; int count = 0; for (DoubleWritable stockPrice : values) { totalStockPrice += stockPrice.get(); count++;/*from w ww. j av a 2s. com*/ } avgPrice.set(totalStockPrice / count); context.write(key, avgPrice); }
From source file:smile.wide.algorithms.em.StatCombiner.java
License:Apache License
/** * Performs the summing.//w w w . j ava 2 s.c o m */ @Override public void reduce(IntWritable key, Iterable<DoubleArrayWritable> values, Context context) throws IOException, InterruptedException { double[] totals = null; for (DoubleArrayWritable v : values) { Writable[] counts = v.get(); if (totals == null) { totals = new double[counts.length]; } for (int i = 0; i < totals.length; i++) { DoubleWritable dw = (DoubleWritable) counts[i]; totals[i] += dw.get(); } } DoubleWritable[] totalsOut = new DoubleWritable[totals.length]; for (int i = 0; i < totals.length; i++) { totalsOut[i] = new DoubleWritable(totals[i]); } context.write(key, new DoubleArrayWritable(totalsOut)); }