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

* Evaluates the gamma probability distribution.

*

* This example evaluates the gamma density, gradient, and hessian for a small * sample of data.

* * @see Code * @see Output */ public class GammaPDEx1 { public static void main(String[] args) throws Exception { double x[] = { 1.015998e0, 0.2677489e0, 2.198958e0, 1.784697e0, 0.691063e0, 0.992409e0, 0.5466309e0, 1.154601e0, 2.613015e0, 1.219826e0 }; double[] values = new double[x.length]; double a = 3.0; double b = 2.0; GammaPD gamma = new GammaPD(); for (int i = 0; i < x.length; i++) { values[i] = gamma.pdf(x[i], a, b); } PrintMatrixFormat pmf = new PrintMatrixFormat(); pmf.setNumberFormat(new DecimalFormat("0.00000000")); PrintMatrix pm = new PrintMatrix("Gamma(3.0,2.0) pdf values at x="); pm.print(pmf, x); pm.setTitle("f(x;3,2)="); pm.print(pmf, values); double[] gradient = gamma.getPDFGradientApproximation(x[0], a, b); String title=String.format("Gradient of f(x;3,2) at x= %1.8f",x[0]); pm.setTitle(title); pm.print(pmf, gradient); double[][] hessian = gamma.getPDFHessianApproximation(x[0], a, b); title=String.format("Hessian of f(x;3,2) at x= %1.8f",x[0]); pm.setTitle(title); pm.print(pmf, hessian); } }