Example usage for com.google.common.collect Multiset count

List of usage examples for com.google.common.collect Multiset count

Introduction

In this page you can find the example usage for com.google.common.collect Multiset count.

Prototype

int count(@Nullable Object element);

Source Link

Document

Returns the number of occurrences of an element in this multiset (the count of the element).

Usage

From source file:org.deeplearning4j.eval.ConfusionMatrix.java

/**
 * Adds the entries from another confusion matrix to this one.
 *//*from   w  ww .ja va2s . c o m*/
public void add(ConfusionMatrix<T> other) {
    for (T actual : other.matrix.keySet()) {
        Multiset<T> counts = other.matrix.get(actual);
        for (T predicted : counts.elementSet()) {
            int count = counts.count(predicted);
            this.add(actual, predicted, count);
        }
    }
}

From source file:edu.berkeley.compbio.ml.MultiClassCrossValidationResults.java

public float precision(final L label) {
    final Multiset<L> predictionsForLabel = confusionMatrix.get(label);

    final int truePositives = predictionsForLabel.count(label);
    final float total = (float) getTotalPredicted(label);
    return total == 0 ? 1f : (float) truePositives / total;
}

From source file:org.kalypso.ogc.sensor.timeseries.TimestampGuesser.java

/**
 * This function returns the timestamp with the most occurances.
 * //from  w  ww  .ja v a 2s . co m
 * @param timestamps
 *          The timestamps
 * @return The timestamp with the most occurances.
 */
private LocalTime doGuessTimestamp(final Multiset<LocalTime> timestamps) {
    LocalTime foundTimestamp = null;
    int maxCount = 0;
    for (final LocalTime timestamp : timestamps) {
        final int count = timestamps.count(timestamp);
        if (count > maxCount) {
            foundTimestamp = timestamp;
            maxCount = count;
        }
    }

    return foundTimestamp;
}

From source file:com.opengamma.strata.report.framework.expression.IterableTokenEvaluator.java

@Override
public Set<String> tokens(Iterable<?> iterable) {
    Multiset<String> tokens = HashMultiset.create();
    int index = 0;

    for (Object item : iterable) {
        tokens.add(String.valueOf(index++));
        tokens.addAll(fieldValues(item));
    }//from w  ww .  j  a v  a2  s. co m
    return tokens.stream().filter(token -> tokens.count(token) == 1).collect(toImmutableSet());
}

From source file:org.sonar.plugins.qi.AbstractViolationsDecorator.java

/**
 * Calculates the weighted violations/*from ww w .  j a  v a2 s  .  c o  m*/
 *
 * @param weights    the weights to be used
 * @param violations the violations
 * @param context    the context
 * @return the crossed sum at the level + the sum of children
 */
protected double getWeightedViolations(Map<RulePriority, Integer> weights, Multiset<RulePriority> violations,
        DecoratorContext context) {
    double weightedViolations = 0.0;
    for (Map.Entry<RulePriority, Integer> entry : weights.entrySet()) {
        weightedViolations += entry.getValue() * violations.count(entry.getKey());
    }
    for (DecoratorContext childContext : context.getChildren()) {
        weightedViolations += MeasureUtils.getValue(childContext.getMeasure(getWeightedViolationMetricKey()),
                0.0);
    }
    return weightedViolations;
}

From source file:master.conditions.LeafCountEndCondition.java

/**
 * Returns true iff the given leafCounts and activeLineages
 * meet the end condition.//  ww w . j  a  va  2s.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.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   ww w  .  ja va 2  s  . c om

    return (float) notLabelRight / (float) notLabel;
}

From source file:org.apache.mahout.math.random.Multinomial.java

public Multinomial(Multiset<T> counts) {
    this();//from w w  w.  ja  v  a 2 s . c  o m
    Preconditions.checkArgument(!counts.isEmpty(), "Need some data to build sampler");
    rand = RandomUtils.getRandom();
    for (T t : counts.elementSet()) {
        add(t, counts.count(t));
    }
}

From source file:edu.uci.ics.sourcerer.tools.java.component.model.cluster.ClusterMatcher.java

public Set<ClusterVersion> getClusterVersions(Collection<FqnVersion> fqns) {
    Multimap<FqnVersion, ClusterVersion> map = fqnVersionsToClusterVersions.get();
    Multiset<ClusterVersion> set = HashMultiset.create();
    for (FqnVersion fqn : fqns) {
        set.addAll(map.get(fqn));//from   ww  w .ja va 2  s .  co  m
    }
    Set<ClusterVersion> result = new HashSet<>();
    for (ClusterVersion version : set.elementSet()) {
        if (set.count(version) == version.getFqns().size()) {
            result.add(version);
        }
    }
    return result;
}