package com.imsl.test.example.stat.distributions; import com.imsl.math.*; import com.imsl.stat.distributions.*; import java.text.DecimalFormat; /** *

* Evaluates the normal probability distribution.

*

* This example evaluates the normal (Gaussian) density, gradient, and * hessian for a small sample of data.

* * @see Code * @see Output */ public class NormalPDEx1 { public static void main(String[] args) throws Exception { double x[] = { 24.67074744935116, 23.452437146719504, 23.508058666655124, 24.085805009837582, 26.387706562892493, 26.244756646592872 }; double[] values = new double[x.length]; double mean = 25.0; double stdDev = 1.0; NormalPD normal = new NormalPD(); for (int i = 0; i < x.length; i++) { values[i] = normal.pdf(x[i], mean, stdDev); } PrintMatrixFormat pmf = new PrintMatrixFormat(); pmf.setNumberFormat(new DecimalFormat("0.00000000")); PrintMatrix pm = new PrintMatrix("Normal(25.0,1.0) pdf values at x="); pm.print(pmf, x); pm.setTitle("f(x;25,1.0)="); pm.print(pmf, values); double[] gradientApprox = normal.getPDFGradientApproximation(x[0], mean, stdDev); String title=String.format("Gradient of f(x;25.0,1.0) at x= %1.8f",x[0]); pm.setTitle(title); pm.print(pmf, gradientApprox); double[] gradient = normal.getPDFGradient(x[0], mean, stdDev); title=String.format("Analytic gradient of f(x;25.0,1.0) at x= %1.8f",x[0]); pm.setTitle(title); pm.print(pmf, gradient); double[][] hessianApprox = normal.getPDFHessianApproximation(x[0], mean, stdDev); title=String.format("Hessian of f(x;25.0,1.0) at x= %1.8f",x[0]); pm.setTitle(title); pm.print(pmf, hessianApprox); double[][] hessian = normal.getPDFHessian(x[0], mean, stdDev); title=String.format("Analytic Hessian of f(x;25.0,1.0) at x= %1.8f",x[0]); pm.setTitle(title); pm.print(pmf, hessian); } }