package com.imsl.test.example.stat.distributions; import com.imsl.math.*; import com.imsl.stat.distributions.BetaPD; import java.text.DecimalFormat; /** *
* Evaluates the beta probability distribution.
** This example evaluates the beta density, gradient, and hessian for a small * sample of data.
* * @see Code * @see Output */ public class BetaPDEx1 { public static void main(String[] args) throws Exception { double[] x = { 0.12396e0, 0.58037e0, 0.28837e0, 0.38195e0, 0.44387e0, 0.17680e0, 0.22661e0, 0.55939e0 }; double[] values = new double[x.length]; double a = 1.2; double b = 2.0; BetaPD beta = new BetaPD(); for (int i = 0; i < x.length; i++) { values[i] = beta.pdf(x[i], a, b); } PrintMatrixFormat pmf = new PrintMatrixFormat(); pmf.setNumberFormat(new DecimalFormat("0.00000000")); PrintMatrix pm = new PrintMatrix("Beta(1.2,2.0) pdf values at x="); pm.print(pmf, x); pm.setTitle("f(x;1.2,2.0)="); pm.print(pmf, values); double[] gradient = beta.getPDFGradientApproximation(x[0], a, b); String title=String.format("Gradient f(x;1.2,2.0) at x= %1.8f",x[0]); pm.setTitle(title); pm.print(pmf, gradient); double[][] hessian = beta.getPDFHessianApproximation(x[0], a, b); title=String.format("Hessian of f(x;1.2,2.0) at x= %1.8f",x[0]); pm.setTitle(title); pm.print(pmf, hessian); } }