static void Main(string[] argv) { modshogun.init_shogun_with_defaults(); int num = 1000; double dist = 1.0; double width = 2.1; double C = 1.0; DoubleMatrix offs =ones(2, num).mmul(dist); DoubleMatrix x = randn(2, num).sub(offs); DoubleMatrix y = randn(2, num).add(offs); DoubleMatrix traindata_real = concatHorizontally(x, y); DoubleMatrix o = ones(1,num); DoubleMatrix trainlab = concatHorizontally(o.neg(), o); DoubleMatrix testlab = concatHorizontally(o.neg(), o); RealFeatures feats = new RealFeatures(traindata_real); GaussianKernel kernel = new GaussianKernel(feats, feats, width); Labels labels = new Labels(trainlab); GMNPSVM svm = new GMNPSVM(C, kernel, labels); feats.add_preprocessor(new NormOne()); feats.add_preprocessor(new LogPlusOne()); feats.set_preprocessed(1); svm.train(feats); SerializableAsciiFile fstream = new SerializableAsciiFile("blaah.asc", 'w'); //svm.save_serializable(fstream); modshogun.exit_shogun(); }
static void Main(string[] argv) { modshogun.init_shogun_with_defaults(); double width = 1.4; int size_cache = 10; DoubleMatrix traindata_real = Load.load_numbers("../data/fm_train_real.dat"); DoubleMatrix testdata_real = Load.load_numbers("../data/fm_test_real.dat"); RealFeatures feats_train = new RealFeatures(traindata_real); RealFeatures feats_test = new RealFeatures(testdata_real); RandomFourierGaussPreproc preproc = new RandomFourierGaussPreproc(); preproc.init(feats_train); feats_train.add_preprocessor(preproc); feats_train.apply_preprocessor(); feats_test.add_preprocessor(preproc); feats_test.apply_preprocessor(); Chi2Kernel kernel = new Chi2Kernel(feats_train, feats_train, width, size_cache); DoubleMatrix km_train = kernel.get_kernel_matrix(); kernel.init(feats_train, feats_test); DoubleMatrix km_test = kernel.get_kernel_matrix(); Console.WriteLine(km_train.ToString()); Console.WriteLine(km_test.ToString()); modshogun.exit_shogun(); }
public static void Main() { modshogun.init_shogun_with_defaults(); double width = 1.4; int size_cache = 10; double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat"); double[,] testdata_real = Load.load_numbers("../data/fm_test_real.dat"); RealFeatures feats_train = new RealFeatures(traindata_real); RealFeatures feats_test = new RealFeatures(testdata_real); LogPlusOne preproc = new LogPlusOne(); preproc.init(feats_train); feats_train.add_preprocessor(preproc); feats_train.apply_preprocessor(); feats_test.add_preprocessor(preproc); feats_test.apply_preprocessor(); Chi2Kernel kernel = new Chi2Kernel(feats_train, feats_train, width, size_cache); double[,] km_train = kernel.get_kernel_matrix(); kernel.init(feats_train, feats_test); double[,] km_test = kernel.get_kernel_matrix(); foreach (double item in km_train) Console.Write(item); foreach (double item in km_test) Console.Write(item); modshogun.exit_shogun(); }
public static void Main() { modshogun.init_shogun_with_defaults(); double width = 1.4; int size_cache = 10; double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat"); double[,] testdata_real = Load.load_numbers("../data/fm_test_real.dat"); RealFeatures feats_train = new RealFeatures(traindata_real); RealFeatures feats_test = new RealFeatures(testdata_real); PruneVarSubMean preproc = new PruneVarSubMean(); preproc.init(feats_train); feats_train.add_preprocessor(preproc); feats_train.apply_preprocessor(); feats_test.add_preprocessor(preproc); feats_test.apply_preprocessor(); Chi2Kernel kernel = new Chi2Kernel(feats_train, feats_train, width, size_cache); double[,] km_train = kernel.get_kernel_matrix(); kernel.init(feats_train, feats_test); double[,] km_test = kernel.get_kernel_matrix(); // Parse and Display km_train Console.Write("km_train:\n"); int numRows = km_train.GetLength(0); int numCols = km_train.GetLength(1); for (int i = 0; i < numRows; i++) { for (int j = 0; j < numCols; j++) { Console.Write(km_train[i, j] + " "); } Console.Write("\n"); } // Parse and Display km_test Console.Write("\nkm_test:\n"); numRows = km_test.GetLength(0); numCols = km_test.GetLength(1); for (int i = 0; i < numRows; i++) { for (int j = 0; j < numCols; j++) { Console.Write(km_test[i, j] + " "); } Console.Write("\n"); } modshogun.exit_shogun(); }
public static void Main() { modshogun.init_shogun_with_defaults(); double width = 1.4; int size_cache = 10; double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat"); double[,] testdata_real = Load.load_numbers("../data/fm_test_real.dat"); RealFeatures feats_train = new RealFeatures(traindata_real); RealFeatures feats_test = new RealFeatures(testdata_real); PruneVarSubMean preproc = new PruneVarSubMean(); preproc.init(feats_train); feats_train.add_preprocessor(preproc); feats_train.apply_preprocessor(); feats_test.add_preprocessor(preproc); feats_test.apply_preprocessor(); Chi2Kernel kernel = new Chi2Kernel(feats_train, feats_train, width, size_cache); double[,] km_train = kernel.get_kernel_matrix(); kernel.init(feats_train, feats_test); double[,] km_test = kernel.get_kernel_matrix(); // Parse and Display km_train Console.Write("km_train:\n"); int numRows = km_train.GetLength(0); int numCols = km_train.GetLength(1); for(int i = 0; i < numRows; i++){ for(int j = 0; j < numCols; j++){ Console.Write(km_train[i,j] +" "); } Console.Write("\n"); } // Parse and Display km_test Console.Write("\nkm_test:\n"); numRows = km_test.GetLength(0); numCols = km_test.GetLength(1); for(int i = 0; i < numRows; i++){ for(int j = 0; j < numCols; j++){ Console.Write(km_test[i,j] +" "); } Console.Write("\n"); } modshogun.exit_shogun(); }
public static void Main() { modshogun.init_shogun_with_defaults(); double width = 1.4; int size_cache = 10; double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat"); double[,] testdata_real = Load.load_numbers("../data/fm_test_real.dat"); RealFeatures feats_train = new RealFeatures(traindata_real); RealFeatures feats_test = new RealFeatures(testdata_real); LogPlusOne preproc = new LogPlusOne(); preproc.init(feats_train); feats_train.add_preprocessor(preproc); feats_train.apply_preprocessor(); feats_test.add_preprocessor(preproc); feats_test.apply_preprocessor(); Chi2Kernel kernel = new Chi2Kernel(feats_train, feats_train, width, size_cache); double[,] km_train = kernel.get_kernel_matrix(); kernel.init(feats_train, feats_test); double[,] km_test = kernel.get_kernel_matrix(); foreach (double item in km_train) { Console.Write(item); } foreach (double item in km_test) { Console.Write(item); } modshogun.exit_shogun(); }