public 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); NormOne preproc = new NormOne(); 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(); System.out.println(km_train.toString()); System.out.println(km_test.toString()); }
public static void main(String argv[]) { modshogun.init_shogun_with_defaults(); double width = 2.1; double epsilon = 1e-5; double C = 1.0; int mkl_norm = 2; DoubleMatrix traindata_real = Load.load_numbers("../data/fm_train_real.dat"); DoubleMatrix testdata_real = Load.load_numbers("../data/fm_test_real.dat"); DoubleMatrix trainlab = Load.load_labels("../data/label_train_multiclass.dat"); CombinedKernel kernel = new CombinedKernel(); CombinedFeatures feats_train = new CombinedFeatures(); CombinedFeatures feats_test = new CombinedFeatures(); RealFeatures subkfeats1_train = new RealFeatures(traindata_real); RealFeatures subkfeats1_test = new RealFeatures(testdata_real); GaussianKernel subkernel = new GaussianKernel(10, width); feats_train.append_feature_obj(subkfeats1_train); feats_test.append_feature_obj(subkfeats1_test); kernel.append_kernel(subkernel); RealFeatures subkfeats2_train = new RealFeatures(traindata_real); RealFeatures subkfeats2_test = new RealFeatures(testdata_real); LinearKernel subkernel2 = new LinearKernel(); feats_train.append_feature_obj(subkfeats2_train); feats_test.append_feature_obj(subkfeats2_test); kernel.append_kernel(subkernel2); RealFeatures subkfeats3_train = new RealFeatures(traindata_real); RealFeatures subkfeats3_test = new RealFeatures(testdata_real); PolyKernel subkernel3 = new PolyKernel(10, 2); feats_train.append_feature_obj(subkfeats3_train); feats_test.append_feature_obj(subkfeats3_test); kernel.append_kernel(subkernel3); kernel.init(feats_train, feats_train); Labels labels = new Labels(trainlab); MKLMultiClass mkl = new MKLMultiClass(C, kernel, labels); mkl.set_epsilon(epsilon); mkl.set_mkl_epsilon(epsilon); mkl.set_mkl_norm(mkl_norm); mkl.train(); kernel.init(feats_train, feats_test); DoubleMatrix out = mkl.apply().get_labels(); modshogun.exit_shogun(); }
public static void main(String argv[]) { modshogun.init_shogun_with_defaults(); 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); EuclideanDistance distance = new EuclideanDistance(feats_train, feats_train); DoubleMatrix dm_train = distance.get_distance_matrix(); distance.init(feats_train, feats_test); DoubleMatrix dm_test = distance.get_distance_matrix(); System.out.println(dm_train.toString()); System.out.println(dm_test.toString()); }
static ArrayList run(int para) { modshogun.init_shogun_with_defaults(); int k = para; init_random(17); DoubleMatrix fm_train = Load.load_numbers("../data/fm_train_real.dat"); RealFeatures feats_train = new RealFeatures(fm_train); EuclidianDistance distance = new EuclidianDistance(feats_train, feats_train); KMeans kmeans = new KMeans(k, distance); kmeans.train(); 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; }