/** * Returns true, if the aggregator value is zero, false otherwise. * * @param iteration The number of the iteration superstep. Ignored in this case. * @param value The aggregator value, which is compared to zero. * @return True, if the aggregator value is zero, false otherwise. */ @Override public boolean isConverged(int iteration, LongValue value) { return value.getValue() == 0; } }
@Override public Character translate(LongValue value, Character reuse) throws Exception { long l = value.getValue(); if (l < 0 || l >= MAX_VERTEX_COUNT) { throw new IllegalArgumentException("Cannot cast long value " + value + " to char."); } return (char) (l & (MAX_VERTEX_COUNT - 1)); } }
@Override public Integer translate(LongValue value, Integer reuse) throws Exception { long l = value.getValue(); if (l < 0 || l >= MAX_VERTEX_COUNT) { throw new IllegalArgumentException("Cannot cast long value " + value + " to integer."); } return (int) (l & (MAX_VERTEX_COUNT - 1)); } }
@Override public Double translate(LongValue value, Double reuse) throws Exception { return Double.longBitsToDouble(value.getValue()); } }
@Override public Tuple3<T, LongValue, FloatValue> map(Vertex<T, LongValue> value) throws Exception { output.f0 = value.f0; output.f1 = value.f1; long degree = value.f1.getValue(); // when the degree is one the logarithm is zero so avoid dividing by this value float inverseLogDegree = (degree == 1) ? 0.0f : 1.0f / (float) Math.log(value.f1.getValue()); output.f2.setValue(inverseLogDegree); return output; } }
@Override public boolean isConverged(int iteration, LongValue value) { return value.getValue() > this.value; } }
@Override public LongValue copy(LongValue from, LongValue reuse) { reuse.setValue(from.getValue()); return reuse; }
@Override public DoubleValue translate(LongValue value, DoubleValue reuse) throws Exception { if (reuse == null) { reuse = new DoubleValue(); } reuse.setValue(Double.longBitsToDouble(value.getValue())); return reuse; } }
@Override public void writeRecord(LocalClusteringCoefficient.Result<T> record) throws IOException { vertexCount++; // local clustering coefficient is only defined on vertices with // at least two neighbors yielding at least one pair of neighbors if (record.getDegree().getValue() > 1) { sumOfLocalClusteringCoefficient += record.getLocalClusteringCoefficientScore(); } }
@Override public void flatMap(Vertex<T, Degrees> vertex, Collector<Tuple2<T, DoubleValue>> out) throws Exception { if (vertex.f1.getInDegree().getValue() == 0) { output.f0 = vertex.f0; out.collect(output); } } }
@Override public void open(Configuration parameters) throws Exception { super.open(parameters); if (minimumRatio > 0.0f) { Collection<Tuple2<FloatValue, LongValue>> var; var = getRuntimeContext().getBroadcastVariable(SUM_OF_SCORES_AND_NUMBER_OF_NEIGHBOR_PAIRS); Tuple2<FloatValue, LongValue> sumAndCount = var.iterator().next(); float averageScore = sumAndCount.f0.getValue() / sumAndCount.f1.getValue(); minimumScore = Math.max(minimumScore, averageScore * minimumRatio); } }
@Override public Tuple2<FloatValue, LongValue> map(Tuple3<T, LongValue, FloatValue> value) throws Exception { long degree = value.f1.getValue(); long neighborPairs = degree * (degree - 1) / 2; sumOfScores.setValue(value.f2.getValue() * neighborPairs); numberOfNeighborPairs.setValue(neighborPairs); return output; } }
@Override public IntValue translate(LongValue value, IntValue reuse) throws Exception { if (reuse == null) { reuse = new IntValue(); } reuse.setValue(MathUtils.checkedDownCast(value.getValue())); return reuse; } }
@Override public void open(Configuration parameters) throws Exception { if (getRuntimeContext().hasBroadcastVariable("number of vertices")) { Collection<LongValue> numberOfVertices = getRuntimeContext().getBroadcastVariable("number of vertices"); this.applyFunction.setNumberOfVertices(numberOfVertices.iterator().next().getValue()); } if (getIterationRuntimeContext().getSuperstepNumber() == 1) { this.applyFunction.init(getIterationRuntimeContext()); } this.applyFunction.preSuperstep(); }
@Override public void open(Configuration parameters) throws Exception { if (getRuntimeContext().hasBroadcastVariable("number of vertices")) { Collection<LongValue> numberOfVertices = getRuntimeContext().getBroadcastVariable("number of vertices"); this.sumFunction.setNumberOfVertices(numberOfVertices.iterator().next().getValue()); } if (getIterationRuntimeContext().getSuperstepNumber() == 1) { this.sumFunction.init(getIterationRuntimeContext()); } this.sumFunction.preSuperstep(); }
@Override public void open(Configuration parameters) throws Exception { if (getRuntimeContext().hasBroadcastVariable("number of vertices")) { Collection<LongValue> numberOfVertices = getRuntimeContext().getBroadcastVariable("number of vertices"); this.gatherFunction.setNumberOfVertices(numberOfVertices.iterator().next().getValue()); } if (getIterationRuntimeContext().getSuperstepNumber() == 1) { this.gatherFunction.init(getIterationRuntimeContext()); } this.gatherFunction.preSuperstep(); }
@Override public void open(Configuration conf) { aggr = getIterationRuntimeContext().getIterationAggregator(NEGATIVE_ELEMENTS_AGGR); superstep = getIterationRuntimeContext().getSuperstepNumber(); if (superstep > 1) { previousAggr = getIterationRuntimeContext().getPreviousIterationAggregate(NEGATIVE_ELEMENTS_AGGR); // check previous aggregator value Assert.assertEquals(superstep - 1, previousAggr.getValue()); } }