Debian Codegraph @

src/dr/oldevomodel/treelikelihood/NativeGeneralLikelihoodCore.java

raw symbols SCIP
1 /*
2 * NativeGeneralLikelihoodCore.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 NativeGeneralLikelihoodCore extends AbstractLikelihoodCore {
30
31 public NativeGeneralLikelihoodCore(int stateCount) {
32 super(stateCount);
33 }
34
35
36 protected void calculateIntegratePartials(double[] inPartials,
37 double[] proportions, double[] outPartials) {
38 nativeIntegratePartials(inPartials, proportions, patternCount, matrixCount, outPartials, stateCount);
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, stateCount);
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, stateCount);
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, stateCount);
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 int v = 0;
82 for (int k = 0; k < patternCount; k++) {
83
84 double sum = 0.0;
85 for (int i = 0; i < stateCount; i++) {
86
87 sum += frequencies[i] * partials[v];
88 v++;
89 }
90 outLogLikelihoods[k] = Math.log(sum) + getLogScalingFactor(k);
91 }
92 }
93
94 public native void nativeIntegratePartials(double[] partials, double[] proportions,
95 int patternCount, int matrixCount,
96 double[] outPartials,
97 int stateCount);
98
99 protected native void nativePartialsPartialsPruning(double[] partials1, double[] matrices1,
100 double[] partials2, double[] matrices2,
101 int patternCount, int matrixCount,
102 double[] partials3,
103 int stateCount);
104
105 protected native void nativeStatesPartialsPruning(int[] states1, double[] matrices1,
106 double[] partials2, double[] matrices2,
107 int patternCount, int matrixCount,
108 double[] partials3,
109 int stateCount);
110
111 protected native void nativeStatesStatesPruning(int[] states1, double[] matrices1,
112 int[] states2, double[] matrices2,
113 int patternCount, int matrixCount,
114 double[] partials3,
115 int stateCount);
116
117 protected native void setMode(int mode);
118
119 public static boolean isAvailable() {
120 return isNativeAvailable;
121 }
122
123 private static boolean isNativeAvailable = false;
124
125 static {
126 try {
127 System.loadLibrary("GeneralLikelihoodCore");
128 isNativeAvailable = true;
129 } catch (UnsatisfiedLinkError e) {
130 System.err.println("Unable to load general core");
131 }
132 }
133 }