Java mean meanWithoutZerosCentered(int[] in, int center, int width)

Here you can find the source of meanWithoutZerosCentered(int[] in, int center, int width)

Description

mean Without Zeros Centered

License

Open Source License

Declaration

static public double meanWithoutZerosCentered(int[] in, int center, int width) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    static public double meanWithoutZerosCentered(int[] in, int center, int width) {
        if (in.length > width) {
            double res = 0;
            int i = 1;
            int k = 1;
            res = in[center];//from  w  w w  .  j a  va2 s .c o m
            while (k < width && (center + i < in.length || center - i > 0)) {
                if (center + i < in.length && in[center + i] != 0) {
                    res += in[center + i];
                    k++;
                }
                if (center - i > 0 && in[center - i] != 0) {
                    res += in[center - i];
                    k++;
                }
                i++;
            }

            return res * 1.0 / k;
        } else {
            System.out.println("faute meanzerocentered");
            return in[center];
        }
    }
}

Related

  1. meanSml(final int a, final int b)
  2. meanSquare(float[] a, int off, int length)
  3. meanSquaredError(double[] x, double[] y)
  4. meanSquaredError(double[][] vectorBatch1, double[][] vectorBatch2)
  5. meanWithoutZeros(int[] in, int x1, int x2)
  6. std(double[] a, double mean, boolean isUnbiasedEstimator)
  7. std(double[] a, int size, double mean)
  8. std(double[] array, double mean)
  9. stdDeviation(int[] values, double mean)