All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nd4j.linalg.ops.reduceops.scalarops.Mean Maven / Gradle / Ivy

There is a newer version: 1.0.0-M2.1
Show newest version
package org.nd4j.linalg.ops.reduceops.scalarops;

import org.nd4j.linalg.api.ndarray.INDArray;

/**
 *
 * @author Adam Gibson
 */
public class Mean extends BaseScalarOp {

    public Mean() {
        super(0);
    }

    @Override
    public double accumulate(INDArray arr, int i, double soFar) {
        if(i < arr.length() - 1)
            return soFar + arr.getDouble(i);
        else {
            soFar +=  arr.getDouble(i);
            soFar /= arr.length();
            // Compute initial estimate using definitional formula
            double xbar = soFar;

            // Compute correction factor in second pass
            double correction = 0;
            for (int j = 0; j < arr.length(); j++) {
                correction += arr.getDouble(j) - xbar;
            }

            return  (xbar + (correction/arr.length()));

        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy