@Override public Object clone() { return new IntCounter<>(this); }
public void reset() { labelsCorrect = 0; labelsIncorrect = 0; labelConfusion = new int[op.numClasses][op.numClasses]; rootLabelsCorrect = 0; rootLabelsIncorrect = 0; rootLabelConfusion = new int[op.numClasses][op.numClasses]; lengthLabelsCorrect = new IntCounter<>(); lengthLabelsIncorrect = new IntCounter<>(); equivalenceClasses = op.equivalenceClasses; equivalenceClassNames = op.equivalenceClassNames; if (op.testOptions.ngramRecordSize > 0) { ngrams = new TopNGramRecord(op.numClasses, op.testOptions.ngramRecordSize, op.testOptions.ngramRecordMaximumLength); } else { ngrams = null; } }
/** * @return the inner Counter associated with key o */ public IntCounter<K2> getCounter(K1 o) { IntCounter<K2> c = map.get(o); if (c == null) { c = new IntCounter<>(innerMF); c.setDefaultReturnValue(defaultValue); map.put(o, c); } return c; }
public VariableStrings() { varsToStrings = Generics.newHashMap(); numVarsSet = new IntCounter<>(); }
public ChineseWordFeatureExtractor(int featureLevel) { wordCounter = new IntCounter(); setFeatureLevel(featureLevel); }
/** * Loads a Counter from a text file. File must have the format of one * key/count pair per line, separated by whitespace. * * @param filename The path to the file to load the Counter from * @param c The Class to instantiate each member of the set. Must have a * String constructor. * @return The counter loaded from the file. */ public static <E> IntCounter<E> loadIntCounter(String filename, Class<E> c) throws Exception { IntCounter<E> counter = new IntCounter<>(); loadIntoCounter(filename, c, counter); return counter; }
public IntCounter<K1> totalCounts() { IntCounter<K1> tc = new IntCounter<>(); for (K1 k1:map.keySet()) { tc.setCount(k1, map.get(k1).totalCount()); } return tc; }
/** * Converts a counter to ranks; ranks start from 0 * * @return A counter where the count is the rank in the original counter */ public static <E> IntCounter<E> toRankCounter(Counter<E> c) { IntCounter<E> rankCounter = new IntCounter<>(); List<E> sortedList = toSortedList(c); for (int i = 0; i < sortedList.size(); i++) { rankCounter.setCount(sortedList.get(i), i); } return rankCounter; }
public void clearCounts() { if (foundCorrect != null) { foundCorrect.clear(); } else { foundCorrect = new IntCounter<>(); } if (foundGuessed != null) { foundGuessed.clear(); } else { foundGuessed = new IntCounter<>(); } if (correctGuesses != null) { correctGuesses.clear(); } else { correctGuesses = new IntCounter<>(); } if (tpCount != null) { Arrays.fill(tpCount, 0); } if (fnCount != null) { Arrays.fill(fnCount, 0); } if (fpCount != null) { Arrays.fill(fpCount, 0); } tokensCount = 0; tokensCorrect = 0; }
public VariableStrings() { varsToStrings = ArrayMap.newArrayMap(); numVarsSet = new IntCounter<>(MapFactory.<String, MutableInteger>arrayMapFactory()); }
/** * Build a dictionary of words collected from a corpus. * <p> * Filters out words with a frequency below the given {@code cutOff}. * * @return Words sorted by decreasing frequency, filtered to remove * any words with a frequency below {@code cutOff} */ public static List<String> generateDict(List<String> str, int cutOff) { Counter<String> freq = new IntCounter<>(); for (String aStr : str) freq.incrementCount(aStr); List<String> keys = Counters.toSortedList(freq, false); List<String> dict = new ArrayList<>(); for (String word : keys) { if (freq.getCount(word) >= cutOff) dict.add(word); } return dict; }
public Object aggregate(Class key, List<? extends CoreMap> in) { if (in == null) return null; IntCounter<Object> counter = new IntCounter<>(); for (CoreMap cm:in) { Object obj = cm.get(key); if (obj != null && (ignoreSet == null || !ignoreSet.contains(obj))) { counter.incrementCount(obj); } } if (counter.size() > 0) { return counter.argmax(); } else { return null; } } }
public void applyFeatureCountThreshold(Collection<String> data, int thresh) { IntCounter c = new IntCounter(); for (String datum : data) { for (String feat : makeFeatures(datum)) { c.incrementCount(feat); } } threshedFeatures = c.keysAbove(thresh); log.info((c.size() - threshedFeatures.size()) + " word features removed due to thresholding."); }
@Override public void initializeTraining(double numTrees) { verbose("Training ChineseMaxentLexicon."); verbose("trainOnLowCount = " + trainOnLowCount + ", trainByType = " + trainByType + ", featureLevel = " + featureLevel + ", tuneSigma = " + tuneSigma); verbose("Making dataset..."); if (featExtractor == null) { featExtractor = new ChineseWordFeatureExtractor(featureLevel); } this.datumCounter = new IntCounter<>(); }
Dataset ret = new Dataset(config.numTokens, numTrans); Counter<Integer> tokPosCount = new IntCounter<>(); log.info(Config.SEPARATOR); log.info("Generate training examples...");
tagCounts = new IntCounter<>(); wordTagCounts.put(word, tagCounts);
public IntCounter<Pair<K1, K2>> flatten() { IntCounter<Pair<K1, K2>> result = new IntCounter<>(); result.setDefaultReturnValue(defaultValue); for (K1 key1 : firstKeySet()) { IntCounter<K2> inner = getCounter(key1); for (K2 key2 : inner.keySet()) { result.setCount(new Pair<>(key1, key2), inner.getIntCount(key2)); } } return result; }
/** * Splits the state counts. Root states and the boundary tag do not * get their counts increased, and all others are doubled. Betas * and transition weights are handled later. */ private void splitStateCounts() { // double the count of states... IntCounter<String> newStateSplitCounts = new IntCounter<>(); newStateSplitCounts.addAll(stateSplitCounts); newStateSplitCounts.addAll(stateSplitCounts); // root states should only have 1 for (String root : startSymbols) { if (newStateSplitCounts.getCount(root) > 1) { newStateSplitCounts.setCount(root, 1); } } if (newStateSplitCounts.getCount(Lexicon.BOUNDARY_TAG) > 1) { newStateSplitCounts.setCount(Lexicon.BOUNDARY_TAG, 1); } stateSplitCounts = newStateSplitCounts; }
featureFrequencies = new IntCounter<>();
@Override public void finishTraining() { IntCounter<String> tagCounter = new IntCounter<>();