Skip to content

Commit

Permalink
Fixes for java examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Aug 26, 2011
1 parent af53b6f commit 23456e6
Show file tree
Hide file tree
Showing 20 changed files with 82 additions and 357 deletions.
Expand Up @@ -9,16 +9,11 @@ public class classifier_averaged_perceptron_modular{
static {
System.loadLibrary("modshogun");
}

public ArrayList parameter_list = new ArrayList(2);
public classifier_averaged_perceptron_modular() {
parameter_list.add(Arrays.asList(new Double(10), new Integer(1000)));
parameter_list.add(Arrays.asList(new Double(10), new Integer(10)));
}
public Serializable run(List para) {

public static void main(String argv[]) {
modshogun.init_shogun_with_defaults();
double learn_rate = ((Double)para.get(0)).doubleValue();
int max_iter = ((Integer)para.get(1)).intValue();
double learn_rate = 10;
int max_iter = 10;

DoubleMatrix traindata_real = Load.load_numbers("../data/fm_train_real.dat");
DoubleMatrix testdata_real = Load.load_numbers("../data/fm_test_real.dat");
Expand All @@ -36,15 +31,7 @@ public Serializable run(List para) {

perceptron.set_features(feats_test);
DoubleMatrix out_labels = perceptron.apply().get_labels();
ArrayList result = new ArrayList();
result.add(perceptron);
result.add(out_labels);

modshogun.exit_shogun();
return result;
}
public static void main(String argv[]) {
classifier_averaged_perceptron_modular x = new classifier_averaged_perceptron_modular();
x.run((List)x.parameter_list.get(0));
}
}
Expand Up @@ -9,19 +9,13 @@ public class classifier_svmlight_linear_term_modular {
static {
System.loadLibrary("modshogun");
}

public ArrayList parameter_list = new ArrayList(2);
public classifier_svmlight_linear_term_modular() {

parameter_list.add(Arrays.asList(new Double(0.9), new Double(1e-3), new Integer(1)));
parameter_list.add(Arrays.asList(new Double(2.3), new Double(1e-5), new Integer(4)));
}
static DoubleMatrix run(List para) {

public static void main(String argv[]) {
int degree = 20;
modshogun.init_shogun_with_defaults();
double C = ((Double)para.get(0)).doubleValue();
double epsilon = ((Double)para.get(1)).doubleValue();
int num_threads = ((Integer)para.get(2)).intValue();
double C = 0.9;
double epsilon = 1e-3;
int num_threads = 1;

String[] fm_train_dna = {"CGCACGTACGTAGCTCGAT",
"CGACGTAGTCGTAGTCGTA",
Expand Down Expand Up @@ -59,13 +53,8 @@ static DoubleMatrix run(List para) {
svm.train();

kernel.init(feats_train, feats_test);
DoubleMatrix out = svm.apply().get_labels();
svm.apply().get_labels();

modshogun.exit_shogun();
return out;
}
public static void main(String argv[]) {
classifier_svmlight_linear_term_modular x = new classifier_svmlight_linear_term_modular();
run((List)x.parameter_list.get(0));
}
}
Expand Up @@ -10,18 +10,12 @@ public class classifier_svmlight_modular {
System.loadLibrary("modshogun");
}

public ArrayList parameter_list = new ArrayList(2);
public classifier_svmlight_modular() {

parameter_list.add(Arrays.asList(new Double(1.1), new Double(1e-5), new Integer(1)));
parameter_list.add(Arrays.asList(new Double(1.2), new Double(1e-5), new Integer(1)));
}
static ArrayList run(List para) {
public static void main(String argv[]) {
int degree = 20;
modshogun.init_shogun_with_defaults();
double C = ((Double)para.get(0)).doubleValue();
double epsilon = ((Double)para.get(1)).doubleValue();
int num_threads = ((Integer)para.get(2)).intValue();
double C = 1.1;
double epsilon = 1e-5;
int num_threads = 1;

String[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat");
String[] fm_test_dna = Load.load_dna("../data/fm_test_dna.dat");
Expand All @@ -40,13 +34,6 @@ static ArrayList run(List para) {
kernel.init(feats_train, feats_test);
svm.apply().get_labels();

ArrayList result = new ArrayList();
result.add(kernel);
modshogun.exit_shogun();
return result;
}
public static void main(String argv[]) {
classifier_svmlight_modular x = new classifier_svmlight_modular();
run((List)x.parameter_list.get(0));
}
}
Expand Up @@ -10,14 +10,9 @@ public class clustering_hierarchical_modular {
System.loadLibrary("modshogun");
}

public int[] parameter_list = new int[2];
public clustering_hierarchical_modular() {
parameter_list[0] = 3;
parameter_list[1] = 4;
}
static ArrayList run(int para) {
public static void main(String argv[]) {
modshogun.init_shogun_with_defaults();
int merges = para;
int merges = 3;

DoubleMatrix fm_train = Load.load_numbers("../data/fm_train_real.dat");

Expand All @@ -30,15 +25,6 @@ static ArrayList run(int para) {
DoubleMatrix out_distance = hierarchical.get_merge_distances();
DoubleMatrix out_cluster = hierarchical.get_cluster_pairs();

ArrayList result = new ArrayList();
result.add(hierarchical);
result.add(out_distance);
result.add(out_cluster);
modshogun.exit_shogun();
return result;
}
public static void main(String argv[]) {
clustering_hierarchical_modular x = new clustering_hierarchical_modular();
run(x.parameter_list[0]);
}
}
18 changes: 2 additions & 16 deletions examples/undocumented/java_modular/clustering_kmeans_modular.java
Expand Up @@ -11,14 +11,9 @@ public class clustering_kmeans_modular {
System.loadLibrary("modshogun");
}

public int[] parameter_list = new int[2];
public clustering_kmeans_modular() {
parameter_list[0] = 3;
parameter_list[1] = 4;
}
static ArrayList run(int para) {
public static void main(String argv[]) {
modshogun.init_shogun_with_defaults();
int k = para;
int k = 3;
init_random(17);

DoubleMatrix fm_train = Load.load_numbers("../data/fm_train_real.dat");
Expand All @@ -32,15 +27,6 @@ static ArrayList run(int para) {
DoubleMatrix out_centers = kmeans.get_cluster_centers();
kmeans.get_radiuses();

ArrayList result = new ArrayList();
result.add(kmeans);
result.add(out_centers);

modshogun.exit_shogun();
return result;
}
public static void main(String argv[]) {
clustering_kmeans_modular x = new clustering_kmeans_modular();
run(x.parameter_list[0]);
}
}
29 changes: 7 additions & 22 deletions examples/undocumented/java_modular/distribution_hmm_modular.java
Expand Up @@ -11,20 +11,14 @@ public class distribution_hmm_modular {
System.loadLibrary("modshogun");
}

public ArrayList parameter_list = new ArrayList(2);
public distribution_hmm_modular() {

parameter_list.add(Arrays.asList(new Integer(1), new Integer(64), new Double(1e-5), new Integer(3), new Integer(0)));
parameter_list.add(Arrays.asList(new Integer(1), new Integer(64), new Double(1e-1), new Integer(4), new Integer(0)));
}
static ArrayList run(List para) {
public static void main(String argv[]) {
boolean reverse = false;
modshogun.init_shogun_with_defaults();
int N = ((Integer)para.get(0)).intValue();
int M = ((Integer)para.get(1)).intValue();
double pseudo = ((Double)para.get(2)).doubleValue();
int order = ((Integer)para.get(3)).intValue();
int gap = ((Integer)para.get(4)).intValue();
int N = 1;
int M = 512;
double pseudo = 1e-5;
int order = 3;
int gap = 0;

String[] fm_train_dna = Load.load_cubes("../data/fm_train_cube.dat");

Expand Down Expand Up @@ -53,16 +47,7 @@ static ArrayList run(List para) {

DoubleMatrix lik_example = hmm.get_log_likelihood();
double lik_sample = hmm.get_log_likelihood_sample();

ArrayList result = new ArrayList();
result.add(lik_example);
result.add(lik_sample);
result.add(hmm);

modshogun.exit_shogun();
return result;
}
public static void main(String argv[]) {
distribution_hmm_modular x = new distribution_hmm_modular();
run((List)x.parameter_list.get(0));
}
}
Expand Up @@ -10,17 +10,11 @@ public class distribution_linearhmm_modular {
System.loadLibrary("modshogun");
}

public ArrayList parameter_list = new ArrayList(2);
public distribution_linearhmm_modular() {

parameter_list.add(Arrays.asList(new Integer(3), new Integer(0)));
parameter_list.add(Arrays.asList(new Integer(4), new Integer(0)));
}
static ArrayList run(List para) {
public static void main(String argv[]) {
boolean reverse = false;
modshogun.init_shogun_with_defaults();
int order = ((Integer)para.get(0)).intValue();
int gap = ((Integer)para.get(1)).intValue();
int order = 3;
int gap = 4;

String[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat");

Expand All @@ -43,15 +37,6 @@ static ArrayList run(List para) {
DoubleMatrix out_likelihood = hmm.get_log_likelihood();
double out_sample = hmm.get_log_likelihood_sample();

ArrayList result = new ArrayList();
result.add(hmm);
result.add(out_sample);
result.add(out_likelihood);
modshogun.exit_shogun();
return result;
}
public static void main(String argv[]) {
distribution_linearhmm_modular x = new distribution_linearhmm_modular();
run((List)x.parameter_list.get(0));
}
}
16 changes: 3 additions & 13 deletions examples/undocumented/java_modular/distribution_ppwm_modular.java
Expand Up @@ -10,17 +10,11 @@ public class distribution_ppwm_modular {
System.loadLibrary("modshogun");
}

public ArrayList parameter_list = new ArrayList(2);
public distribution_ppwm_modular() {

parameter_list.add(Arrays.asList(new Integer(3), new Integer(0)));
parameter_list.add(Arrays.asList(new Integer(4), new Integer(0)));
}
static void run(List para) {
public static void main(String argv[]) {
boolean reverse = false;
modshogun.init_shogun_with_defaults();
int order = ((Integer)para.get(0)).intValue();
int gap = ((Integer)para.get(1)).intValue();
int order = 3;
int gap = 4;

String[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat");

Expand All @@ -40,8 +34,4 @@ static void run(List para) {
DoubleMatrix w = ppwm.get_w();
modshogun.exit_shogun();
}
public static void main(String argv[]) {
distribution_ppwm_modular x = new distribution_ppwm_modular();
run((List)x.parameter_list.get(0));
}
}
18 changes: 3 additions & 15 deletions examples/undocumented/java_modular/features_snp_modular.java
Expand Up @@ -10,25 +10,13 @@ public class features_snp_modular {
System.loadLibrary("modshogun");
}

public static String fname = new String();
public features_snp_modular() {
fname = "../data/snps.dat";
}
static ArrayList run(String filename) {
filename = fname;
public static void main(String argv[]) {
modshogun.init_shogun_with_defaults();
String filename = "../data/snps.dat";
StringByteFeatures sf = new StringByteFeatures(SNP);
sf.load_ascii_file(fname, false, SNP, SNP);
sf.load_ascii_file(filename, false, SNP, SNP);
SNPFeatures snps = new SNPFeatures(sf);

ArrayList result = new ArrayList();
result.add(snps);

modshogun.exit_shogun();
return result;
}
public static void main(String argv[]) {
features_snp_modular x = new features_snp_modular();
run(x.fname);
}
}
@@ -1,6 +1,7 @@
import org.shogun.*;
import org.jblas.*;
import static org.shogun.EAlphabet.RAWBYTE;
import static org.shogun.E_COMPRESSION_TYPE.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -10,52 +11,41 @@ public class features_string_char_compressed_modular {
System.loadLibrary("modshogun");
}

public static String filename = new String();
public features_string_char_compressed_modular() {
filename = "features_string_char_compressed_modular.java";
}
static ArrayList run(String fname) {

public static void main(String argv[]) {
modshogun.init_shogun_with_defaults();

StringFileCharFeatures f = new StringFileCharFeatures(fname, RAWBYTE);
//f.save_compressed("foo_uncompressed.str", UNCOMPRESSED, 1);
StringFileCharFeatures f = new StringFileCharFeatures("features_string_char_compressed_modular.java", RAWBYTE);
f.save_compressed("foo_uncompressed.str", UNCOMPRESSED, 1);

StringCharFeatures f2 = new StringCharFeatures(RAWBYTE);
f2.load_compressed("foo_uncompressed.str", true);

//f.save_compressed("foo_lzo.str", LZO, 9);
f2 = new StringCharFeatures(RAWBYTE);
f2.load_compressed("foo_lzo.str", true);
//f2.load_compressed("foo_lzo.str", true);

//f.save_compressed("foo_gzip.str", GZIP, 9);
f2 = new StringCharFeatures(RAWBYTE);
f2.load_compressed("foo_gzip.str", true);
//f2.load_compressed("foo_gzip.str", true);

//f.save_compressed("foo_bzip2.str", BZIP2, 9);
f2 = new StringCharFeatures(RAWBYTE);
f2.load_compressed("foo_bzip2.str", true);
//f2.load_compressed("foo_bzip2.str", true);

//f.save_compressed("foo_lzma.str", LZMA, 9);
f2 = new StringCharFeatures(RAWBYTE);
f2.load_compressed("foo_lzma.str", true);
//f2.load_compressed("foo_lzma.str", true);

f2 = new StringCharFeatures(RAWBYTE);
f2.load_compressed("foo_lzo.str", false);
//f2.load_compressed("foo_lzo.str", false);
//f2.add_preprocessor(new DecompressCharString(LZO));
f2.apply_preprocessor();
//f2.apply_preprocessor();

f2 = new StringCharFeatures(RAWBYTE);
f2.load_compressed("foo_lzo.str", false);
//f2.load_compressed("foo_lzo.str", false);
//f2.add_preprocessor(new DecompressCharString(LZO));
f2.enable_on_the_fly_preprocessing();
ArrayList result = new ArrayList();
//f2.enable_on_the_fly_preprocessing();

modshogun.exit_shogun();
return result;
}
public static void main(String argv[]) {
features_string_char_compressed_modular x = new features_string_char_compressed_modular();
run(x.filename);
}
}

0 comments on commit 23456e6

Please sign in to comment.