Beispiel #1
0
 @Override
 public NamespaceDef getNamespaceDef() {
   try {
     NamespaceDef def = new NamespaceDef();
     def.parse(Resources.newReaderSupplier(getNamespaceURL(), Charsets.UTF_8));
     return def;
   } catch (IOException e) {
     throw new RuntimeException("IOException while parsing NAMESPACE file");
   }
 }
 @Test
 public void testDistributionFunctions() throws IOException {
   InputSupplier<InputStreamReader> input =
       Resources.newReaderSupplier(
           Resources.getResource("negative-binomial-test-data.csv"), Charsets.UTF_8);
   boolean header = true;
   for (String line : CharStreams.readLines(input)) {
     if (header) {
       // skip
       header = false;
     } else {
       Iterable<String> values = onComma.split(line);
       int k = Integer.parseInt(Iterables.get(values, 0));
       double p = Double.parseDouble(Iterables.get(values, 1));
       int r = Integer.parseInt(Iterables.get(values, 2));
       double density = Double.parseDouble(Iterables.get(values, 3));
       double cume = Double.parseDouble(Iterables.get(values, 4));
       NegativeBinomial nb = new NegativeBinomial(r, p, new MersenneTwister());
       Assert.assertEquals("cumulative " + k + ',' + p + ',' + r, cume, nb.cdf(k), cume * 1e-05);
       Assert.assertEquals(
           "density " + k + ',' + p + ',' + r, density, nb.pdf(k), density * 1e-05);
     }
   }
 }