/** * Test of getMaxSupport method, of class * gov.sandia.cognition.learning.util.statistics.UniformDistribution. */ public void testGetMaxX() { System.out.println("getMaxX"); double a = RANDOM.nextGaussian(); double b = a + 1; UniformDistribution instance = new UniformDistribution(a, b); assertEquals(b, instance.getMaxSupport()); }
/** Tests what happens when the min == max */ public void testDegenerate() { System.out.println("CDF.degenerate"); for (int i = 0; i < 100; i++) { double x = RANDOM.nextGaussian(); UniformDistribution.CDF instance = new UniformDistribution.CDF(x, x); assertEquals(x, instance.getMinSupport()); assertEquals(x, instance.getMaxSupport()); assertEquals(x, instance.getMean()); assertEquals(0.0, instance.getVariance()); assertEquals(x, instance.sample(RANDOM)); } }
@Override public void testCDFConstructors() { System.out.println("CDF Constructor"); UniformDistribution.CDF u = new UniformDistribution.CDF(); assertEquals(UniformDistribution.DEFAULT_MIN, u.getMinSupport()); assertEquals(UniformDistribution.DEFAULT_MAX, u.getMaxSupport()); double a = RANDOM.nextGaussian(); double b = RANDOM.nextDouble() + a; u = new UniformDistribution.CDF(a, b); assertEquals(a, u.getMinSupport()); assertEquals(b, u.getMaxSupport()); UniformDistribution.CDF u2 = new UniformDistribution.CDF(u); assertEquals(u.getMinSupport(), u2.getMinSupport()); assertEquals(u.getMaxSupport(), u2.getMaxSupport()); }
@Override public void testCDFKnownValues() { System.out.println("CDF.knownValues"); for (int i = 0; i < 1000; i++) { UniformDistribution.CDF instance = this.createInstance().getCDF(); double x = RANDOM.nextGaussian(); double phat = instance.evaluate(x); double p; if (x < instance.getMinSupport()) { p = 0.0; } else if (x > instance.getMaxSupport()) { p = 1.0; } else { p = (x - instance.getMinSupport()) / (instance.getMaxSupport() - instance.getMinSupport()); } assertEquals(p, phat, TOLERANCE); } }
@Override public UniformDistribution createInstance() { double a = RANDOM.nextGaussian(); double b = a + RANDOM.nextDouble() * 2.0; return new UniformDistribution(a, b); }