List of usage examples for org.apache.hadoop.io DoubleWritable get
public double get()
From source file:smile.wide.algorithms.em.StatNormalizer.java
License:Apache License
/** * Sums and normalizes the stats/*from w ww .j a va 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(); } } int handle = key.get(); if (handle >= 0) { int outcomes = outcomeCounts.get(handle); for (int i = 0; i < totals.length; i += outcomes) { double colTotal = 0; for (int j = 0; j < outcomes; j++) { colTotal += totals[i + j]; } if (colTotal > 0) { for (int j = 0; j < outcomes; j++) { totals[i + j] /= colTotal; } } else { double uniform = 1.0 / outcomes; for (int j = 0; j < outcomes; j++) { totals[i + j] = uniform; } } } } StringBuilder s = new StringBuilder(totals.length * 10); for (int i = 0; i < totals.length; i++) { if (i > 0) { s.append(' '); } s.append(totals[i]); } context.write(key, new Text(s.toString())); }
From source file:smile.wide.counter.ReduceCounter.java
License:Apache License
public void reduce(BytesWritable key, Iterable<DoubleWritable> values, Context context) throws IOException, InterruptedException { double total = 0; for (DoubleWritable p : values) { total += p.get(); }//from ww w . j a va2 s . c om byte[] bits = key.getBytes(); BitBuffer buf = new BitBuffer(bits, bits.length * 8); Network net = params.getNet(); StringBuilder out = new StringBuilder(); int[][] families = params.getFamilies(); int pos = Parameters.bitCount(families.length); int familyIndex = buf.getBits(0, pos); out.append(familyIndex); int[] keyFamily = families[familyIndex]; for (int i = 0; i < keyFamily.length; i++) { out.append(' '); int handle = keyFamily[i]; int bitsPerNode = Parameters.bitCount(net.getOutcomeCount(handle)); int outcomeIndex = buf.getBits(pos, bitsPerNode); out.append(net.getOutcomeId(handle, outcomeIndex)); pos += bitsPerNode; } context.write(new Text(out.toString()), new DoubleWritable(total)); }
From source file:teppeistudio.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(); }//from w w w .ja v a 2 s . com 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)); System.out.println(getId() + ": PageRank=" + vertexValue + " max=" + getAggregatedValue(MAX_AGG) + " min=" + getAggregatedValue(MIN_AGG)); // 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:test.LiveJournalShortestPaths.java
License:Apache License
@Override public void compute(Iterable<DoubleWritable> messages) { if (getSuperstep() == 0) { setValue(new DoubleWritable(Double.MAX_VALUE)); }/*from w w w. ja va 2 s . c o m*/ 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<IntWritable, NullWritable> edge : getEdges()) { double distance = minDist + 1;//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:test.PageRankVertex.java
License:Apache License
@Override public void compute(Iterable<DoubleWritable> messages) { double vertexValue = 1.0; if (getSuperstep() == 1) { setValue(new DoubleWritable(1.0f / getTotalNumVertices())); } else {//w w w .ja va 2s .co m double sum = 0; for (DoubleWritable message : messages) { sum += message.get(); } vertexValue = (1.0f - DAMPING_FACTOR) + (DAMPING_FACTOR * sum); setValue(new DoubleWritable(vertexValue)); if (LOG.isDebugEnabled()) { LOG.debug("Vertex " + getId() + " got Sum = " + sum + " vertex value = " + getValue()); } } if (getSuperstep() <= MAX_SUPERSTEPS) { DoubleWritable value = new DoubleWritable((double) vertexValue / getNumEdges()); for (Edge<IntWritable, NullWritable> edge : getEdges()) { if (LOG.isDebugEnabled()) { LOG.debug("Vertex " + getId() + " sent to " + edge.getTargetVertexId() + " = " + value); } sendMessage(edge.getTargetVertexId(), value); } } else { voteToHalt(); } }
From source file:top10flight.FirstReducer.java
public void reduce(Text movie, Iterable<DoubleWritable> movieRatingArray, Context context) throws IOException, InterruptedException { double totalMovieRating = 0.0; int count = 0; for (DoubleWritable movieRating : movieRatingArray) { totalMovieRating += movieRating.get(); count++;//from w w w . j a v a 2 s. co m } avgRating.set(totalMovieRating / count); context.write(movie, avgRating); }
From source file:top25products.FirstReducer.java
public void reduce(Text product, Iterable<DoubleWritable> movieRatingArray, Context context) throws IOException, InterruptedException { double totalProductRating = 0.0; int count = 0; for (DoubleWritable movieRating : movieRatingArray) { totalProductRating += movieRating.get(); count++;/*www .j a v a 2 s . c o m*/ } avgRating.set(totalProductRating / count); context.write(product, avgRating); }
From source file:tv.icntv.grade.film.utils.MathExtend.java
License:Apache License
public static void main(String[] args) { double d = divide(234L, 34L, 5); DoubleWritable dd = new DoubleWritable(d); System.out.println(dd.get()); }