Example usage for org.apache.commons.math3.stat.descriptive SummaryStatistics getGeometricMean

List of usage examples for org.apache.commons.math3.stat.descriptive SummaryStatistics getGeometricMean

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat.descriptive SummaryStatistics getGeometricMean.

Prototype

public double getGeometricMean() 

Source Link

Document

Returns the geometric mean of the values that have been added.

Usage

From source file:ca.mcgill.cs.creco.logic.ScoredAttribute.java

private void setNumericStats(ArrayList<TypedValue> pValues) {
    SummaryStatistics ss = new SummaryStatistics();
    double min = DEFAULT_MIN;
    double max = DEFAULT_MAX;
    ArrayList<Double> values = new ArrayList<Double>(pValues.size());
    for (TypedValue tv : pValues) {
        if (tv.isNumeric()) {
            ss.addValue(tv.getNumeric());
            if (tv.getNumeric() < min) {
                min = tv.getNumeric();//from   w ww . j  a  va2  s.  com

            }
            if (tv.getNumeric() > max) {
                max = tv.getNumeric();
            }
            values.add(tv.getNumeric());
        }

    }
    //Set bounds
    if (Double.isNaN(min)) {
        LOG.error("Min value is NaN: " + aAttributeID + ", " + aAttributeName + ", " + aCategory.getId());
    }
    if (Double.isNaN(max)) {
        LOG.error("Max value is NaN: " + aAttributeID + ", " + aAttributeName + ", " + aCategory.getId());
    }
    aMin = new TypedValue(min);
    aMax = new TypedValue(max);
    double mean = ss.getGeometricMean();
    double variance = ss.getStandardDeviation() * ss.getStandardDeviation();
    //Calculate Entropy
    double entropy = 0;
    for (TypedValue tv : pValues) {
        if (tv.isNumeric()) {
            double prob = computeNormalProbability(tv, mean, variance);
            entropy = entropy - prob * (Math.log(prob));
        }
    }
    aDefaultValue = new TypedValue(mean);
    if (!Double.isNaN(entropy)) {
        aEntropy = entropy;
    } else {
        aEntropy = 0;
    }

    //Get the correlation
    NumericCorrelator ac = new NumericCorrelator(aCategory);
    aCorrelation = ac.computeCorrelation(aAttributeID, CONSIDERATION_THRESHOLD);

    if (aIsPrice) {
        aDirection = Direction.LESS_IS_BETTER;
    } else {
        aDirection = ac.computeAttributeDirection(aAttributeID, CONSIDERATION_THRESHOLD);
    }
    //Calculate Ranking
    if (aDirection == Direction.LESS_IS_BETTER) {
        Collections.sort(values);
    } else {
        Collections.sort(values, Collections.reverseOrder());
    }
    setRank(values);
}

From source file:org.apache.tika.eval.tokens.TokenStatistics.java

@Override
public boolean equals(Object o) {

    if (this == o)
        return true;
    if (o == null || getClass() != o.getClass())
        return false;

    TokenStatistics that = (TokenStatistics) o;

    if (totalTokens != that.totalTokens)
        return false;
    if (totalUniqueTokens != that.totalUniqueTokens)
        return false;
    if (!doubleEquals(that.entropy, entropy))
        return false;
    // Probably incorrect - comparing Object[] arrays with Arrays.equals
    if (!Arrays.equals(topN, that.topN))
        return false;

    SummaryStatistics thatS = ((TokenStatistics) o).summaryStatistics;
    if (summaryStatistics.getN() != thatS.getN())
        return false;

    //if both have n==0, don't bother with the stats
    if (summaryStatistics.getN() == 0L)
        return true;
    //TODO: consider adding others...
    if (!doubleEquals(summaryStatistics.getGeometricMean(), thatS.getGeometricMean()))
        return false;
    if (!doubleEquals(summaryStatistics.getMax(), thatS.getMax()))
        return false;
    if (!doubleEquals(summaryStatistics.getMean(), thatS.getMean()))
        return false;
    if (!doubleEquals(summaryStatistics.getMin(), thatS.getMin()))
        return false;
    if (!doubleEquals(summaryStatistics.getSum(), thatS.getSum()))
        return false;
    if (!doubleEquals(summaryStatistics.getStandardDeviation(), thatS.getStandardDeviation()))
        return false;
    return true;/*w w w . j a va  2s .c om*/
}

From source file:org.apereo.portal.events.aggr.stat.JpaStatisticalSummary.java

/**
 * Returns true iff <code>object</code> is a
 * <code>SummaryStatistics</code> instance and all statistics have the
 * same values as this./*w w  w .j av  a 2 s  .c o m*/
 * @param object the object to test equality against.
 * @return true if object equals this
 */
@Override
public boolean equals(Object object) {
    if (object == this) {
        return true;
    }
    if (object instanceof SummaryStatistics == false) {
        return false;
    }
    SummaryStatistics stat = (SummaryStatistics) object;
    return Precision.equalsIncludingNaN(stat.getGeometricMean(), getGeometricMean())
            && Precision.equalsIncludingNaN(stat.getMax(), getMax())
            && Precision.equalsIncludingNaN(stat.getMean(), getMean())
            && Precision.equalsIncludingNaN(stat.getMin(), getMin())
            && Precision.equalsIncludingNaN(stat.getN(), getN())
            && Precision.equalsIncludingNaN(stat.getSum(), getSum())
            && Precision.equalsIncludingNaN(stat.getSumsq(), getSumsq())
            && Precision.equalsIncludingNaN(stat.getVariance(), getVariance());
}

From source file:org.lightjason.agentspeak.action.buildin.math.statistic.EStatisticValue.java

/**
 * returns a statistic value//from ww w.j a v a  2  s  .  c o m
 *
 * @param p_statistic statistic object
 * @return statistic value
 */
public final double value(final SummaryStatistics p_statistic) {
    switch (this) {
    case GEOMETRICMEAN:
        return p_statistic.getGeometricMean();

    case MAX:
        return p_statistic.getMax();

    case MIN:
        return p_statistic.getMin();

    case COUNT:
        return p_statistic.getN();

    case POPULATIONVARIANCE:
        return p_statistic.getPopulationVariance();

    case QUADRATICMEAN:
        return p_statistic.getQuadraticMean();

    case SECONDMOMENT:
        return p_statistic.getSecondMoment();

    case STANDARDDEVIATION:
        return p_statistic.getStandardDeviation();

    case SUM:
        return p_statistic.getSum();

    case SUMLOG:
        return p_statistic.getSumOfLogs();

    case SUMSQUARE:
        return p_statistic.getSumsq();

    case VARIANCE:
        return p_statistic.getVariance();

    case MEAN:
        return p_statistic.getMean();

    default:
        throw new CIllegalStateException(
                org.lightjason.agentspeak.common.CCommon.languagestring(this, "unknown", this));
    }
}

From source file:org.lightjason.agentspeak.action.builtin.math.statistic.EStatisticValue.java

/**
 * returns a statistic value/*from  w ww. ja  v a  2  s.co m*/
 *
 * @param p_statistic statistic object
 * @return statistic value
 */
public final double value(@Nonnull final SummaryStatistics p_statistic) {
    switch (this) {
    case GEOMETRICMEAN:
        return p_statistic.getGeometricMean();

    case MAX:
        return p_statistic.getMax();

    case MIN:
        return p_statistic.getMin();

    case COUNT:
        return p_statistic.getN();

    case POPULATIONVARIANCE:
        return p_statistic.getPopulationVariance();

    case QUADRATICMEAN:
        return p_statistic.getQuadraticMean();

    case SECONDMOMENT:
        return p_statistic.getSecondMoment();

    case STANDARDDEVIATION:
        return p_statistic.getStandardDeviation();

    case SUM:
        return p_statistic.getSum();

    case SUMLOG:
        return p_statistic.getSumOfLogs();

    case SUMSQUARE:
        return p_statistic.getSumsq();

    case VARIANCE:
        return p_statistic.getVariance();

    case MEAN:
        return p_statistic.getMean();

    default:
        throw new CIllegalStateException(
                org.lightjason.agentspeak.common.CCommon.languagestring(this, "unknown", this));
    }
}

From source file:tech.tablesaw.columns.numbers.Stats.java

private static Stats getStats(NumericColumn<?> values, SummaryStatistics summaryStatistics) {
    Stats stats = new Stats("Column: " + values.name());
    stats.min = summaryStatistics.getMin();
    stats.max = summaryStatistics.getMax();
    stats.n = summaryStatistics.getN();/*ww w .  jav  a  2 s .  co m*/
    stats.sum = summaryStatistics.getSum();
    stats.variance = summaryStatistics.getVariance();
    stats.populationVariance = summaryStatistics.getPopulationVariance();
    stats.quadraticMean = summaryStatistics.getQuadraticMean();
    stats.geometricMean = summaryStatistics.getGeometricMean();
    stats.mean = summaryStatistics.getMean();
    stats.standardDeviation = summaryStatistics.getStandardDeviation();
    stats.sumOfLogs = summaryStatistics.getSumOfLogs();
    stats.sumOfSquares = summaryStatistics.getSumsq();
    stats.secondMoment = summaryStatistics.getSecondMoment();
    return stats;
}