package com.imsl.test.example.stat.distributions; import com.imsl.math.PrintMatrix; import com.imsl.math.PrintMatrixFormat; import com.imsl.stat.distributions.ExtremeValuePD; import java.text.DecimalFormat; /** *
* Evaluates the extreme value probability distribution.
** This example evaluates the extreme value density, gradient, and hessian for a * small sample of data.
* * @see Code * @see Output */ public class ExtremeValuePDEx1 { public static void main(String[] args) { double[] x = {-0.9720382, 2.8992983, -0.8798220, 0.1390195, -1.9596219}; double mu = 0; double beta = 2; ExtremeValuePD evpd = new ExtremeValuePD(); double[] values = new double[x.length]; for (int i = 0; i < x.length; i++) { values[i] = evpd.pdf(x[i], mu, beta); } PrintMatrixFormat pmf = new PrintMatrixFormat(); pmf.setNumberFormat(new DecimalFormat("0.00000000")); PrintMatrix pm = new PrintMatrix("ExtremeValuePD(x,0,2) pdf values at x="); pm.print(pmf, x); pm.setTitle("f(x;0,2)="); pm.print(pmf, values); double[] gradient = evpd.getPDFGradientApproximation(x[0], mu, beta); String title=String.format("Gradient of f(x;0,2) at x= %1.8f",x[0]); pm.setTitle(title); pm.print(pmf, gradient); gradient = evpd.getPDFGradient(x[0], mu, beta); title=String.format("Analytic gradient of f(x;0,2) at x= %1.8f",x[0]); pm.setTitle(title); pm.print(pmf, gradient); double[][] hessian = evpd.getPDFHessianApproximation(x[0], mu, beta); title=String.format("Hessian of f(x;0,2) at x= %1.8f",x[0]); pm.setTitle(title); pm.print(pmf, hessian); hessian = evpd.getPDFHessian(x[0], mu, beta); title=String.format("Analytic Hessian of f(x;0,2) at x= %1.8f",x[0]); pm.setTitle(title); pm.print(pmf, hessian); } }