package com.imsl.test.example.stat.distributions; import com.imsl.math.PrintMatrix; import com.imsl.math.PrintMatrixFormat; import com.imsl.stat.distributions.LogNormalPD; import java.text.DecimalFormat; /** *
* Evaluates the log normal probability distribution.
** This example evaluates the log normal density, gradient, and hessian for a * small sample of data.
* * @see Code * @see Output */ public class LogNormalPDEx1 { public static void main(String[] args) { double[] x = {46.657860153788675, 13.11758795134333, 5.745848033140661, 11.938973204787175, 0.7861595073630269, 7.573448549416857, 37.58546296416137, 2.945815957716158, 5.80958651458377, 15.017807093913715}; LogNormalPD lnpd = new LogNormalPD(); double[] values = new double[x.length]; for (int i = 0; i < x.length; i++) { values[i] = lnpd.pdf(x[i], 2.0, 1.0); } PrintMatrixFormat pmf = new PrintMatrixFormat(); pmf.setNumberFormat(new DecimalFormat("0.00000000")); PrintMatrix pm = new PrintMatrix("LogNormal(2.0,1.0) pdf values at x="); pm.print(pmf, x); pm.setTitle("f(x;2.0,1.0)="); pm.print(pmf, values); double[] gradient = lnpd.getPDFGradientApproximation(x[0], 2.0, 1.0); String title=String.format("Gradient of f(x;2.0,1.0) at x= %1.8f",x[0]); pm.setTitle(title); pm.print(pmf, gradient); double[][] hessian = lnpd.getPDFHessianApproximation(x[0], 2.0, 1.0); title=String.format("Hessian of f(x;2.0,1.0) at x= %1.8f",x[0]); pm.setTitle(title); pm.print(pmf, hessian); } }