Getting a minimal shogun java_modular interface program running

I used this code just to see whether shogun works or not. I configured shogun with --interfaces=java_modular option and did a make install in /usr/local. It has to have jblas installed in /usr/share/java/jblas.jar

1. First I checked if jblas works fine. I tried this example –

import org.jblas.*;

public class jblas_test {
  public static void main(String[] args) {
    double[][] data = new double[][]
                      {{ 1, 2, 3, 4, 5},
                      { 6, 7, 8, 9, 10},
                      {11, 12, 13, 14, 15}};
    DoubleMatrix matrix = new DoubleMatrix(data);

    DoubleMatrix vector = new DoubleMatrix(new double[]{3, 3, 3, 3,3});
    DoubleMatrix result = matrix.mmul(vector);
    System.out.println(result.rows+"x"+result.columns+": "+result);
    System.out.println("Jblas working fine");
  }
}

2. Then I compiled and ran it with –


[rahul@cfdvs4-2 jblas]$ javac -cp ".:/usr/share/java/jblas.jar" jblas_test.java

[rahul@cfdvs4-2 jblas]$ java -cp ".:/usr/share/java/jblas.jar" jblas_test

3x1: [45.000000; 120.000000; 195.000000]
Jblas working fine

3. Next step was to get a minimal shogun example run. I wrote a simple code –

import org.shogun.*;

public class helloworld {
  static {
    try{
      System.load("/usr/local/lib/jni/libmodshogun.so");
      System.out.println("Loaded modshogun API");
    } catch(UnsatisfiedLinkError e) {
      System.out.println("Couldn't load modshogun");
      System.out.println(e.getMessage());
    }
}

  public static void main(String[] args) {
    modshogun.init_shogun_with_defaults();
    System.out.println("shogun works");
    modshogun.exit_shogun();
  }
}

4. Then I compiled and ran it with –

[rahul@cfdvs4-2 test]$ javac -cp ".:/usr/local/share/java/shogun.jar" helloworld.java
[rahul@cfdvs4-2 test]$ java -cp ".:/usr/local/share/java/shogun.jar" -Djava.library.path=".:/usr/local/lib/jni/libmodshogun.so" helloworld
Loaded modshogun API
shogun works

5. Now was the time to run some actual shogun code. I need shogun for string kernel classification, so I tried out classifier_domainadaptationsvm_modular.java . Just changed System.loadLibrary("modshogun"); to System.load("/usr/local/lib/jni/libmodshogun.so"); at line #9. And also added this line after line 51.

System.out.println(out.rows+"x"+out.columns+": "+out);

Then compiled and ran –

[rahul@cfdvs4-2 test]$ javac -cp ".:/usr/share/java/jblas.jar:/usr/local/share/java/shogun.jar" classifier_domainadaptationsvm_modular.java
[rahul@cfdvs4-2 test]$ java -cp ".:/usr/share/java/jblas.jar:/usr/local/share/java/shogun.jar" -Djava.library.path=".:/usr/local/lib/jni/libmodshogun.so" classifier_domainadaptationsvm_modular
1x10: [-1.000000, 1.000000, -1.000000, -1.000000, -1.000000, -1.000000, 1.000000, 1.000000, 1.000000, -1.000000]

Feels terrific :D

4 thoughts on “Getting a minimal shogun java_modular interface program running

  1. helloworld.java:5: illegal character: \160
     try{
    ^
    helloworld.java:6: illegal character: \160
       System.load(“/usr/local/lib/jni/libshogun.so”);
    ^
    helloworld.java:6: illegal character: \160
       System.load(“/usr/local/lib/jni/libshogun.so”);
    ^
    helloworld.java:6: ‘;’ expected
       System.load(“/usr/local/lib/jni/libshogun.so”);
    ^
    helloworld.java:7: illegal character: \160
         System.out.println(“Loaded shogun API”);
    ^
    helloworld.java:7: illegal character: \160
         System.out.println(“Loaded shogun API”);
    ^
    helloworld.java:7: illegal character: \160
         System.out.println(“Loaded shogun API”);
    ^
    helloworld.java:9: illegal character: \160
         System.out.println(“Couldn’t load shogun”);
    ^
    helloworld.java:9: illegal character: \160
         System.out.println(“Couldn’t load shogun”);
    ^
    helloworld.java:9: illegal character: \160
         System.out.println(“Couldn’t load shogun”);
    ^
    10 errors

  2. I followed your example, I got this error
    /usr/local/lib/jni/libmodshogun.so: libshogun.so.16: cannot open shared object file: No such file or directory

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s