Search in sources :

Example 16 with Aggregator

use of org.apache.flink.api.common.aggregators.Aggregator in project flink-mirror by flink-ci.

the class IterationSynchronizationSinkTask method checkForConvergence.

private boolean checkForConvergence() {
    if (maxNumberOfIterations == currentIteration) {
        if (log.isInfoEnabled()) {
            log.info(formatLogString("maximum number of iterations [" + currentIteration + "] reached, terminating..."));
        }
        return true;
    }
    if (convergenceAggregatorName != null) {
        @SuppressWarnings("unchecked") Aggregator<Value> aggregator = (Aggregator<Value>) aggregators.get(convergenceAggregatorName);
        if (aggregator == null) {
            throw new RuntimeException("Error: Aggregator for convergence criterion was null.");
        }
        Value aggregate = aggregator.getAggregate();
        if (convergenceCriterion.isConverged(currentIteration, aggregate)) {
            if (log.isInfoEnabled()) {
                log.info(formatLogString("convergence reached after [" + currentIteration + "] iterations, terminating..."));
            }
            return true;
        }
    }
    if (implicitConvergenceAggregatorName != null) {
        @SuppressWarnings("unchecked") Aggregator<Value> aggregator = (Aggregator<Value>) aggregators.get(implicitConvergenceAggregatorName);
        if (aggregator == null) {
            throw new RuntimeException("Error: Aggregator for default convergence criterion was null.");
        }
        Value aggregate = aggregator.getAggregate();
        if (implicitConvergenceCriterion.isConverged(currentIteration, aggregate)) {
            if (log.isInfoEnabled()) {
                log.info(formatLogString("empty workset convergence reached after [" + currentIteration + "] iterations, terminating..."));
            }
            return true;
        }
    }
    return false;
}
Also used : IntValue(org.apache.flink.types.IntValue) Value(org.apache.flink.types.Value) Aggregator(org.apache.flink.api.common.aggregators.Aggregator)

Aggregations

Aggregator (org.apache.flink.api.common.aggregators.Aggregator)16 Value (org.apache.flink.types.Value)16 HashMap (java.util.HashMap)13 ArrayList (java.util.ArrayList)10 LinkedHashSet (java.util.LinkedHashSet)10 List (java.util.List)10 Map (java.util.Map)10 InvalidProgramException (org.apache.flink.api.common.InvalidProgramException)10 ConvergenceCriterion (org.apache.flink.api.common.aggregators.ConvergenceCriterion)10 TypeComparable (org.apache.flink.api.common.operators.util.TypeComparable)5 CompositeType (org.apache.flink.api.common.typeutils.CompositeType)5 HashSet (java.util.HashSet)3 IntValue (org.apache.flink.types.IntValue)3 LongValue (org.apache.flink.types.LongValue)3 StringValue (org.apache.flink.types.StringValue)3 Test (org.junit.Test)3