/** * This method returns total sum of counter values * @return */ public double totalCount() { if (dirty.get()) rebuildTotals(); return totalCount.get(); }
/** * This method will apply normalization to counter values and totals. */ public void normalize() { for (T key : keySet()) { setCount(key, getCount(key) / totalCount.get()); } rebuildTotals(); }
/** * This method removes all elements except of top N by counter values * @param N */ public void keepTopNElements(int N){ PriorityQueue<Pair<T, Double>> queue = asPriorityQueue(); clear(); for (int e = 0; e < N; e++) { Pair<T, Double> pair = queue.poll(); if (pair != null) incrementCount(pair.getFirst(), pair.getSecond()); } }
/** * Returns the key corresponding to this entry. * * @return the key corresponding to this entry * @throws IllegalStateException implementations may, but are not * required to, throw this exception if the entry has been * removed from the backing map. */ public Pair<K, T> getKey() { return new Pair<>(firstKey, secondKey); } }
/** * This method will increment counts of this counter by counts from other counter * @param other */ public <T2 extends T> void incrementAll(Counter<T2> other) { for (T2 element: other.keySet()) { double cnt = other.getCount(element); incrementCount(element, cnt); } }
public static <F, S, T> Triple<F, S,T> of(F first, S second, T third) { return new Triple<>(first, second, third); } }
/** * This method will increment all elements in collection * * @param elements * @param inc */ public void incrementAll(Collection<T> elements, double inc) { for (T element: elements) { incrementCount(element, inc); } }
/** * This method returns total number of elements in this CounterMap * @return */ public int totalSize() { int size = 0; for (F first: keySet()) { size += getCounter(first).size(); } return size; } }
/** * Returns an Optional describing the specified value, if non-null, otherwise returns an empty Optional. * * @param value the possibly-null value to describe * @return an Optional with a present value if the specified value is non-null, otherwise an empty Optional */ public static <T> Optional<T> ofNullable(T value){ if(value == null){ return empty(); } return new Optional<>(value); }
public static <T, E> ImmutablePair<T,E> pairOf(T key, E value) { return new ImmutablePair<T, E>(key, value); } }
public static <F, S, T, O> ImmutableQuad<F, S,T, O> of(F first, S second, T third, O fourth) { return new ImmutableQuad(first, second, third, fourth); } }
public static <F, S, T, O> Quad<F, S,T, O> of(F first, S second, T third, O fourth) { return new Quad<>(first, second, third, fourth); } }
public static <T, E> Pair<T,E> pairOf(T key, E value) { return new Pair<T, E>(key, value); } }
@Override public int hashCode(){ return get() ? 1 : 0; }
@Override public Pair<INDArray, INDArray> backprop(INDArray in, INDArray epsilon) { return new Pair<>(epsilon, null); }