Java Utililty Methods mean

List of utility methods to do mean

Description

The list of methods to do mean are organized into topic(s).

Method

double[]means(double[][] input)
Return an array of the means of each column in the 2D input
double[] theMeans = sums(input);
for (int i = 0; i < theMeans.length; i++) {
    theMeans[i] = theMeans[i] / input.length;
return theMeans;
doublemeanSlow(final double[] values)
mean Slow
return sumSlow(values) / values.length;
intmeanSml(final int a, final int b)
mean Sml
int result = meanLow(a, b);
if (!haveSameEvenness(a, b)) {
    if ((a & b) < 0 || (a | b) < 0 && a + b < 0) {
        result++;
return result;
floatmeanSquare(float[] a, int off, int length)
mean Square
double d = 0.0, d1;
final int stop = off + length;
while (off < stop) {
    d1 = a[off++];
    d += d1 * d1;
return (float) (d / length);
doublemeanSquaredError(double[] x, double[] y)
mean Squared Error
double mse = 0;
for (int i = 0; i < x.length; ++i) {
    mse += Math.pow(x[i] - y[i], 2);
return mse / (double) x.length;
doublemeanSquaredError(double[][] vectorBatch1, double[][] vectorBatch2)
mean Squared Error
double error = 0;
for (int i = 0; i < vectorBatch1.length; i++) {
    error += squaredError(vectorBatch1[i], vectorBatch2[i]);
return error / vectorBatch1.length;
doublemeanWithoutZeros(int[] in, int x1, int x2)
mean Without Zeros
double res = 0;
int k = 0;
for (int i = x1; i < Math.min(in.length, x2); i++) {
    if (in[i] != 0) {
        res += in[i];
        k++;
return (1.0 * res) / k;
doublemeanWithoutZerosCentered(int[] in, int center, int width)
mean Without Zeros Centered
if (in.length > width) {
    double res = 0;
    int i = 1;
    int k = 1;
    res = in[center];
    while (k < width && (center + i < in.length || center - i > 0)) {
        if (center + i < in.length && in[center + i] != 0) {
            res += in[center + i];
...
doublestd(double[] a, double mean, boolean isUnbiasedEstimator)
std
if (a.length == 0) {
    throw new IllegalArgumentException("The entered array is empty.");
int N = a.length;
int divisor = isUnbiasedEstimator ? N - 1 : N;
double sum = 0.0;
for (int n = 0; n < N; n++) {
    sum += (a[n] - mean) * (a[n] - mean);
...
doublestd(double[] a, int size, double mean)
std
double x = 0.0;
for (int iter = 0; iter < size; iter++) {
    double val = a[iter] - mean;
    x += val * val;
return Math.sqrt(x / (double) (size - 1));