public void subtractAll(TwoDimensionalCounterInterface<K1, K2> c, boolean removeKeys) { for (K1 key : c.firstKeySet()) { Counter<K2> inner = c.getCounter(key); ClassicCounter<K2> myInner = getCounter(key); Counters.subtractInPlace(myInner, inner); if (removeKeys) Counters.retainNonZeros(myInner); total -= inner.totalCount(); } }
public void subtractAll(K1 key, IntCounter<K2> c) { IntCounter<K2> myInner = getCounter(key); Counters.subtractInPlace(myInner, c); total -= c.totalIntCount(); }
public E drawSample(Random random) { E drawn = Counters.sample(sampled); if (drawn == null) { drawn = baseMeasure.drawSample(random); } sampled.incrementCount(drawn); return drawn; }
public static <F> Multinomial<F> drawSample(Random random, Counter<F> parameters) { Counter<F> multParameters = new ClassicCounter<>(); double sum = 0.0; for (F o : parameters.keySet()) { double parameter = Gamma.drawSample(random, parameters.getCount(o)); sum += parameter; multParameters.setCount(o, parameter); } for (F o : multParameters.keySet()) { multParameters.setCount(o, multParameters.getCount(o)/sum); } return new Multinomial<>(multParameters); }
public static<E> double pearsonsCorrelationCoefficient(Counter<E> x, Counter<E> y){ double stddevX = Counters.standardDeviation(x); double stddevY = Counters.standardDeviation(y); double meanX = Counters.mean(x); double meanY = Counters.mean(y); Counter<E> t1 = Counters.add(x, -meanX); Counter<E> t2 = Counters.add(y, -meanY); Counters.divideInPlace(t1, stddevX); Counters.divideInPlace(t2, stddevY); return Counters.dotProduct(t1, t2)/ (double)(x.size() -1); }
public void addAll(TwoDimensionalCounterInterface<K1, K2> c) { for (K1 key : c.firstKeySet()) { Counter<K2> inner = c.getCounter(key); ClassicCounter<K2> myInner = getCounter(key); Counters.addInPlace(myInner, inner); total += inner.totalCount(); } }
public void subtractAll(TwoDimensionalIntCounter<K1, K2> c, boolean removeKeys) { for (K1 key : c.firstKeySet()) { IntCounter<K2> inner = c.getCounter(key); IntCounter<K2> myInner = getCounter(key); Counters.subtractInPlace(myInner, inner); if (removeKeys) { Counters.retainNonZeros(myInner); } total -= inner.totalIntCount(); } }
public void addAll(TwoDimensionalIntCounter<K1, K2> c) { for (K1 key : c.firstKeySet()) { IntCounter<K2> inner = c.getCounter(key); IntCounter<K2> myInner = getCounter(key); Counters.addInPlace(myInner, inner); total += inner.totalIntCount(); } }
/** * Constructs a new Counter with the contents of the given Counter. * <i>Implementation note:</i> A new Counter is allocated with its * own counts, but keys will be shared and should be an immutable class. * * @param c The Counter which will be copied. */ public ClassicCounter(Counter<E> c) { this(); Counters.addInPlace(this, c); setDefaultReturnValue(c.defaultReturnValue()); }
public ClassicCounter<OUT> lastRecall() { ClassicCounter<OUT> result = new ClassicCounter<>(); Counters.addInPlace(result, previousGoldCorrect); Counters.divideInPlace(result, previousGold); return result; }
public static double sampleBeta(double a, double b, Random random) { Counter<Boolean> c = new ClassicCounter<>(); c.setCount(true, a); c.setCount(false, b); Multinomial<Boolean> beta = (new Dirichlet<>(c)).drawSample(random); return beta.probabilityOf(true); }
/** */ @Override public void setCount(K1 o1, K2 o2, double count) { ClassicCounter<K2> c = getCounter(o1); double oldCount = getCount(o1, o2); total -= oldCount; c.setCount(o2, count); total += count; }
public void addFeature(String s, double v) { if(features == null){ features = new ClassicCounter<>(); } features.setCount(s, v); }
/** */ public void setCount(K1 o1, K2 o2, int count) { IntCounter<K2> c = getCounter(o1); int oldCount = getCount(o1, o2); total -= oldCount; c.setCount(o2, count); total += count; }
/** * * @param <E> * @param originalCounter * @return a copy of the original counter */ public static <E> Counter<E> getCopy(Counter<E> originalCounter) { Counter<E> copyCounter = new ClassicCounter<>(); copyCounter.addAll(originalCounter); return copyCounter; }
public void addFeatures(Collection<String> feat) { if(features == null){ features = new ClassicCounter<>(); } Counters.addInPlace(features, feat); }
/** * L1 normalize a counter. Return a counter that is a probability distribution, * so the sum of the resulting value equals 1. * * @param c The {@link Counter} to be L1 normalized. This counter is not * modified. * @return A new L1-normalized Counter based on c. */ public static <E, C extends Counter<E>> C asNormalizedCounter(C c) { return scale(c, 1.0 / c.totalCount()); }
/** */ public void incrementCount(K1 o1, K2 o2, int count) { IntCounter<K2> c = getCounter(o1); c.incrementCount(o2, count); total += count; }
/** {@inheritDoc} */ @Override public Factory<Counter<E>> getFactory() { return new ClassicCounterFactory<>(getMapFactory()); }
/** * Normalizes the target counter in-place, so the sum of the resulting values * equals 1. * * @param <E> Type of elements in TwoDimensionalCounter * @param <F> Type of elements in TwoDimensionalCounter */ public static <E, F> void normalize(TwoDimensionalCounter<E, F> target) { Counters.divideInPlace(target, target.totalCount()); }