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; }
public static<E> Counter<E> getFCounter(Counter<E> precision, Counter<E> recall, double beta){ Counter<E> fscores = new ClassicCounter<>(); for(E k: precision.keySet()){ fscores.setCount(k, precision.getCount(k)*recall.getCount(k)*(1+beta*beta)/(beta*beta*precision.getCount(k) + recall.getCount(k))); } return fscores; }
/** * 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)); } }
/** * Saves a Counter as one key/count pair per line separated by white space to * the given OutputStream. Does not close the stream. */ public static <E> void saveCounter(Counter<E> c, OutputStream stream) { PrintStream out = new PrintStream(stream); for (E key : c.keySet()) { out.println(key + " " + c.getCount(key)); } }
/** * 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!"); } }
/** * 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); }