Debian Codegraph @

src/test/dr/evomodel/substmodel/ProductChainFrequencyModelTest.java

raw symbols SCIP
1 package test.dr.evomodel.substmodel;
2
3 import test.dr.math.MathTestCase;
4 import dr.evomodel.substmodel.FrequencyModel;
5 import dr.evomodel.substmodel.ProductChainFrequencyModel;
6 import dr.evolution.datatype.Nucleotides;
7 import dr.math.matrixAlgebra.Vector;
8
9 import java.util.List;
10 import java.util.ArrayList;
11
12 /**
13 * @author Marc A. Suchard
14 */
15 public class ProductChainFrequencyModelTest extends MathTestCase {
16
17 public void testFrequencyModel() {
18
19 FrequencyModel firstPosition = new FrequencyModel(Nucleotides.INSTANCE, freq1);
20 FrequencyModel secondPosition = new FrequencyModel(Nucleotides.INSTANCE, freq2);
21 FrequencyModel thirdPosition = new FrequencyModel(Nucleotides.INSTANCE, freq3);
22
23 List<FrequencyModel> freqModels = new ArrayList<FrequencyModel>(3);
24 freqModels.add(firstPosition);
25 freqModels.add(secondPosition);
26 freqModels.add(thirdPosition);
27
28 ProductChainFrequencyModel pcFreqModel = new ProductChainFrequencyModel("freq", freqModels);
29
30 double[] freqs = pcFreqModel.getFrequencies();
31
32 System.out.println("Freq.length = " + freqs.length);
33
34 int pos1 = 2;
35 int pos2 = 1;
36 int pos3 = 3;
37
38 int index = computeIndex(pos1, pos2, pos3);
39
40 System.out.println("Entry: " + new Vector(pcFreqModel.decomposeEntry(index)));
41 System.out.println("Freq = " + freqs[index]);
42 System.out.println("Freq = " + computeFreq(pos1, pos2, pos3));
43
44 assertEquals(computeFreq(pos1, pos2, pos3), freqs[index]);
45 }
46
47 private int computeIndex(int i, int j, int k) {
48 return i * 16 + j * 4 + k;
49 }
50
51 private double computeFreq(int i, int j, int k) {
52 return freq1[i] * freq2[j] * freq3[k];
53 }
54
55 private static double[] freq1 = {0.3, 0.25, 0.20, 0.25}; // A,C,G,T
56 private static double[] freq2 = {0.1, 0.4, 0.25, 0.25}; // A,C,G,T
57 private static double[] freq3 = {0.3, 0.15, 0.25, 0.30}; // A,C,G,T
58 }