@Test public void testPDF() throws Exception { System.out.println("Testing 10000 random pdf calls"); LogNormalDistributionModel logNormal = new LogNormalDistributionModel(); logNormal.init("1.0", "2.0"); for (int i = 0; i < 10000; i++) { double M = Math.random() * 10.0 - 5.0; double S = Math.random() * 10; double x = -1; while (x < 0) { x = Math.log(Math.random() * 10); } logNormal.MParameterInput.setValue(M + "", logNormal); logNormal.SParameterInput.setValue(S + "", logNormal); logNormal.initAndValidate(); double pdf = 1.0 / (x * S * Math.sqrt(2 * Math.PI)) * Math.exp(-Math.pow(Math.log(x) - M, 2) / (2 * S * S)); System.out.println("Testing logNormal[M=" + M + " S=" + S + "].pdf(" + x + ")"); double f = logNormal.density(x); assertEquals(pdf, f, 1e-10); } }
@Test public void testCalcLogP3() throws Exception { // does the same as testCalcLogP(), but with by constructing object through init LogNormalDistributionModel logNormal = new LogNormalDistributionModel(); logNormal.init("2000", "0.6", true, "1200"); RealParameter p = new RealParameter(new Double[] {2952.6747000000014}); double f0 = logNormal.calcLogP(p); assertEquals(-7.880210654973873, f0, 1e-10); }