Refine search
private static <E> int[] getCountCounts(Counter<E> counter) { int[] countCounts = new int[11]; for (int i = 0; i <= 10; i++) { countCounts[i] = 0; } for (E key : counter.keySet()) { int count = (int) Math.round(counter.getCount(key)); if (count <= 10) { countCounts[count]++; } } return countCounts; }
/** * Places the minimum of first and second keys values in the first counter. * @param <E> */ public static <E> void minInPlace(Counter<E> target, Counter<E> other){ for(E e: CollectionUtils.union(other.keySet(), target.keySet())){ target.setCount(e, Math.min(target.getCount(e), other.getCount(e))); } }
/** * Places the maximum of first and second keys values in the first counter. * @param <E> */ public static <E> void maxInPlace(Counter<E> target, Counter<E> other) { for(E e: CollectionUtils.union(other.keySet(), target.keySet())){ target.setCount(e, Math.max(target.getCount(e), other.getCount(e))); } }
private void checkParameters(Counter<E> parameters) { for (E o : parameters.keySet()) { if (parameters.getCount(o) < 0.0) { throw new RuntimeException("Parameters must be non-negative!"); } } if (parameters.totalCount() <= 0.0) { throw new RuntimeException("Parameters must have positive mass!"); } }
/** * Divides every non-zero count in target by the corresponding value in the * denominator Counter. Beware that this can give NaN values for zero counts * in the denominator counter! */ public static <E> void divideInPlace(Counter<E> target, Counter<E> denominator) { for (E key : target.keySet()) { target.setCount(key, target.getCount(key) / denominator.getCount(key)); } }
/** * Returns the set of keys that have exactly the given count. This set may * have 0 elements but will not be null. */ public static <E> Set<E> keysAt(Counter<E> c, double count) { Set<E> keys = Generics.newHashSet(); for (E key : c.keySet()) { if (c.getCount(key) == count) { keys.add(key); } } return (keys); }
/** * Returns the set of keys whose counts are at or below the given threshold. * This set may have 0 elements but will not be null. */ public static <E> Set<E> keysBelow(Counter<E> c, double countThreshold) { Set<E> keys = Generics.newHashSet(); for (E key : c.keySet()) { if (c.getCount(key) <= countThreshold) { keys.add(key); } } return (keys); }
public static <E> List<Pair<E, Double>> toDescendingMagnitudeSortedListWithCounts(Counter<E> c) { List<E> keys = new ArrayList<>(c.keySet()); Collections.sort(keys, toComparator(c, false, true)); List<Pair<E, Double>> l = new ArrayList<>(keys.size()); for (E key : keys) { l.add(new Pair<>(key, c.getCount(key))); } return l; }