Debian Codegraph @

src/dr/oldevomodel/treelikelihood/NativeAminoAcidLikelihoodCore.java

raw symbols SCIP
1 /*
2 * NativeAminoAcidLikelihoodCore.java
3 *
4 * Copyright (c) 2002-2015 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 dr.oldevomodel.treelikelihood;
27
28 @Deprecated // Switching to BEAGLE
29 public class NativeAminoAcidLikelihoodCore extends AbstractLikelihoodCore{
30
31 public NativeAminoAcidLikelihoodCore() {
32 super(20);
33 }
34
35
36 protected void calculateIntegratePartials(double[] inPartials,
37 double[] proportions, double[] outPartials) {
38 nativeIntegratePartials(inPartials, proportions, patternCount, matrixCount, outPartials);
39 }
40
41 protected void calculatePartialsPartialsPruning(double[] partials1,
42 double[] matrices1, double[] partials2, double[] matrices2,
43 double[] partials3) {
44 nativePartialsPartialsPruning(partials1, matrices1, partials2, matrices2, patternCount, matrixCount, partials3);
45 }
46
47 protected void calculateStatesPartialsPruning(int[] states1,
48 double[] matrices1, double[] partials2, double[] matrices2,
49 double[] partials3) {
50 nativeStatesPartialsPruning(states1, matrices1, partials2, matrices2, patternCount, matrixCount, partials3);
51 }
52
53 protected void calculateStatesStatesPruning(int[] states1,
54 double[] matrices1, int[] states2, double[] matrices2,
55 double[] partials3) {
56
57
58 nativeStatesStatesPruning(states1, matrices1, states2, matrices2, patternCount, matrixCount, partials3);
59 }
60
61 protected void calculatePartialsPartialsPruning(double[] partials1,
62 double[] matrices1, double[] partials2, double[] matrices2,
63 double[] partials3, int[] matrixMap) {
64 throw new RuntimeException("not implemented using matrixMap");
65 }
66
67 protected void calculateStatesStatesPruning(int[] states1,
68 double[] matrices1, int[] states2, double[] matrices2,
69 double[] partials3, int[] matrixMap) {
70 throw new RuntimeException("not implemented using matrixMap");
71 }
72
73 protected void calculateStatesPartialsPruning(int[] states1,
74 double[] matrices1, double[] partials2, double[] matrices2,
75 double[] partials3, int[] matrixMap) {
76 throw new RuntimeException("not implemented using matrixMap");
77 }
78
79 public void calculateLogLikelihoods(double[] partials,
80 double[] frequencies, double[] outLogLikelihoods) {
81
82 int v = 0;
83 for (int k = 0; k < patternCount; k++) {
84
85 double sum = frequencies[0] * partials[v]; v++;
86 sum += frequencies[1] * partials[v]; v++;
87 sum += frequencies[2] * partials[v]; v++;
88 sum += frequencies[3] * partials[v]; v++;
89
90 sum += frequencies[4] * partials[v]; v++;
91 sum += frequencies[5] * partials[v]; v++;
92 sum += frequencies[6] * partials[v]; v++;
93 sum += frequencies[7] * partials[v]; v++;
94
95 sum += frequencies[8] * partials[v]; v++;
96 sum += frequencies[9] * partials[v]; v++;
97 sum += frequencies[10] * partials[v]; v++;
98 sum += frequencies[11] * partials[v]; v++;
99
100 sum += frequencies[12] * partials[v]; v++;
101 sum += frequencies[13] * partials[v]; v++;
102 sum += frequencies[14] * partials[v]; v++;
103 sum += frequencies[15] * partials[v]; v++;
104
105 sum += frequencies[16] * partials[v]; v++;
106 sum += frequencies[17] * partials[v]; v++;
107 sum += frequencies[18] * partials[v]; v++;
108 sum += frequencies[19] * partials[v]; v++;
109 outLogLikelihoods[k] = Math.log(sum) + getLogScalingFactor(k);
110 }
111 }
112
113 public native void nativeIntegratePartials(double[] partials, double[] proportions,
114 int patternCount, int matrixCount,
115 double[] outPartials);
116
117 protected native void nativePartialsPartialsPruning(double[] partials1, double[] matrices1,
118 double[] partials2, double[] matrices2,
119 int patternCount, int matrixCount,
120 double[] partials3);
121
122 protected native void nativeStatesPartialsPruning(int[] states1, double[] matrices1,
123 double[] partials2, double[] matrices2,
124 int patternCount, int matrixCount,
125 double[] partials3);
126
127 protected native void nativeStatesStatesPruning(int[] states1, double[] matrices1,
128 int[] states2, double[] matrices2,
129 int patternCount, int matrixCount,
130 double[] partials3);
131
132 public static boolean isAvailable(){
133 return isNativeAvailable;
134 }
135
136 private static boolean isNativeAvailable = false;
137
138 static {
139 try {
140 System.loadLibrary("AminoAcidLikelihoodCore");
141 isNativeAvailable = true;
142 } catch (UnsatisfiedLinkError e) {
143 System.err.println("Using Java AminoAcid likelihood core " + e.toString());
144 System.err.println("Looking for AminoAcidLikelihoodCore in " + System.getProperty("java.library.path"));
145 }
146 }
147 }