package yi.stat.dist;

/**
 * A Normal Distribution
 */

public class NormalDistribution {
  double mu;
  double sigma;

  public NormalDistribution(double mu, double sigma) {
    this.mu = mu;
    this.sigma = sigma;
  }

  /**
   * Generate a frequency function (starting from min, ending with max, slice
   * number of "slice_num") of a normaldistribution.  For example, min = 0,
   * max = 1, slice_num =10, then p(0.05), p(.15), ...p(.95) will be returned
   * @param norm
   * @param min
   * @param max
   * @param step
   * @return
   */
  static public double[] getFrequencyFunction(NormalDistribution norm,
                                              double min, double max, int slice_num) {
    double[] ff = new double[slice_num];
    double step = (max - min) / slice_num;
    double x  = min + step / 2;
    for (int i=0; i<slice_num; i++, x+=step) {
      double diff = x - norm.mu;
      ff[i] = Math.exp(-0.5*diff*diff/norm.sigma) / ( Math.sqrt(2*Math.PI*norm.sigma));
    }
    return ff;
  }

}