Debian Codegraph @

src/test/dr/app/beagle/TN93Test.java

raw symbols SCIP
1 /*
2 * TN93Test.java
3 *
4 * Copyright (c) 2002-2012 Alexei Drummond, Andrew Rambaut and Marc Suchard
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.app.beagle;
27
28 import dr.evomodel.substmodel.EigenDecomposition;
29 import dr.evomodel.substmodel.FrequencyModel;
30 import dr.evomodel.substmodel.nucleotide.TN93;
31 import dr.evolution.datatype.Nucleotides;
32 import dr.inference.model.Parameter;
33 import dr.math.matrixAlgebra.Vector;
34 import test.dr.math.MathTestCase;
35
36 /**
37 * @author Marc Suchard
38 */
39 public class TN93Test extends MathTestCase {
40
41 public void testTN93() {
42
43 Parameter kappa1 = new Parameter.Default(5.0);
44 Parameter kappa2 = new Parameter.Default(2.0);
45 double[] pi = new double[]{0.40, 0.20, 0.30, 0.10};
46 double time = 0.1;
47
48 FrequencyModel freqModel = new FrequencyModel(Nucleotides.INSTANCE, pi);
49 TN93 tn = new TN93(kappa1, kappa2, freqModel);
50
51 EigenDecomposition decomp = tn.getEigenDecomposition();
52
53 Vector eval = new Vector(decomp.getEigenValues());
54 System.out.println("Eval = " + eval);
55
56 double[] probs = new double[16];
57 tn.getTransitionProbabilities(time, probs);
58 System.out.println("new probs = " + new Vector(probs));
59
60 // check against old implementation
61 dr.oldevomodel.substmodel.FrequencyModel oldFreq = new dr.oldevomodel.substmodel.FrequencyModel(Nucleotides.INSTANCE, pi);
62 dr.oldevomodel.substmodel.TN93 oldTN = new dr.oldevomodel.substmodel.TN93(kappa1, kappa2, oldFreq);
63
64 double[] oldProbs = new double[16];
65 oldTN.getTransitionProbabilities(time, oldProbs);
66 System.out.println("old probs = " + new Vector(oldProbs));
67 assertEquals(probs, oldProbs, 10E-6);
68 }
69
70 }