| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.inference.regression; |
| 27 |
|
| 28 |
|
| 29 |
|
| 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 |
|
| 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 |
|
| 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 |
} |