Debian Codegraph @

src/test/dr/inference/distribution/DirichletProcessTest.java

raw symbols SCIP
1 /*
2 * BinomialLikelihood.java
3 *
4 * Copyright (C) 2002-2009 Alexei Drummond and Andrew Rambaut
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package test.dr.inference.distribution;
27
28 import dr.inference.distribution.DirichletProcessLikelihood;
29 import dr.inference.model.*;
30 import junit.framework.Test;
31 import junit.framework.TestCase;
32 import junit.framework.TestSuite;
33
34 /**
35 * A test suit for the Dirichlet Process likelihood.
36 *
37 * @author Andrew Rambaut
38 * @author Trevor Bedford
39 * @version $Id: BinomialLikelihood.java,v 1.5 2005/05/24 20:25:59 rambaut Exp $
40 */
41
42 public class DirichletProcessTest extends TestCase {
43
44 public DirichletProcessTest(String name) {
45 super(name);
46 }
47
48 public void setUp() throws Exception {
49 super.setUp();
50 }
51
52 public void testDirichletProcess() {
53 // these are expected results calculated manually...
54 testDirichletProcess(new double[] {1, 1, 1}, 1.0, -Math.log(6.0)); // log 1/6
55 testDirichletProcess(new double[] {2, 1}, 1.0, -Math.log(6.0)); // log 1/6
56 testDirichletProcess(new double[] {3}, 1.0, -Math.log(3.0)); // log 1/3
57
58 // check the unoccupied groups are not counted
59 testDirichletProcess(new double[] {2, 1, 0}, 1.0, -Math.log(6.0)); // log 1/6
60 testDirichletProcess(new double[] {3, 0, 0}, 1.0, -Math.log(3.0)); // log 1/3
61
62 // these are results calculated by the method but confirmed against an independent implementation...
63 testDirichletProcess(new double[] {1, 1, 1, 1, 1}, 0.5, -6.851184927493743);
64 testDirichletProcess(new double[] {2, 1, 1, 1, 0}, 0.5, -6.158037746933798);
65 testDirichletProcess(new double[] {3, 1, 1, 0, 0}, 0.5, -4.771743385813907);
66 testDirichletProcess(new double[] {4, 1, 0, 0, 0}, 0.5, -2.9799839165858524);
67 testDirichletProcess(new double[] {5, 0, 0, 0, 0}, 0.5, -0.9005423749060166);
68
69 testDirichletProcess(new double[] {1, 1, 1, 1, 1}, 1.0, -4.787491742782046);
70 testDirichletProcess(new double[] {2, 1, 1, 1, 0}, 1.0, -4.787491742782046);
71 testDirichletProcess(new double[] {3, 1, 1, 0, 0}, 1.0, -4.0943445622221);
72 testDirichletProcess(new double[] {4, 1, 0, 0, 0}, 1.0, -2.995732273553991);
73 testDirichletProcess(new double[] {5, 0, 0, 0, 0}, 1.0, -1.6094379124341005);
74
75 testDirichletProcess(new double[] {1, 1, 1, 1, 1}, 2.0, -3.1135153092103747);
76 testDirichletProcess(new double[] {2, 1, 1, 1, 0}, 2.0, -3.80666248977032);
77 testDirichletProcess(new double[] {3, 1, 1, 0, 0}, 2.0, -3.80666248977032);
78 testDirichletProcess(new double[] {4, 1, 0, 0, 0}, 2.0, -3.401197381662156);
79 testDirichletProcess(new double[] {5, 0, 0, 0, 0}, 2.0, -2.7080502011022105);
80
81 testDirichletProcess(new double[] {1, 1, 1, 1, 1}, 5.0, -1.5765840875630222);
82 testDirichletProcess(new double[] {2, 1, 1, 1, 0}, 5.0, -3.1860219999971227);
83 testDirichletProcess(new double[] {3, 1, 1, 0, 0}, 5.0, -4.102312731871278);
84 testDirichletProcess(new double[] {4, 1, 0, 0, 0}, 5.0, -4.613138355637268);
85 testDirichletProcess(new double[] {5, 0, 0, 0, 0}, 5.0, -4.836281906951478);
86 }
87
88 private void testDirichletProcess(double[] eta, double chi, double expectedLogL) {
89 Parameter etaParameter = new Parameter.Default("eta", eta);
90 Parameter chiParameter = new Parameter.Default("chi", chi, 0.0, Double.MAX_VALUE);
91
92 DirichletProcessLikelihood dirichlet = new DirichletProcessLikelihood(etaParameter, chiParameter);
93
94 assertEquals(expectedLogL, dirichlet.getLogLikelihood(), 1E-10);
95 }
96
97
98 public static Test suite() {
99 return new TestSuite(DirichletProcessTest.class);
100 }
101 }