/** {@inheritDoc} */ @Override public void addAll(Counter<E> counter) { Counters.addInPlace(this, counter); }
/** {@inheritDoc} */ public void addAll(Counter<E> counter) { Counters.addInPlace(this, counter); }
@Override public void addAll(Counter<E> counter) { Counters.addInPlace(this, counter); }
/** * For all keys (u,v) in arg1 and arg2, sets return[u,v] to be summation of both. * @param <T1> * @param <T2> */ public static <T1, T2> TwoDimensionalCounter<T1, T2> add(TwoDimensionalCounter<T1, T2> arg1, TwoDimensionalCounter<T1, T2> arg2) { TwoDimensionalCounter<T1, T2> add = new TwoDimensionalCounter<>(); Counters.addInPlace(add , arg1); Counters.addInPlace(add , arg2); return add; }
public void addFeatures(Collection<String> feat) { if(features == null){ features = new ClassicCounter<>(); } Counters.addInPlace(features, feat); }
/** * Returns a Counter that is the union of the two Counters passed in (counts * are added). * * @return A Counter that is the union of the two Counters passed in (counts * are added). */ @SuppressWarnings("unchecked") public static <E, C extends Counter<E>> C union(C c1, C c2) { C result = (C) c1.getFactory().create(); addInPlace(result, c1); addInPlace(result, c2); return result; }
/** * 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> lastPrecision() { ClassicCounter<OUT> result = new ClassicCounter<>(); Counters.addInPlace(result, previousGuessedCorrect); Counters.divideInPlace(result, previousGuessed); return result; }
public ClassicCounter<OUT> lastRecall() { ClassicCounter<OUT> result = new ClassicCounter<>(); Counters.addInPlace(result, previousGoldCorrect); Counters.divideInPlace(result, previousGold); return result; }
public Dirichlet<E> getPosteriorDistribution(Counter<E> counts) { Counter<E> newParameters = new ClassicCounter<>(parameters); Counters.addInPlace(newParameters, counts); return new Dirichlet<>(newParameters); }
public void addAll(K1 key, IntCounter<K2> c) { IntCounter<K2> myInner = getCounter(key); Counters.addInPlace(myInner, c); total += c.totalIntCount(); }
/** * For all keys (u,v) in target, sets target[u,v] to be target[u,v] + value * * @param <T1> * @param <T2> */ public static <T1, T2> void addInPlace(TwoDimensionalCounter<T1, T2> target, double value) { for (T1 outer : target.firstKeySet()){ addInPlace(target.getCounter(outer), value); } }
public void addAll(K1 key, Counter<K2> c) { ClassicCounter<K2> myInner = getCounter(key); Counters.addInPlace(myInner, c); total += c.totalCount(); }
/** * @param guesses Collection of guessed objects * @param golds Collection of gold-standard objects * @param pw {@link PrintWriter} to print eval stats */ public void eval(Collection<IN> guesses, Collection<IN> golds, PrintWriter pw) { if (verbose) { System.out.println("evaluating precision..."); } Pair<ClassicCounter<OUT>, ClassicCounter<OUT>> precision = evalPrecision(guesses, golds); previousGuessed = precision.first(); Counters.addInPlace(guessed, previousGuessed); previousGuessedCorrect = precision.second(); Counters.addInPlace(guessedCorrect, previousGuessedCorrect); if (verbose) { System.out.println("evaluating recall..."); } Pair<ClassicCounter<OUT>, ClassicCounter<OUT>> recall = evalPrecision(golds, guesses); previousGold = recall.first(); Counters.addInPlace(gold, previousGold); previousGoldCorrect = recall.second(); Counters.addInPlace(goldCorrect, previousGoldCorrect); }
public static <E> Counter<E> add(Counter<E> c1, Collection<E> c2) { Counter<E> result = c1.getFactory().create(); addInPlace(result, c1); for (E key : c2) { result.incrementCount(key, 1); } return result; }
public ClassicCounter<L> scoresOf(RVFDatum<L, F> example) { ClassicCounter<L> scores = new ClassicCounter<>(); Counters.addInPlace(scores, priors); if (addZeroValued) { Counters.addInPlace(scores, priorZero); } for (L l : labels) { double score = 0.0; Counter<F> features = example.asFeaturesCounter(); for (F f : features.keySet()) { int value = (int) features.getCount(f); score += weight(l, f, Integer.valueOf(value)); if (addZeroValued) { score -= weight(l, f, zero); } } scores.incrementCount(l, score); } return scores; }
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(); } }
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(); } }
/** * Use {@link SpanishXMLTreeReader} to load the trees from the provided files, * and begin collecting some statistics to be used in later MWE cleanup. * * NB: Much of the important cleanup happens implicitly here; the XML tree reader triggers the * tree normalization routine. */ private List<Tree> loadTrees() throws InterruptedException, IOException, ExecutionException { boolean ner = PropertiesUtils.getBool(options, "ner", false); final String encoding = new SpanishTreebankLanguagePack().getEncoding(); final SpanishXMLTreeReaderFactory trf = new SpanishXMLTreeReaderFactory(true, true, ner, false); List<Tree> trees = new ArrayList<>(); for (File file : inputFiles) { Pair<TwoDimensionalCounter<String, String>, List<Tree>> ret = processTreeFile(file, trf, encoding); Counters.addInPlace(unigramTagger, ret.first()); trees.addAll(ret.second()); } return trees; }
/** * Takes all the support vectors, and their corresponding alphas, and computes a weight * vector that can be used in a vanilla LinearClassifier. This only works because * we are using a linear kernel. The Counter is over the feature indices (+1 cos for * some reason svm_light is 1-indexed), not features. */ private static ClassicCounter<Integer> getWeights(List<Pair<Double, ClassicCounter<Integer>>> supportVectors) { ClassicCounter<Integer> weights = new ClassicCounter<>(); for (Pair<Double, ClassicCounter<Integer>> sv : supportVectors) { ClassicCounter<Integer> c = new ClassicCounter<>(sv.second()); Counters.multiplyInPlace(c, sv.first()); Counters.addInPlace(weights, c); } return weights; }