Java Gauss gaussTable(final int steps)

Here you can find the source of gaussTable(final int steps)

Description

Returns an array of gaussian values that add up to 1 for the number of steps Solves the problem of having using an intergral to distribute values

License

Open Source License

Parameter

Parameter Description
steps Number of steps in the distribution

Return

An array of values that contains the percents of the distribution

Declaration

private static double[] gaussTable(final int steps) 

Method Source Code

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

public class Main {
    /**/* w  w w  .  ja v a 2s .co m*/
     * Returns an array of gaussian values that add up to 1 for the number of
     * steps Solves the problem of having using an intergral to distribute
     * values
     *
     * @param steps Number of steps in the distribution
     *
     * @return An array of values that contains the percents of the distribution
     */
    private static double[] gaussTable(final int steps) {
        final double[] table = new double[steps];
        final double step = 1D / steps;
        double sum = 0;
        for (int i = 0; i < steps; i++) {
            sum += gaussian(i * step);
        }
        for (int i = 0; i < steps; i++) {
            table[i] = gaussian(i * step) / sum;
        }
        return table;
    }

    /**
     * Satisfies Integral[gaussian(t),t,0,1] == 1D Therefore can distribute a
     * value as a bell curve over the intervel 0 to 1
     *
     * @param t = A value, 0 to 1, representing a percent along the curve
     *
     * @return The value of the gaussian curve at this position
     */
    private static double gaussian(double t) {
        t = 10D * t - 5D;
        return 1D / (Math.sqrt(5D) * Math.sqrt(2D * Math.PI)) * Math.exp(-t * t / 20D);
    }
}

Related

  1. gaussianIntegral(double x)
  2. gaussianPDF(double mean, double variance, double x)
  3. gaussianPDF(double mu, double sigma, double x)
  4. gaussianWindow(double mean1, double mean2, double std)
  5. gaussJordanElimination(boolean[][] matrix)