Example usage for org.apache.commons.math3.stat.descriptive StorelessUnivariateStatistic getN

List of usage examples for org.apache.commons.math3.stat.descriptive StorelessUnivariateStatistic getN

Introduction

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

Prototype

long getN();

Source Link

Document

Returns the number of values that have been added.

Usage

From source file:com.cloudera.oryx.rdf.common.rule.NumericPrediction.java

static NumericPrediction buildNumericPrediction(Iterable<Example> examples) {
    StorelessUnivariateStatistic mean = new Mean();
    for (Example example : examples) {
        mean.increment(((NumericFeature) example.getTarget()).getValue());
    }/*from  w  w w.  j  a v a2 s. com*/
    Preconditions.checkState(mean.getN() > 0);
    return new NumericPrediction((float) mean.getResult(), (int) mean.getN());
}

From source file:org.jpmml.evaluator.functions.AggregateFunction.java

@Override
public FieldValue evaluate(List<FieldValue> arguments) {
    StorelessUnivariateStatistic statistic = createStatistic();

    DataType dataType = null;/*from  w  ww.j  a v  a  2s  .  co  m*/

    // "Missing values in the input to an aggregate function are simply ignored"
    Iterable<FieldValue> values = Iterables.filter(arguments, Predicates.notNull());
    for (FieldValue value : values) {
        statistic.increment((value.asNumber()).doubleValue());

        if (dataType != null) {
            dataType = TypeUtil.getResultDataType(dataType, value.getDataType());
        } else

        {
            dataType = value.getDataType();
        }
    }

    if (statistic.getN() == 0) {
        throw new InvalidResultException(null);
    }

    Object result = cast(getResultType(dataType), statistic.getResult());

    return FieldValueUtil.create(result);
}