Example usage for org.apache.commons.math3.stat.descriptive.moment Mean evaluate

List of usage examples for org.apache.commons.math3.stat.descriptive.moment Mean evaluate

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat.descriptive.moment Mean evaluate.

Prototype

@Override
public double evaluate(final double[] values) throws MathIllegalArgumentException 

Source Link

Document

This default implementation calls #clear , then invokes #increment in a loop over the the input array, and then uses #getResult to compute the return value.

Usage

From source file:cz.cuni.mff.d3s.spl.utils.StatisticsUtils.java

/** Compute arithmetic mean of given data.
 * /*from   w w w.j  av a  2s  .  c  o m*/
 * @param values Array of values to compute the mean from.
 * @return Mean of the provided values.
 */
public static double mean(double... values) {
    Mean mean = new Mean();
    return mean.evaluate(values);
}

From source file:cz.cuni.mff.d3s.spl.data.BenchmarkRunSummary.java

/** Compute artihmetic mean of the samples.
 * //from w  w w.  j ava2 s .co m
 * @return Arithmetic mean of the data in the original benchmark run.
 */
public synchronized double getMean() {
    if (cacheMean == null) {
        Mean mean = new Mean();
        cacheMean = mean.evaluate(data);
    }
    return cacheMean;
}

From source file:net.sf.sessionAnalysis.SessionVisitorSessionLengthNanosStatistics.java

public double computeSessionLengthMean() {
    double[] lengths = computeLengthVector();
    Mean meanObj = new Mean();
    return meanObj.evaluate(lengths);
}

From source file:de.biomedical_imaging.traj.math.MomentsCalculator.java

public double calculateNthMoment(int n) {
    Array2DRowRealMatrix gyr = RadiusGyrationTensor2D.getRadiusOfGyrationTensor(t);
    EigenDecomposition eigdec = new EigenDecomposition(gyr);

    Vector2d eigv = new Vector2d(eigdec.getEigenvector(0).getEntry(0), eigdec.getEigenvector(0).getEntry(1));

    double[] projected = new double[t.size()];
    for (int i = 0; i < t.size(); i++) {
        Vector2d pos = new Vector2d(t.get(i).x, t.get(i).y);
        double v = eigv.dot(pos);
        projected[i] = v;// w w  w  .  jav a 2  s . c  o  m
    }

    Mean m = new Mean();
    StandardDeviation s = new StandardDeviation();
    double mean = m.evaluate(projected);
    double sd = s.evaluate(projected);
    double sumPowN = 0;

    for (int i = 0; i < projected.length; i++) {
        sumPowN += Math.pow((projected[i] - mean) / sd, n);
    }

    double nThMoment = sumPowN / projected.length;

    return nThMoment;
}

From source file:eagle.security.userprofile.model.kde.UserProfileKDEModeler.java

private void computeStats(RealMatrix m) {
    if (m.getColumnDimension() != this.cmdTypes.length) {
        LOG.error("Please fix the commands list in config file");
    }//w w  w  .j  a va 2s .c om

    statistics = new UserCommandStatistics[m.getColumnDimension()];

    for (int i = 0; i < m.getColumnDimension(); i++) {
        UserCommandStatistics stats = new UserCommandStatistics();
        stats.setCommandName(this.cmdTypes[i]);
        RealVector colData = m.getColumnVector(i);
        StandardDeviation deviation = new StandardDeviation();
        double stddev = deviation.evaluate(colData.toArray());

        if (LOG.isDebugEnabled())
            LOG.debug("Stddev is NAN ? " + (Double.isNaN(stddev) ? "yes" : "no"));
        if (stddev <= lowVarianceVal)
            stats.setLowVariant(true);
        else
            stats.setLowVariant(false);

        stats.setStddev(stddev);
        Mean mean = new Mean();
        double mu = mean.evaluate(colData.toArray());
        if (LOG.isDebugEnabled())
            LOG.debug("mu is NAN ? " + (Double.isNaN(mu) ? "yes" : "no"));

        stats.setMean(mu);
        statistics[i] = stats;
    }
}

From source file:de.biomedical_imaging.traJ.features.SplineCurveSpatialFeature.java

@Override
/**//from w  w w .j  a va2s.com
 * @return [0] Mean  distance [1] SD  distance 
 */
public double[] evaluate() {
    splinefit = new TrajectorySplineFit(t, nSegments);
    splinefit.calculateSpline();
    if (!splinefit.wasSuccessfull()) {
        return new double[] { Double.NaN, Double.NaN };
    }
    double[] data = new double[t.size()];
    for (int i = 0; i < t.size(); i++) {

        Point2D.Double help = new Point2D.Double(splinefit.getRotatedTrajectory().get(i).x,
                splinefit.getRotatedTrajectory().get(i).y);
        data[i] = help.distance(splinefit.minDistancePointSpline(new Point2D.Double(
                splinefit.getRotatedTrajectory().get(i).x, splinefit.getRotatedTrajectory().get(i).y), 50));
    }
    Mean m = new Mean();
    StandardDeviation sd = new StandardDeviation();
    result = new double[] { m.evaluate(data), sd.evaluate(data) };
    return result;

}

From source file:br.unicamp.ic.recod.gpsi.measures.gpsiNormalBhattacharyyaDistanceScore.java

@Override
public double score(double[][][] input) {

    Mean mean = new Mean();
    Variance var = new Variance();

    double mu0, sigs0, mu1, sigs1;
    double dist[][] = new double[2][];

    dist[0] = MatrixUtils.createRealMatrix(input[0]).getColumn(0);
    dist[1] = MatrixUtils.createRealMatrix(input[1]).getColumn(0);

    mu0 = mean.evaluate(dist[0]);
    sigs0 = var.evaluate(dist[0]) + Double.MIN_VALUE;
    mu1 = mean.evaluate(dist[1]);//w w w . j av a2 s.  co  m
    sigs1 = var.evaluate(dist[1]) + Double.MIN_VALUE;

    double distance = (Math.log((sigs0 / sigs1 + sigs1 / sigs0 + 2) / 4)
            + (Math.pow(mu1 - mu0, 2.0) / (sigs0 + sigs1))) / 4;

    return distance == Double.POSITIVE_INFINITY ? 0 : distance;

}

From source file:eagle.security.userprofile.model.eigen.UserProfileEigenModeler.java

private void computeStats(RealMatrix m) {

    if (m.getColumnDimension() != this.cmdTypes.length) {
        LOG.error("Please fix the commands list in config file");
        return;// w w  w  .j a v  a 2s. c  o  m
    }
    statistics = new UserCommandStatistics[m.getColumnDimension()];
    for (int i = 0; i < m.getColumnDimension(); i++) {
        UserCommandStatistics stats = new UserCommandStatistics();
        stats.setCommandName(this.cmdTypes[i]);
        RealVector colData = m.getColumnVector(i);
        StandardDeviation deviation = new StandardDeviation();
        double stddev = deviation.evaluate(colData.toArray());
        //LOG.info("stddev is nan?" + (stddev == Double.NaN? "yes":"no"));
        if (stddev <= lowVarianceVal)
            stats.setLowVariant(true);
        else
            stats.setLowVariant(false);
        stats.setStddev(stddev);
        Mean mean = new Mean();
        double mu = mean.evaluate(colData.toArray());
        //LOG.info("mu is nan?" + (mu == Double.NaN? "yes":"no"));
        stats.setMean(mu);
        statistics[i] = stats;
    }
}

From source file:edu.uci.imbs.actor.VariablePopulationProtectionStatistics.java

private void calculateAverageBanditNumberPeasantsToPreyUpon() {
    Mean mean = new Mean();
    averageBanditNumberPeasantsToPreyUpon = mean.evaluate(numbersOfPeasantsToPreyUponDoubles);
}

From source file:gamlss.distributions.GA.java

/**  Calculates initial value of mu, by assumption these
  * values lie between observed data and the trend line.
 * @param y - vector of values of response variable
 * @return  a vector of initial values of mu
 *///from w  ww .  j  a  v  a 2s .  com
private ArrayRealVector setMuInitial(final ArrayRealVector y) {
    //mu.initial = expression({mu <- (y+mean(y))/2})
    size = y.getDimension();
    double[] out = new double[size];
    Mean mean = new Mean();
    double yMean = mean.evaluate(y.getDataRef());
    for (int i = 0; i < size; i++) {
        out[i] = (y.getEntry(i) + yMean) / 2;
    }
    return new ArrayRealVector(out, false);
}