Java Mean Calculation calculateMeanLevel(float[] distribution, int mid, int oldMid, float difference)

Here you can find the source of calculateMeanLevel(float[] distribution, int mid, int oldMid, float difference)

Description

calculate Mean Level

License

Open Source License

Declaration

@Deprecated
    public static int calculateMeanLevel(float[] distribution, int mid, int oldMid, float difference) 

Method Source Code

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

public class Main {
    @Deprecated
    public static int calculateMeanLevel(float[] distribution, int mid, int oldMid, float difference) {
        return calculateMeanLevel(distribution, mid);
    }//from  ww w .  java  2  s.co  m

    /**
     * @param distribution the target array
     * @param mid          the "best guess" of the midpoint
     * @return the mid level of the distribution
     */
    public static int calculateMeanLevel(float[] distribution, int mid) {
        float adjacent = 0;
        float maxAdjacent = 0;
        int consecutive = 0;
        mid = 0;
        for (int i = 0; i < 4 && i < distribution.length; i++)
            adjacent += distribution[i];
        for (int i = 0; i < distribution.length - 4; i++) {
            adjacent -= distribution[i] - distribution[i + 4];
            if (adjacent > maxAdjacent) {
                mid = i + 2;
                maxAdjacent = adjacent + 0.00001f;
                consecutive = 0;
            } else if (adjacent > maxAdjacent - 0.00002f) {
                consecutive++;
            } else {
                mid += consecutive / 2;
                consecutive = 0;
            }
        }
        return mid;
    }
}

Related

  1. calculateMean(double[] values)
  2. calculateMean(float[] data)
  3. calculateMeanAndStandardDeviation(float[] data)
  4. calculateMeanAndStandardDeviationIgnoreNegatives( float[] data)
  5. calculateMeanAndStandardDeviationVectors( float[][] vectors)
  6. calculateMeanSD(double[] d)