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

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

Introduction

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

Prototype

public long getN() 

Source Link

Document

Returns the number of available values

Usage

From source file:co.turnus.common.util.CommonDataUtil.java

public static StatisticalData createFrom(SummaryStatistics summary) {
    StatisticalData data = CommonFactory.eINSTANCE.createStatisticalData();
    if (summary.getN() != 0) {
        data.setMax(summary.getMax());//from  ww  w .j a v  a2  s .c o  m
        data.setMin(summary.getMin());
        data.setSamples(summary.getN());
        data.setSum(summary.getSum());
        data.setVariance(summary.getVariance());
        data.setMean(summary.getMean());
    }
    return data;
}

From source file:edu.wisc.ssec.mcidasv.data.hydra.Statistics.java

public static Long[] histogram(FlatField field, int bins) throws VisADException {
    Long[] histogram = new Long[bins];
    EmpiricalDistribution distribution = new EmpiricalDistribution(bins);
    distribution.load(field.getValues(false)[0]);
    int k = 0;//from w ww . j  av a  2  s.co  m
    for (SummaryStatistics stats : distribution.getBinStats()) {
        histogram[k++] = stats.getN();
    }
    return histogram;
}

From source file:net.recommenders.rival.evaluation.statistics.EffectSize.java

/**
 * Computes Cohen's d, either the classical formulation (dividing the pooled
 * standard deviation by the sum of the number of samples) or using the
 * least squares estimation (substracting 2 to the sum of the number of
 * samples when normalizing the pooled standard deviation).
 *
 * @param <V> type of the keys of each map.
 * @param baselineMetricPerDimension map for the baseline method, one value
 * for each user (dimension)/*from www.  j a  v a 2  s . c  om*/
 * @param testMetricPerDimension map for the test method, one value for each
 * user (dimension)
 * @param doLeastSquares flag to use one formulation or the other (see
 * description above)
 * @return the computed Cohen's d as estimation of the effect size..
 */
public static <V> double getCohenD(final Map<V, Double> baselineMetricPerDimension,
        final Map<V, Double> testMetricPerDimension, final boolean doLeastSquares) {
    SummaryStatistics statsBaseline = new SummaryStatistics();
    for (double d : baselineMetricPerDimension.values()) {
        statsBaseline.addValue(d);
    }
    SummaryStatistics statsTest = new SummaryStatistics();
    for (double d : testMetricPerDimension.values()) {
        statsTest.addValue(d);
    }
    if (doLeastSquares) {
        return getCohenDLeastSquares((int) statsBaseline.getN(), statsBaseline.getMean(),
                statsBaseline.getStandardDeviation(), (int) statsTest.getN(), statsTest.getMean(),
                statsTest.getStandardDeviation());
    }
    return getCohenD((int) statsBaseline.getN(), statsBaseline.getMean(), statsBaseline.getStandardDeviation(),
            (int) statsTest.getN(), statsTest.getMean(), statsTest.getStandardDeviation());
}

From source file:ijfx.ui.utils.ChartUpdater.java

public void updateChart() {

    final double min; // minimum value
    final double max; // maximum value
    double range; // max - min
    final double binSize;
    // int maximumBinNumber = 30;
    int finalBinNumber;

    int differentValuesCount = possibleValues.stream().filter(n -> Double.isFinite(n.doubleValue()))
            .collect(Collectors.toSet()).size();
    if (differentValuesCount < maximumBinNumber) {
        finalBinNumber = differentValuesCount;
    } else {/*from  ww w .  j a va 2  s.  c o  m*/
        finalBinNumber = maximumBinNumber;
    }

    EmpiricalDistribution distribution = new EmpiricalDistribution(finalBinNumber);

    Double[] values = possibleValues.parallelStream().filter(n -> Double.isFinite(n.doubleValue()))
            .map(v -> v.doubleValue()).sorted()
            //.toArray();
            .toArray(size -> new Double[size]);
    distribution.load(ArrayUtils.toPrimitive(values));

    min = values[0];
    max = values[values.length - 1];
    range = max - min;
    binSize = range / (finalBinNumber - 1);

    //System.out.println(String.format("min = %.0f, max = %.0f, range = %.0f, bin size = %.0f, bin number = %d", min, max, range, binSize, finalBinNumber));

    XYChart.Series<Double, Double> serie = new XYChart.Series<>();
    ArrayList<XYChart.Data<Double, Double>> data = new ArrayList<>();
    double k = min;
    for (SummaryStatistics st : distribution.getBinStats()) {
        data.add(new XYChart.Data<>(k, new Double(st.getN())));
        k += binSize;
    }

    Platform.runLater(() -> {
        serie.getData().addAll(data);
        areaChart.getData().clear();
        areaChart.getData().add(serie);
    });

}

From source file:ijfx.core.timer.DefaultTimer.java

protected String getRow(String id, SummaryStatistics statics) {

    return String.format("%30s | %6.0fms | %6.0fms | %8d\n", id.length() > 22 ? id.substring(0, 21) : id,
            statics.getMean(), statics.getStandardDeviation(), statics.getN());

}

From source file:net.recommenders.rival.evaluation.statistics.StandardError.java

/**
 * Implements equation (8.13) from "Elementary Statistics: A Problem Solving
 * Approach 4th Edition", Andrew L. Comrey, Howard B. Lee
 *
 * @return the standard error as the ratio of the standard deviation divided
 * by the sqrt(number of users) of the distribution of difference scores.
 *//*  www  .  j a v a2 s . com*/
public double getStandardError() {
    Set<V> overlap = new HashSet<V>(baselineMetricPerDimension.keySet());
    overlap.retainAll(testMetricPerDimension.keySet());

    // paired or matched samples --> analyse distribution of difference scores
    SummaryStatistics differences = new SummaryStatistics();
    for (V key : overlap) {
        double diff = baselineMetricPerDimension.get(key) - testMetricPerDimension.get(key);
        differences.addValue(diff);
    }

    double e = differences.getStandardDeviation() / Math.sqrt(differences.getN());
    return e;
}

From source file:net.recommenders.rival.evaluation.statistics.ConfidenceInterval.java

/**
 * Method that takes only one metric as parameter. It is useful when
 * comparing more than two metrics (so that a confidence interval is
 * computed for each of them), as suggested in [Sakai, 2014]
 *
 * @param alpha probability of incorrectly rejecting the null hypothesis (1
 * - confidence_level)//from w  w w . j av  a 2  s .  co  m
 * @param metricValuesPerDimension one value of the metric for each
 * dimension
 * @return array with the confidence interval: [mean - margin of error, mean
 * + margin of error]
 */
public double[] getConfidenceInterval(final double alpha, final Map<?, Double> metricValuesPerDimension) {
    SummaryStatistics differences = new SummaryStatistics();
    for (Double d : metricValuesPerDimension.values()) {
        differences.addValue(d);
    }
    return getConfidenceInterval(alpha, (int) differences.getN() - 1, (int) differences.getN(),
            differences.getStandardDeviation(), differences.getMean());
}

From source file:net.sourceforge.jabm.report.AbstractReportVariables.java

public void recordSummaryStatistics(Object statName, Map<Object, Number> variables, SummaryStatistics stats) {
    variables.put(createVariable(statName + ".mean"), stats.getMean());
    variables.put(createVariable(statName + ".min"), stats.getMin());
    variables.put(createVariable(statName + ".max"), stats.getMax());
    variables.put(createVariable(statName + ".n"), stats.getN());
    variables.put(createVariable(statName + ".stdev"), stats.getStandardDeviation());
}

From source file:ijfx.ui.filter.DefaultNumberFilter.java

public void updateChart() {

    final double min; // minimum value
    final double max; // maximum value
    double range; // max - min
    final double binSize;
    int maximumBinNumber = 30;
    int finalBinNumber;

    int differentValuesCount = possibleValues.stream().filter(n -> Double.isFinite(n.doubleValue()))
            .collect(Collectors.toSet()).size();
    if (differentValuesCount < maximumBinNumber) {
        finalBinNumber = differentValuesCount;
    } else {//ww  w . j  a v  a  2 s . c om
        finalBinNumber = maximumBinNumber;
    }

    EmpiricalDistribution distribution = new EmpiricalDistribution(finalBinNumber);

    double[] values = possibleValues.parallelStream().filter(n -> Double.isFinite(n.doubleValue()))
            .mapToDouble(v -> v.doubleValue()).sorted().toArray();
    distribution.load(values);

    min = values[0];
    max = values[values.length - 1];
    range = max - min;
    binSize = range / (finalBinNumber - 1);

    XYChart.Series<Double, Double> serie = new XYChart.Series<>();
    ArrayList<Data<Double, Double>> data = new ArrayList<>();
    double k = min;
    for (SummaryStatistics st : distribution.getBinStats()) {
        data.add(new Data<>(k, new Double(st.getN())));
        k += binSize;
    }

    Platform.runLater(() -> {

        serie.getData().addAll(data);
        areaChart.getData().clear();

        areaChart.getData().add(serie);

        updateSlider(min, max, finalBinNumber);
    });
}

From source file:edu.washington.gs.skyline.model.quantification.RegressionFit.java

public Double computeRSquared(CalibrationCurve curve, List<WeightedObservedPoint> points) {
    SummaryStatistics yValues = new SummaryStatistics();
    SummaryStatistics residuals = new SummaryStatistics();
    for (WeightedObservedPoint point : points) {
        Double yFitted = curve.getY(point.getX());
        if (yFitted == null) {
            continue;
        }//from w  w w. j  av a  2  s.co  m
        yValues.addValue(point.getY());
        residuals.addValue(point.getY() - yFitted);
    }
    if (0 == residuals.getN()) {
        return null;
    }
    double yMean = yValues.getMean();
    double totalSumOfSquares = points.stream().mapToDouble(p -> (p.getY() - yMean) * (p.getY() - yMean)).sum();
    double sumOfSquaresOfResiduals = residuals.getSumsq();
    double rSquared = 1 - sumOfSquaresOfResiduals / totalSumOfSquares;
    return rSquared;
}