package com.imsl.test.example.stat.distributions; import com.imsl.math.PrintMatrix; import com.imsl.math.PrintMatrixFormat; import com.imsl.stat.distributions.RayleighPD; import java.text.DecimalFormat; /** *
* Evaluates the Rayleigh probability distribution.
** This example evaluates the Rayleigh density, gradient, and hessian for a small * sample of data.
* * @see Code * @see Output */ public class RayleighPDEx1 { public static void main(String[] args) { double[] x = {0, 0.5, 1, 4, 9}; RayleighPD rpd = new RayleighPD(); double[] values = new double[x.length]; for (int i = 0; i < x.length; i++) { values[i] = rpd.pdf(x[i], 3.0); } PrintMatrixFormat pmf = new PrintMatrixFormat(); pmf.setNumberFormat(new DecimalFormat("0.00000000")); PrintMatrix pm = new PrintMatrix("Rayleigh(3.0) pdf values at x="); pm.print(pmf, x); pm.setTitle("f(x;3.0)="); pm.print(pmf, values); double[] gradient = rpd.getPDFGradientApproximation(x[2], 3.0); String title = String.format("Approximate gradient of f(x;3.0) at x= %1.8f",x[2]); pm.setTitle(title); pm.print(pmf, gradient); gradient = rpd.getPDFGradient(x[2], 3.0); title = String.format("Analytic gradient of f(x;3.0) at x= %1.8f",x[2]); pm.setTitle(title); pm.print(pmf, gradient); double[][] hessian = rpd.getPDFHessianApproximation(x[2], 3.0); title = String.format("Approximate Hessian of f(x;3.0) at x= %1.8f",x[2]); pm.setTitle(title); pm.print(pmf, hessian); hessian = rpd.getPDFHessian(x[2], 3.0); title = String.format("Analytic Hessian of f(x;3.0) at x= %1.8f",x[2]); pm.setTitle(title); pm.print(pmf, hessian); } }