List of usage examples for com.google.common.collect Multiset size
int size();
From source file:org.apache.mahout.knn.generate.Multinomial.java
public Multinomial(Multiset<T> counts, int width) { Preconditions.checkArgument(counts.size() > 0, "Need some data to build sampler"); rand = RandomUtils.getRandom();/*from ww w .ja v a2 s . c o m*/ List<WeightedThing<T>> things = Lists.newArrayList(); double n = counts.size(); for (T t : counts.elementSet()) { things.add(new WeightedThing<T>(t, counts.count(t) / n)); } init(width, things); }
From source file:master.conditions.LeafCountEndCondition.java
/** * Returns true iff the given leafCounts and activeLineages * meet the end condition./*from www . j av a 2 s . c o m*/ * * @param leafCounts Multiset containing all leaf populations so far * @param activeLineages * @return true if the end condition is met. */ public boolean isMet(Multiset<Population> leafCounts, Map<Population, List<Node>> activeLineages) { int size; if (populationInput.get().isEmpty()) size = leafCounts.size(); else { size = 0; for (Population pop : populationInput.get()) size += leafCounts.count(pop); } if (includeExtant) { if (populationInput.get().isEmpty()) { for (List<Node> nodeList : activeLineages.values()) size += nodeList.size(); } else { for (Population pop : populationInput.get()) { if (activeLineages.containsKey(pop)) size += activeLineages.get(pop).size(); } } } return size == nTerminalNodes; }
From source file:edu.cornell.cs.nlp.spf.test.ccg.lambda.SingleSentencePartialCreditTestingStatistics.java
private static PartialCreditTriplet partialCompare(LogicalExpression gold, LogicalExpression label) { final Multiset<Pair<? extends LogicalExpression, ? extends LogicalExpression>> goldPairs = GetPredConstPairs .of(gold);//from www.ja v a 2 s . c o m final Multiset<Pair<? extends LogicalExpression, ? extends LogicalExpression>> labelPairs; if (label == null) { labelPairs = HashMultiset.create(); } else { labelPairs = GetPredConstPairs.of(label); } // The "intersection" of the gold and label pair sets = the number of // matches final Multiset<Pair<? extends LogicalExpression, ? extends LogicalExpression>> intersection = HashMultiset .create(); for (final Entry<Pair<? extends LogicalExpression, ? extends LogicalExpression>> entry : goldPairs .entrySet()) { intersection.setCount(entry.getElement(), Math.min(entry.getCount(), labelPairs.count(entry.getElement()))); } return new PartialCreditTriplet(goldPairs.size(), labelPairs.size(), intersection.size()); }
From source file:org.simmetrics.metrics.BlockDistance.java
@Override public float compare(Multiset<T> a, Multiset<T> b) { if (a.isEmpty() && b.isEmpty()) { return 1.0f; }/*from w ww. j av a 2 s. co m*/ if (a.isEmpty() || b.isEmpty()) { return 0.0f; } return 1.0f - distance(a, b) / (a.size() + b.size()); }
From source file:edu.berkeley.compbio.ml.MultiClassCrossValidationResults.java
public void sanityCheck() { int predictionCount = 0; for (final Multiset<L> ls : confusionMatrix.values()) { predictionCount += ls.size(); }/*from w w w .jav a 2s.co m*/ assert predictionCount == numExamples; // every example got a prediction (perhaps null) }
From source file:edu.berkeley.compbio.ml.MultiClassCrossValidationResults.java
public float sensitivity(final L label) { final Multiset<L> predictionsForLabel = confusionMatrix.get(label); final int totalWithRealLabel = predictionsForLabel.size(); final int truePositives = predictionsForLabel.count(label); return (float) truePositives / (float) totalWithRealLabel; }
From source file:edu.berkeley.compbio.ml.MultiClassCrossValidationResults.java
public float specificity(final L label) { // == sensitivity( not label ) // note "unknown" counts as a negative final Multiset<L> predictionsForLabel = confusionMatrix.get(label); final int hasLabel = predictionsForLabel.size(); final int hasLabelRight = predictionsForLabel.count(label); // true positives final int notLabelWrong = getTotalPredicted(label) - hasLabelRight; // false negatives final int notLabel = numExamples - hasLabel; final int notLabelRight = notLabel - notLabelWrong; // true negatives if (notLabel == 0) { return 1.0f; }//from w w w .j a v a 2 s . c o m return (float) notLabelRight / (float) notLabel; }
From source file:org.simmetrics.metrics.GeneralizedOverlapCoefficient.java
@Override public float compare(Multiset<T> a, Multiset<T> b) { if (a.isEmpty() && b.isEmpty()) { return 1.0f; }/*from w w w. j av a 2s . com*/ if (a.isEmpty() || b.isEmpty()) { return 0.0f; } // q r / min{q, r} return intersection(a, b).size() / (float) min(a.size(), b.size()); }
From source file:nextmethod.web.razor.parser.syntaxtree.Span.java
private String[] getSymbolGroupCounts() { final Multiset<Class<?>> counts = HashMultiset.create(); counts.addAll(symbols.stream().map(ISymbol::getClass).collect(Collectors.toList())); final String[] ret = new String[counts.size()]; int i = 0;/*from w ww.ja va 2 s . c o m*/ for (Multiset.Entry<Class<?>> entry : counts.entrySet()) { ret[i++] = String.format("%s:%d", entry.getElement().getSimpleName(), entry.getCount()); } return ret; }
From source file:master.conditions.LeafCountPostSimCondition.java
/** * Returns true iff the given inheritance trajectory * meet the post-simulation acceptance condition. * // w w w .j a va2 s. c o m * @param itraj inheritance trajectory * @return true if the end condition is met. */ @Override public boolean accept(InheritanceTrajectory itraj) { // Assemble leaf counts: Multiset<Population> leafCounts = HashMultiset.create(); for (Node leaf : itraj.getEndNodes()) leafCounts.add(leaf.getPopulation()); // Check whether condition is met: int size; if (populationInput.get().isEmpty()) size = leafCounts.size(); else { size = 0; for (Population pop : populationInput.get()) size += leafCounts.count(pop); } if (exact) return size == nTerminalNodes; if (exceed) return size >= nTerminalNodes; else return size <= nTerminalNodes; }