private static void checkPdf(Exponential dist, double lambda) { assertEquals(0, dist.pdf(-1), 0); double sum = 0; double dx = 0.001 / lambda; for (double x = 0; x < 20/lambda; x+=dx) { sum += x * dist.pdf(x) * dx; assertEquals(Math.exp(-x * lambda) * lambda, dist.pdf(x), 1.0e-9); } assertEquals(1 / lambda, sum, 1.0e-6 / lambda); }
private static void checkEmpiricalDistribution(Exponential dist, int n, double lambda) { double[] x = new double[n]; for (int i = 0; i < n; i++) { x[i] = dist.nextDouble(); } Arrays.sort(x); for (int i = 0; i < n; i++) { double cumulative = (double) i / (n - 1); assertEquals(String.format("lambda = %.3f", lambda), cumulative, dist.cdf(x[i]), 0.02); } }
@Test public void testToString() { assertEquals("org.apache.mahout.math.jet.random.Exponential(3.1000)", new Exponential(3.1, null).toString()); assertEquals("org.apache.mahout.math.jet.random.Exponential(3.1000)", new Exponential(3.1, null).toString()); } }
@Test public void testCdf() { Exponential dist = new Exponential(5.0, RandomUtils.getRandom()); for (int i = 0; i < 1000; i++) { double x = i / 50.0; assertEquals(1 - Math.exp(-x * 5.0), dist.cdf(x), 1.0e-9); } }
private static void checkPdf(Exponential dist, double lambda) { assertEquals(0, dist.pdf(-1), 0); double sum = 0; double dx = 0.001 / lambda; for (double x = 0; x < 20/lambda;x+=dx) { sum += x * dist.pdf(x) * dx; assertEquals(Math.exp(-x * lambda) * lambda, dist.pdf(x), 1.0e-9); } assertEquals(1 / lambda, sum, 1.0e-6 / lambda); }
private static void checkEmpiricalDistribution(Exponential dist, int n, double lambda) { double[] x = new double[n]; for (int i = 0; i < n; i++) { x[i] = dist.nextDouble(); } Arrays.sort(x); for (int i = 0; i < n; i++) { double cumulative = (double) i / (n - 1); assertEquals(String.format("lambda = %.3f", lambda), cumulative, dist.cdf(x[i]), 0.02); } }
@Test public void testToString() { assertEquals("org.apache.mahout.math.jet.random.Exponential(3.1000)", new Exponential(3.1, null).toString()); assertEquals("org.apache.mahout.math.jet.random.Exponential(3.1000)", new Exponential(3.1, null).toString()); } }
@Test public void testCdf() { Exponential dist = new Exponential(5.0, RandomUtils.getRandom()); for (int i = 0; i < 1000; i++) { double x = i / 50.0; assertEquals(1 - Math.exp(-x * 5.0), dist.cdf(x), 1.0e-9); } }