コード例 #1
0
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        double width    = 2.1;
        double epsilon  = 1e-5;
        double C        = 1.0;
        int    mkl_norm = 2;

        double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat");
        double[,] testdata_real  = Load.load_numbers("../data/fm_test_real.dat");

        double[] 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);

        MulticlassLabels labels = new MulticlassLabels(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);
        double[] outMatrix = LabelsFactory.to_multiclass(mkl.apply()).get_labels();
    }
コード例 #2
0
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        double width    = 2.1;
        double epsilon  = 1e-5;
        double C        = 1.0;
        int    mkl_norm = 2;

        double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat");
        double[,] testdata_real  = Load.load_numbers("../data/fm_test_real.dat");

        double[] trainlab = Load.load_labels("../data/label_train_twoclass.dat");

        RealFeatures tfeats  = new RealFeatures(traindata_real);
        PolyKernel   tkernel = new PolyKernel(10, 3);

        tkernel.init(tfeats, tfeats);
        double[,] K_train = tkernel.get_kernel_matrix();

        RealFeatures pfeats = new RealFeatures(testdata_real);

        tkernel.init(tfeats, pfeats);
        double[,] K_test = tkernel.get_kernel_matrix();

        CombinedFeatures feats_train = new CombinedFeatures();

        feats_train.append_feature_obj(new RealFeatures(traindata_real));

        CombinedKernel kernel = new CombinedKernel();

        kernel.append_kernel(new CustomKernel(K_train));
        kernel.append_kernel(new PolyKernel(10, 2));
        kernel.init(feats_train, feats_train);

        BinaryLabels labels = new BinaryLabels(trainlab);

        MKLClassification mkl = new MKLClassification();

        mkl.set_mkl_norm(1);
        mkl.set_kernel(kernel);
        mkl.set_labels(labels);

        mkl.train();

        CombinedFeatures feats_pred = new CombinedFeatures();

        feats_pred.append_feature_obj(new RealFeatures(testdata_real));

        CombinedKernel kernel2 = new CombinedKernel();

        kernel2.append_kernel(new CustomKernel(K_test));
        kernel2.append_kernel(new PolyKernel(10, 2));
        kernel2.init(feats_train, feats_pred);

        mkl.set_kernel(kernel2);
        mkl.apply();

        modshogun.exit_shogun();
    }
コード例 #3
0
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        double width = 2.1;
        double epsilon = 1e-5;
        double C = 1.0;
        int mkl_norm = 2;

        double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat");
        double[,] testdata_real = Load.load_numbers("../data/fm_test_real.dat");

        double[] 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);

        MulticlassLabels labels = new MulticlassLabels(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);
        double[] outMatrix =  MulticlassLabels.obtain_from_generic(mkl.apply()).get_labels();

        modshogun.exit_shogun();
    }
コード例 #4
0
    static void Main(string[] argv)
    {
        modshogun.init_shogun_with_defaults();
        double width = 2.1;
        double epsilon = 1e-5;
        double C = 1.0;

        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_twoclass.dat");

        CombinedKernel kernel = new CombinedKernel();
        CombinedFeatures feats_train = new CombinedFeatures();

        RealFeatures tfeats = new RealFeatures(traindata_real);
        PolyKernel tkernel = new PolyKernel(10,3);
        tkernel.init(tfeats, tfeats);
        DoubleMatrix K = tkernel.get_kernel_matrix();
        kernel.append_kernel(new CustomKernel(K));

        RealFeatures subkfeats_train = new RealFeatures(traindata_real);
        feats_train.append_feature_obj(subkfeats_train);
        PolyKernel subkernel = new PolyKernel(10,2);
        kernel.append_kernel(subkernel);

        kernel.init(feats_train, feats_train);

        Labels labels = new Labels(trainlab);

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

        CombinedKernel kernel_pred = new CombinedKernel();
        CombinedFeatures feats_pred = new CombinedFeatures();

        RealFeatures pfeats = new RealFeatures(testdata_real);
        PolyKernel tkernel_pred = new PolyKernel(10,3);
        tkernel_pred.init(tfeats, pfeats);
        DoubleMatrix KK = tkernel.get_kernel_matrix();
        kernel_pred.append_kernel(new CustomKernel(KK));

        RealFeatures subkfeats_test = new RealFeatures(testdata_real);
        feats_pred.append_feature_obj(subkfeats_train);
        PolyKernel subkernel_pred = new PolyKernel(10,2);
        kernel_pred.append_kernel(subkernel_pred);

        kernel_pred.init(feats_train, feats_pred);

        svm.set_kernel(kernel_pred);
        svm.apply();
        DoubleMatrix km_train =kernel.get_kernel_matrix();
        Console.WriteLine(km_train.ToString());

        modshogun.exit_shogun();
    }
コード例 #5
0
ファイル: mkl_binclass_modular.cs プロジェクト: orico/shogun
    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_twoclass.dat");

        RealFeatures tfeats = new RealFeatures(traindata_real);
        PolyKernel tkernel = new PolyKernel(10,3);
        tkernel.init(tfeats, tfeats);
        DoubleMatrix K_train = tkernel.get_kernel_matrix();

        RealFeatures pfeats = new RealFeatures(testdata_real);
        tkernel.init(tfeats, pfeats);
        DoubleMatrix K_test = tkernel.get_kernel_matrix();

        CombinedFeatures feats_train = new CombinedFeatures();
        feats_train.append_feature_obj(new RealFeatures(traindata_real));

        CombinedKernel kernel = new CombinedKernel();
           kernel.append_kernel(new CustomKernel(K_train));
        kernel.append_kernel(new PolyKernel(10,2));
        kernel.init(feats_train, feats_train);

        Labels labels = new Labels(trainlab);

        MKLClassification mkl = new MKLClassification();
        mkl.set_mkl_norm(1);
        mkl.set_kernel(kernel);
        mkl.set_labels(labels);

        mkl.train();

        CombinedFeatures feats_pred = new CombinedFeatures();
        feats_pred.append_feature_obj(new RealFeatures(testdata_real));

        CombinedKernel kernel2 = new CombinedKernel();
        kernel2.append_kernel(new CustomKernel(K_test));
        kernel2.append_kernel(new PolyKernel(10, 2));
        kernel2.init(feats_train, feats_pred);

        mkl.set_kernel(kernel2);
        mkl.apply();

        modshogun.exit_shogun();
    }
コード例 #6
0
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        int cardinality = 2;
        int cache       = 10;

        double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat");
        double[,] testdata_real  = Load.load_numbers("../data/fm_test_real.dat");
        String[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat");
        String[] fm_test_dna  = Load.load_dna("../data/fm_test_dna.dat");

        RealFeatures subfeats_train = new RealFeatures(traindata_real);
        RealFeatures subfeats_test  = new RealFeatures(testdata_real);

        CombinedKernel   kernel      = new CombinedKernel();
        CombinedFeatures feats_train = new CombinedFeatures();
        CombinedFeatures feats_test  = new CombinedFeatures();

        GaussianKernel subkernel = new GaussianKernel(cache, 1.1);

        feats_train.append_feature_obj(subfeats_train);
        feats_test.append_feature_obj(subfeats_test);
        kernel.append_kernel(subkernel);

        StringCharFeatures subkfeats_train = new StringCharFeatures(fm_train_dna, EAlphabet.DNA);
        StringCharFeatures subkfeats_test  = new StringCharFeatures(fm_test_dna, EAlphabet.DNA);

        int degree = 3;

        FixedDegreeStringKernel subkernel2 = new FixedDegreeStringKernel(10, degree);

        feats_train.append_feature_obj(subkfeats_train);
        feats_test.append_feature_obj(subkfeats_test);
        kernel.append_kernel(subkernel2);

        subkfeats_train = new StringCharFeatures(fm_train_dna, EAlphabet.DNA);
        subkfeats_test  = new StringCharFeatures(fm_test_dna, EAlphabet.DNA);
        LocalAlignmentStringKernel subkernel3 = new LocalAlignmentStringKernel(10);

        feats_train.append_feature_obj(subkfeats_train);
        feats_test.append_feature_obj(subkfeats_test);
        kernel.append_kernel(subkernel3);

        kernel.init(feats_train, feats_train);
        double[,] km_train = kernel.get_kernel_matrix();

        kernel.init(feats_train, feats_test);
        double[,] km_test = kernel.get_kernel_matrix();

        modshogun.exit_shogun();
    }
コード例 #7
0
    public virtual object run(IList para)
    {
        modshogun.init_shogun_with_defaults();
        int cardinality = (int)((int?)para[0]);
        int size_cache = (int)((int?)para[1]);

        DoubleMatrix traindata_real = Load.load_numbers("../data/fm_train_real.dat");
        DoubleMatrix testdata_real = Load.load_numbers("../data/fm_test_real.dat");
        string[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat");
        string[] fm_test_dna = Load.load_dna("../data/fm_test_dna.dat");

        RealFeatures subfeats_train = new RealFeatures(traindata_real);
        RealFeatures subfeats_test = new RealFeatures(testdata_real);

        CombinedKernel kernel = new CombinedKernel();
        CombinedFeatures feats_train = new CombinedFeatures();
        CombinedFeatures feats_test = new CombinedFeatures();

        GaussianKernel subkernel = new GaussianKernel(10, 1.1);
        feats_train.append_feature_obj(subfeats_train);
        feats_test.append_feature_obj(subfeats_test);
        kernel.append_kernel(subkernel);

        StringCharFeatures subkfeats_train = new StringCharFeatures(fm_train_dna, DNA);
        StringCharFeatures subkfeats_test = new StringCharFeatures(fm_test_dna, DNA);
        int degree = 3;
        FixedDegreeStringKernel subkernel2 = new FixedDegreeStringKernel(10, degree);
        feats_train.append_feature_obj(subkfeats_train);
        feats_test.append_feature_obj(subkfeats_test);
        kernel.append_kernel(subkernel2);

        subkfeats_train = new StringCharFeatures(fm_train_dna, DNA);
        subkfeats_test = new StringCharFeatures(fm_test_dna, DNA);
        LocalAlignmentStringKernel subkernel3 = new LocalAlignmentStringKernel(10);
        feats_train.append_feature_obj(subkfeats_train);
        feats_test.append_feature_obj(subkfeats_test);
        kernel.append_kernel(subkernel3);

        kernel.init(feats_train, feats_train);
        DoubleMatrix km_train =kernel.get_kernel_matrix();
        kernel.init(feats_train, feats_test);
        DoubleMatrix km_test =kernel.get_kernel_matrix();

        ArrayList result = new ArrayList();
        result.Add(km_train);
        result.Add(km_test);
        result.Add(kernel);

        modshogun.exit_shogun();
        return (object)result;
    }
コード例 #8
0
    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_twoclass.dat");

        CombinedKernel kernel = new CombinedKernel();
        CombinedFeatures feats_train = new CombinedFeatures();
        CombinedFeatures feats_test = new CombinedFeatures();

        RealFeatures subkfeats_train = new RealFeatures(traindata_real);
        RealFeatures subkfeats_test = new RealFeatures(testdata_real);

        GaussianKernel subkernel = new GaussianKernel(10, width);
        feats_train.append_feature_obj(subkfeats_train);
        feats_test.append_feature_obj(subkfeats_test);
        kernel.append_kernel(subkernel);

        LinearKernel subkernel2 = new LinearKernel();
        feats_train.append_feature_obj(subkfeats_train);
        feats_test.append_feature_obj(subkfeats_test);
        kernel.append_kernel(subkernel2);

        PolyKernel subkernel3 = new PolyKernel(10, 2);
        feats_train.append_feature_obj(subkfeats_train);
        feats_test.append_feature_obj(subkfeats_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();
    }
コード例 #9
0
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        int cardinality = 2;
        int cache = 10;

        double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat");
        double[,] testdata_real = Load.load_numbers("../data/fm_test_real.dat");
        String[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat");
        String[] fm_test_dna = Load.load_dna("../data/fm_test_dna.dat");

        RealFeatures subfeats_train = new RealFeatures(traindata_real);
        RealFeatures subfeats_test = new RealFeatures(testdata_real);

        CombinedKernel kernel= new CombinedKernel();
        CombinedFeatures feats_train = new CombinedFeatures();
        CombinedFeatures feats_test = new CombinedFeatures();

        GaussianKernel subkernel = new GaussianKernel(cache, 1.1);
        feats_train.append_feature_obj(subfeats_train);
        feats_test.append_feature_obj(subfeats_test);
        kernel.append_kernel(subkernel);

        StringCharFeatures subkfeats_train = new StringCharFeatures(fm_train_dna, EAlphabet.DNA);
        StringCharFeatures subkfeats_test = new StringCharFeatures(fm_test_dna, EAlphabet.DNA);

        int degree = 3;

        FixedDegreeStringKernel subkernel2= new FixedDegreeStringKernel(10, degree);
        feats_train.append_feature_obj(subkfeats_train);
        feats_test.append_feature_obj(subkfeats_test);
        kernel.append_kernel(subkernel2);

        subkfeats_train = new StringCharFeatures(fm_train_dna, EAlphabet.DNA);
        subkfeats_test = new StringCharFeatures(fm_test_dna, EAlphabet.DNA);
        LocalAlignmentStringKernel subkernel3 = new LocalAlignmentStringKernel(10);
        feats_train.append_feature_obj(subkfeats_train);
        feats_test.append_feature_obj(subkfeats_test);
        kernel.append_kernel(subkernel3);

        kernel.init(feats_train, feats_train);
        double[,] km_train=kernel.get_kernel_matrix();

        kernel.init(feats_train, feats_test);
        double[,] km_test=kernel.get_kernel_matrix();

        modshogun.exit_shogun();
    }