package com.imsl.test.example.stat.distributions; import com.imsl.math.PrintMatrix; import com.imsl.math.PrintMatrixFormat; import com.imsl.stat.distributions.LogisticPD; import java.text.DecimalFormat; /** *
* Evaluates the logistic probability distribution.
** This example evaluates the logistic density, gradient, and hessian for a * small sample of data.
* * @see Code * @see Output */ public class LogisticPDEx1 { public static void main(String[] args) { double[] x = { 11.707046582345296,2.9154448753588817,7.374648574841656, 5.558291914606187,8.38921517862132,-1.1445036313647128, 13.688322228418551,5.822189639995519,9.315168188063211, 4.028151081671112}; LogisticPD lpd = new LogisticPD(); double[] values = new double[x.length]; for (int i = 0; i < x.length; i++) { values[i] = lpd.pdf(x[i], 5.0, 2.0); } PrintMatrixFormat pmf = new PrintMatrixFormat(); pmf.setNumberFormat(new DecimalFormat("0.00000000")); PrintMatrix pm = new PrintMatrix("logistic(5.0,2.0) pdf values at x="); pm.print(pmf, x); pm.setTitle("f(x;5.0,2.0)="); pm.print(pmf, values); double[] gradient = lpd.getPDFGradientApproximation(x[0], 5.0, 2.0); String title=String.format("Gradient of f(x;5.0,2.0) at x= %1.8f",x[0]); pm.setTitle(title); pm.print(pmf, gradient); double[][] hessian = lpd.getPDFHessianApproximation(x[0], 5.0, 2.0); title=String.format("Hessian of f(x;5.0,2.0) at x= %1.8f",x[0]); pm.setTitle(title); pm.print(pmf, hessian); } }