コード例 #1
0
  /**
   * 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());
  }
コード例 #2
0
  /** 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));
    }
  }
コード例 #3
0
  @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());
  }
コード例 #4
0
  @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);
    }
  }
コード例 #5
0
 @Override
 public UniformDistribution createInstance() {
   double a = RANDOM.nextGaussian();
   double b = a + RANDOM.nextDouble() * 2.0;
   return new UniformDistribution(a, b);
 }