Skip to content

Commit

Permalink
fix c# and ruby example to work with new SGVector
Browse files Browse the repository at this point in the history
  • Loading branch information
Soeren Sonnenburg committed May 25, 2012
1 parent 1de9b14 commit f96fdfa
Show file tree
Hide file tree
Showing 23 changed files with 54 additions and 54 deletions.
6 changes: 3 additions & 3 deletions examples/undocumented/csharp_modular/VectorTest.cs
Expand Up @@ -5,10 +5,10 @@ public class VectorTest
public static void Main(string[] args) {
modshogun.init_shogun_with_defaults();

double[] y = new double[4] {1, 2, 3, 4,};
Labels x = new Labels(y);
double[] y = new double[5] {0, 1, 2, 3, 4,};
MulticlassLabels x = new MulticlassLabels(y);
double[] r = x.get_labels();
for (int i = 0; i < 4; i++) {
for (int i = 0; i < 5; i++) {
Console.WriteLine(r[i]);
}

Expand Down
Expand Up @@ -15,14 +15,14 @@ public class classifier_averaged_perceptron_modular{
feats_train.set_feature_matrix(traindata_real);
RealFeatures feats_test = new RealFeatures();
feats_test.set_feature_matrix(testdata_real);
Labels labels = new Labels(trainlab);
BinaryLabels labels = new BinaryLabels(trainlab);
AveragedPerceptron perceptron = new AveragedPerceptron(feats_train, labels);
perceptron.set_learn_rate(learn_rate);
perceptron.set_max_iter(max_iter);
perceptron.train();

perceptron.set_features(feats_test);
double[] out_labels = perceptron.apply().get_labels();
double[] out_labels = BinaryLabels.obtain_from_generic(perceptron.apply()).get_labels();

foreach(double item in out_labels) {
Console.Write(item);
Expand Down
Expand Up @@ -13,11 +13,11 @@ public class classifier_gaussiannaivebayes_modular {
feats_train.set_feature_matrix(traindata_real);
RealFeatures feats_test = new RealFeatures();
feats_test.set_feature_matrix(testdata_real);
Labels labels = new Labels(trainlab);
MulticlassLabels labels = new MulticlassLabels(trainlab);

GaussianNaiveBayes gnb = new GaussianNaiveBayes(feats_train, labels);
gnb.train();
double[] out_labels = gnb.apply(feats_test).get_labels();
double[] out_labels = MulticlassLabels.obtain_from_generic(gnb.apply(feats_test)).get_labels();

foreach(double item in out_labels) {
Console.Write(item);
Expand Down
Expand Up @@ -19,13 +19,13 @@ public class classifier_gmnpsvm_modular {

GaussianKernel kernel = new GaussianKernel(feats_train, feats_train, width);

Labels labels = new Labels(trainlab);
MulticlassLabels labels = new MulticlassLabels(trainlab);

GMNPSVM svm = new GMNPSVM(C, kernel, labels);
svm.set_epsilon(epsilon);
svm.train();
kernel.init(feats_train, feats_test);
double[] out_labels = svm.apply(feats_test).get_labels();
double[] out_labels = MulticlassLabels.obtain_from_generic(svm.apply(feats_test)).get_labels();

foreach(double item in out_labels) {
Console.Write(item);
Expand Down
Expand Up @@ -19,18 +19,18 @@ public class classifier_gpbtsvm_modular {

GaussianKernel kernel = new GaussianKernel(feats_train, feats_train, width);

Labels labels = new Labels(trainlab);
BinaryLabels labels = new BinaryLabels(trainlab);

GPBTSVM svm = new GPBTSVM(C, kernel, labels);
svm.set_epsilon(epsilon);
svm.train();
kernel.init(feats_train, feats_test);
double[] out_labels = svm.apply().get_labels();
double[] out_labels = BinaryLabels.obtain_from_generic(svm.apply()).get_labels();

foreach(double item in out_labels) {
Console.Write(item);
}

modshogun.exit_shogun();
}
}
}
Expand Up @@ -14,11 +14,11 @@ public class classifier_knn_modular {
RealFeatures feats_test = new RealFeatures(testdata_real);
EuclidianDistance distance = new EuclidianDistance(feats_train, feats_train);

Labels labels = new Labels(trainlab);
MulticlassLabels labels = new MulticlassLabels(trainlab);

KNN knn = new KNN(k, distance, labels);
knn.train();
double[] out_labels = knn.apply(feats_test).get_labels();
double[] out_labels = MulticlassLabels.obtain_from_generic(knn.apply(feats_test)).get_labels();

foreach(double item in out_labels) {
Console.Write(item);
Expand Down
Expand Up @@ -19,18 +19,18 @@ public class classifier_larank_modular {

GaussianKernel kernel = new GaussianKernel(feats_train, feats_train, width);

Labels labels = new Labels(trainlab);
MulticlassLabels labels = new MulticlassLabels(trainlab);

LaRank svm = new LaRank(C, kernel, labels);
svm.set_batch_mode(false);
svm.set_epsilon(epsilon);
svm.train();
double[] out_labels = svm.apply(feats_train).get_labels();
double[] out_labels = MulticlassLabels.obtain_from_generic(svm.apply(feats_train)).get_labels();

foreach(double item in out_labels) {
Console.Write(item);
}

modshogun.exit_shogun();
}
}
}
Expand Up @@ -15,7 +15,7 @@ public class classifier_lda_modular {
RealFeatures feats_test = new RealFeatures();
feats_test.set_feature_matrix(testdata_real);

Labels labels = new Labels(trainlab);
BinaryLabels labels = new BinaryLabels(trainlab);

LDA lda = new LDA(gamma, feats_train, labels);
lda.train();
Expand All @@ -29,12 +29,12 @@ public class classifier_lda_modular {


lda.set_features(feats_test);
double[] out_labels = lda.apply().get_labels();
double[] out_labels = BinaryLabels.obtain_from_generic(lda.apply()).get_labels();

foreach(double item in out_labels) {
Console.Write(item);
}

modshogun.exit_shogun();
}
}
}
Expand Up @@ -17,15 +17,15 @@ public class classifier_liblinear_modular {
RealFeatures feats_test = new RealFeatures();
feats_test.set_feature_matrix(testdata_real);

Labels labels = new Labels(trainlab);
BinaryLabels labels = new BinaryLabels(trainlab);

LibLinear svm = new LibLinear(C, feats_train, labels);
svm.set_liblinear_solver_type(LIBLINEAR_SOLVER_TYPE.L2R_L2LOSS_SVC_DUAL);
svm.set_epsilon(epsilon);
svm.set_bias_enabled(true);
svm.train();
svm.set_features(feats_test);
double[] out_labels = svm.apply().get_labels();
double[] out_labels = BinaryLabels.obtain_from_generic(svm.apply()).get_labels();

foreach(double item in out_labels) {
Console.Write(item);
Expand Down
Expand Up @@ -19,19 +19,19 @@ public class classifier_libsvm_modular {

GaussianKernel kernel = new GaussianKernel(feats_train, feats_train, width);

Labels labels = new Labels(trainlab);
BinaryLabels labels = new BinaryLabels(trainlab);

LibSVM svm = new LibSVM(C, kernel, labels);
svm.set_epsilon(epsilon);
svm.train();

kernel.init(feats_train, feats_test);
double[] out_labels = svm.apply().get_labels();
double[] out_labels = BinaryLabels.obtain_from_generic(svm.apply()).get_labels();

foreach(double item in out_labels) {
Console.Write(item);
}

modshogun.exit_shogun();
}
}
}
Expand Up @@ -22,7 +22,7 @@ public class classifier_libsvmoneclass_modular {
svm.train();

kernel.init(feats_train, feats_test);
double[] out_labels = svm.apply().get_labels();
double[] out_labels = BinaryLabels.obtain_from_generic(svm.apply()).get_labels();

foreach (double item in out_labels)
Console.Write(item);
Expand Down
Expand Up @@ -20,19 +20,19 @@ public class classifier_mpdsvm_modular {

GaussianKernel kernel = new GaussianKernel(feats_train, feats_train, width);

Labels labels = new Labels(trainlab);
BinaryLabels labels = new BinaryLabels(trainlab);

MPDSVM svm = new MPDSVM(C, kernel, labels);
svm.set_epsilon(epsilon);
svm.train();

kernel.init(feats_train, feats_test);
// already tried double[,]
double[] out_labels = svm.apply().get_labels();
double[] out_labels = BinaryLabels.obtain_from_generic(svm.apply()).get_labels();

foreach (double item in out_labels)
Console.Write(item);

modshogun.exit_shogun();
}
}
}
Expand Up @@ -19,14 +19,14 @@ public class classifier_multiclasslibsvm_modular {

GaussianKernel kernel = new GaussianKernel(feats_train, feats_train, width);

Labels labels = new Labels(trainlab);
MulticlassLabels labels = new MulticlassLabels(trainlab);

MulticlassLibSVM svm = new MulticlassLibSVM(C, kernel, labels);
svm.set_epsilon(epsilon);
svm.train();

kernel.init(feats_train, feats_test);
double[] out_labels = svm.apply().get_labels();
double[] out_labels = MulticlassLabels.obtain_from_generic(svm.apply()).get_labels();

foreach (double item in out_labels)
Console.Write(item);
Expand Down
Expand Up @@ -17,7 +17,7 @@ public class classifier_perceptron_modular {
RealFeatures feats_test = new RealFeatures();
feats_test.set_feature_matrix(testdata_real);

Labels labels = new Labels(trainlab);
BinaryLabels labels = new BinaryLabels(trainlab);

Perceptron perceptron = new Perceptron(feats_train, labels);
perceptron.set_learn_rate(learn_rate);
Expand All @@ -26,7 +26,7 @@ public class classifier_perceptron_modular {

perceptron.set_features(feats_test);
// already tried double[][]
double[] out_labels = perceptron.apply().get_labels();
double[] out_labels = BinaryLabels.obtain_from_generic(perceptron.apply()).get_labels();

foreach (double item in out_labels)
Console.Write(item);
Expand Down
Expand Up @@ -11,8 +11,8 @@ public class evaluation_contingencytableevaluation_modular {
predicted[i] = RandomNumber.NextDouble();
}

Labels ground_truth_labels = new Labels(ground_truth);
Labels predicted_labels = new Labels(predicted);
BinaryLabels ground_truth_labels = new BinaryLabels(ground_truth);
BinaryLabels predicted_labels = new BinaryLabels(predicted);

ContingencyTableEvaluation base_evaluator = new ContingencyTableEvaluation();
base_evaluator.evaluate(predicted_labels,ground_truth_labels);
Expand Down
2 changes: 1 addition & 1 deletion examples/undocumented/csharp_modular/kernel_auc_modular.cs
Expand Up @@ -11,7 +11,7 @@ public class kernel_auc_modular {
RealFeatures feats_train = new RealFeatures(train_real);
GaussianKernel subkernel = new GaussianKernel(feats_train, feats_train, width);

Labels labels = new Labels(trainlab);
BinaryLabels labels = new BinaryLabels(trainlab);

AUCKernel kernel = new AUCKernel(0, subkernel);
kernel.setup_auc_maximization(labels);
Expand Down
Expand Up @@ -19,7 +19,7 @@ public class kernel_salzberg_word_string_modular {
StringWordFeatures feats_test = new StringWordFeatures(charfeat.get_alphabet());
feats_test.obtain_from_char(charfeat, order-1, order, gap, false);

Labels labels = new Labels(Load.load_labels("../data/label_train_dna.dat"));
BinaryLabels labels = new BinaryLabels(Load.load_labels("../data/label_train_dna.dat"));

PluginEstimate pie = new PluginEstimate();
pie.set_labels(labels);
Expand All @@ -30,7 +30,7 @@ public class kernel_salzberg_word_string_modular {
double[,] km_train = kernel.get_kernel_matrix();
kernel.init(feats_train, feats_test);
pie.set_features(feats_test);
pie.apply().get_labels();
BinaryLabels.obtain_from_generic(pie.apply()).get_labels();
double[,] km_test=kernel.get_kernel_matrix();

modshogun.exit_shogun();
Expand Down
Expand Up @@ -30,7 +30,7 @@ public class mkl_binclass_modular {
kernel.append_kernel(new PolyKernel(10,2));
kernel.init(feats_train, feats_train);

Labels labels = new Labels(trainlab);
BinaryLabels labels = new BinaryLabels(trainlab);

MKLClassification mkl = new MKLClassification();
mkl.set_mkl_norm(1);
Expand Down
Expand Up @@ -44,7 +44,7 @@ public class mkl_multiclass_modular {

kernel.init(feats_train, feats_train);

Labels labels = new Labels(trainlab);
MulticlassLabels labels = new MulticlassLabels(trainlab);

MKLMulticlass mkl = new MKLMulticlass(C, kernel, labels);
mkl.set_epsilon(epsilon);
Expand All @@ -54,7 +54,7 @@ public class mkl_multiclass_modular {
mkl.train();

kernel.init(feats_train, feats_test);
double[] outMatrix = mkl.apply().get_labels();
double[] outMatrix = MulticlassLabels.obtain_from_generic(mkl.apply()).get_labels();

modshogun.exit_shogun();
}
Expand Down
Expand Up @@ -15,13 +15,13 @@ public class regression_krr_modular {
RealFeatures feats_test = new RealFeatures(testdata_real);
GaussianKernel kernel= new GaussianKernel(feats_train, feats_train, width);

Labels labels = new Labels(trainlab);
RegressionLabels labels = new RegressionLabels(trainlab);

KernelRidgeRegression krr = new KernelRidgeRegression(tau, kernel, labels);
krr.train(feats_train);

kernel.init(feats_train, feats_test);
double[] out_labels = krr.apply().get_labels();
double[] out_labels = RegressionLabels.obtain_from_generic(krr.apply()).get_labels();

foreach(double item in out_labels) {
Console.Write(item);
Expand Down
Expand Up @@ -18,19 +18,19 @@ public class regression_libsvr_modular {
RealFeatures feats_test = new RealFeatures(testdata_real);
GaussianKernel kernel= new GaussianKernel(feats_train, feats_train, width);

Labels labels = new Labels(trainlab);
RegressionLabels labels = new RegressionLabels(trainlab);

LibSVR svr = new LibSVR(C, epsilon, kernel, labels);
svr.set_tube_epsilon(tube_epsilon);
svr.train();

kernel.init(feats_train, feats_test);
double[] out_labels = svr.apply().get_labels();
double[] out_labels = RegressionLabels.obtain_from_generic(svr.apply()).get_labels();

foreach (double item in out_labels)
Console.Write(out_labels);

modshogun.exit_shogun();

}
}
}
Expand Up @@ -18,19 +18,19 @@ public class regression_svrlight_modular {
RealFeatures feats_test = new RealFeatures(testdata_real);
GaussianKernel kernel= new GaussianKernel(feats_train, feats_train, width);

Labels labels = new Labels(trainlab);
RegressionLabels labels = new RegressionLabels(trainlab);

SVRLight svr = new SVRLight(C, epsilon, kernel, labels);
svr.set_tube_epsilon(tube_epsilon);
//svr.parallel.set_num_threads(num_threads);
svr.train();

kernel.init(feats_train, feats_test);
double[] out_labels = svr.apply().get_labels();
double[] out_labels = RegressionLabels.obtain_from_generic(svr.apply()).get_labels();

foreach (double item in out_labels)
Console.Write(item);

modshogun.exit_shogun();
}
}
}

0 comments on commit f96fdfa

Please sign in to comment.