Debian Codegraph @

src/dr/oldevomodel/treelikelihood/NativeCovarionLikelihoodCore.java

raw symbols SCIP
1 /*
2 * NativeCovarionLikelihoodCore.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 NativeCovarionLikelihoodCore extends AbstractLikelihoodCore {
30
31 public NativeCovarionLikelihoodCore() {
32 super(8);
33 }
34
35 protected void calculateIntegratePartials(double[] inPartials,
36 double[] proportions, double[] outPartials) {
37 nativeIntegratePartials(inPartials, proportions, patternCount, matrixCount, outPartials);
38 }
39
40 protected void calculatePartialsPartialsPruning(double[] partials1,
41 double[] matrices1, double[] partials2, double[] matrices2,
42 double[] partials3) {
43 nativePartialsPartialsPruning(partials1, matrices1, partials2, matrices2, patternCount, matrixCount, partials3);
44 }
45
46 protected void calculateStatesPartialsPruning(int[] states1,
47 double[] matrices1, double[] partials2, double[] matrices2,
48 double[] partials3) {
49
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 nativeStatesStatesPruning(states1, matrices1, states2, matrices2, patternCount, matrixCount, partials3);
58 }
59
60 protected void calculatePartialsPartialsPruning(double[] partials1,
61 double[] matrices1, double[] partials2, double[] matrices2,
62 double[] partials3, int[] matrixMap) {
63 throw new RuntimeException("not implemented using matrixMap");
64 }
65
66 protected void calculateStatesStatesPruning(int[] states1,
67 double[] matrices1, int[] states2, double[] matrices2,
68 double[] partials3, int[] matrixMap) {
69 throw new RuntimeException("not implemented using matrixMap");
70 }
71
72 protected void calculateStatesPartialsPruning(int[] states1,
73 double[] matrices1, double[] partials2, double[] matrices2,
74 double[] partials3, int[] matrixMap) {
75 throw new RuntimeException("not implemented using matrixMap");
76 }
77
78 public void calculateLogLikelihoods(double[] partials,
79 double[] frequencies, double[] outLogLikelihoods) {
80
81 int v = 0;
82 for (int k = 0; k < patternCount; k++) {
83
84 double sum = frequencies[0] * partials[v];
85 v++;
86 sum += frequencies[1] * partials[v];
87 v++;
88 sum += frequencies[2] * partials[v];
89 v++;
90 sum += frequencies[3] * partials[v];
91 v++;
92
93 sum += frequencies[4] * partials[v];
94 v++;
95 sum += frequencies[5] * partials[v];
96 v++;
97 sum += frequencies[6] * partials[v];
98 v++;
99 sum += frequencies[7] * partials[v];
100 v++;
101
102 outLogLikelihoods[k] = Math.log(sum) + getLogScalingFactor(k);
103 }
104 }
105
106 public native void nativeIntegratePartials(double[] partials, double[] proportions,
107 int patternCount, int matrixCount,
108 double[] outPartials);
109
110 protected native void nativePartialsPartialsPruning(double[] partials1, double[] matrices1,
111 double[] partials2, double[] matrices2,
112 int patternCount, int matrixCount,
113 double[] partials3);
114
115 protected native void nativeStatesPartialsPruning(int[] states1, double[] matrices1,
116 double[] partials2, double[] matrices2,
117 int patternCount, int matrixCount,
118 double[] partials3);
119
120 protected native void nativeStatesStatesPruning(int[] states1, double[] matrices1,
121 int[] states2, double[] matrices2,
122 int patternCount, int matrixCount,
123 double[] partials3);
124
125 public static boolean isAvailable() {
126 return isNativeAvailable;
127 }
128
129 private static boolean isNativeAvailable = false;
130
131 static {
132 try {
133 System.loadLibrary("CovarionLikelihoodCore");
134 isNativeAvailable = true;
135 } catch (UnsatisfiedLinkError e) {
136 System.err.println("Using Java general likelihood core " + e.toString());
137 }
138 }
139
140 }