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

* Evaluates the Weibull probability distribution.

*

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

* * @see Code * @see Output */ public class WeibullPDEx1 { public static void main(String[] args) { double[] x = {0, .5, 1, 4, 9}; WeibullPD wpd = new WeibullPD(); double[] values = new double[x.length]; for (int i = 0; i < x.length; i++) { values[i] = wpd.pdf(x[i], 3.0, 2.0); } PrintMatrixFormat pmf = new PrintMatrixFormat(); pmf.setNumberFormat(new DecimalFormat("0.000000000")); PrintMatrix pm = new PrintMatrix("Weibull(3.0,2.0) pdf values at x="); pm.print(pmf, x); pm.setTitle("f(x;3.0,2.0)="); pm.print(pmf, values); double[] gradient = wpd.getPDFGradientApproximation(x[2], 3.0, 2.0); String title = String.format("Approximate gradient of f(x;3.0,2.0) at x= %1.8f",x[2]); pm.setTitle(title); pm.print(pmf, gradient); gradient = wpd.getPDFGradient(x[2], 3.0, 2.0); title = String.format("Analytic gradient of f(x;3.0,2.0) at x= %1.8f",x[2]); pm.setTitle(title); pm.print(pmf, gradient); double[][] hessian = wpd.getPDFHessianApproximation(x[2], 3.0, 2.0); title = String.format("Approximate Hessian of f(x;3.0,2.0) at x= %1.8f",x[2]); pm.setTitle(title); pm.print(pmf, hessian); hessian = wpd.getPDFHessian(x[2], 3.0, 2.0); title = String.format("Analytic Hessian of f(x;3.0,2.0) at x= %1.8f",x[2]); pm.setTitle(title); pm.print(pmf, hessian); } }