Debian Codegraph @

src/dr/inference/regression/RegressionJNIWrapper.java

raw symbols SCIP
1 /*
2 * RegressionJNIWrapper.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.inference.regression;
27
28 /**
29 * @author Marc A. Suchard
30 */
31 public class RegressionJNIWrapper {
32
33 public static final String LIBRARY_NAME = "bsccs_jni";
34 public static final String LIBRARY_PATH_LABEL = "bsccs.library.path";
35 public static final String LIBRARY_PLATFORM_NAME = getPlatformSpecificLibraryName();
36
37 public static final int NO_PRIOR = 0;
38 public static final int LAPLACE_PRIOR = 1;
39 public static final int NORMAL_PRIOR = 2;
40
41 /**
42 * private constructor to enforce singleton instance
43 */
44 private RegressionJNIWrapper() {
45 }
46
47 public native int loadData(String fileName);
48
49 public native double getLogLikelihood(int instance);
50
51 public native double getLogPrior(int instance);
52
53 public native double getBeta(int instance, int index);
54
55 public native int getBetaSize(int instance);
56
57 public native double getHessian(int instance, int index1, int index2);
58
59 public native void setBeta(int instance, int index, double value);
60
61 public native void setBeta(int instance, double[] values);
62
63 public native double getHyperprior(int instance);
64
65 public native void setHyperprior(int instance, double value);
66
67 public native void findMode(int instance);
68
69 public native int getUpdateCount(int instance);
70
71 public native int getLikelihoodCount(int instance);
72
73 public native void setPriorType(int instance, int type);
74
75 public native void makeDirty(int instance);
76
77 /* Library loading routines */
78
79 private static String getPlatformSpecificLibraryName() {
80 String osName = System.getProperty("os.name").toLowerCase();
81 String osArch = System.getProperty("os.arch").toLowerCase();
82 if (osName.startsWith("windows")) {
83 if(osArch.equals("i386")) return LIBRARY_NAME + "32";
84 if(osArch.startsWith("amd64")||osArch.startsWith("x86_64")) return LIBRARY_NAME + "64";
85 }
86 return LIBRARY_NAME;
87 }
88
89 public static RegressionJNIWrapper loadLibrary() throws UnsatisfiedLinkError {
90
91 if (INSTANCE == null) {
92 System.err.println("Trying to load BSCCS library...");
93 String path = "";
94 if (System.getProperty(LIBRARY_PATH_LABEL) != null) {
95 path = System.getProperty(LIBRARY_PATH_LABEL);
96 if (path.length() > 0 && !path.endsWith("/")) {
97 path += "/";
98 }
99 }
100
101 System.loadLibrary(path + LIBRARY_PLATFORM_NAME);
102 INSTANCE = new RegressionJNIWrapper();
103 System.err.println("BSCCS library loaded.");
104 }
105
106 return INSTANCE;
107 }
108
109 private static RegressionJNIWrapper INSTANCE = null;
110 }