Esempio n. 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_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();
    }
Esempio n. 2
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");

        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();
    }
    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();
    }
Esempio n. 4
0
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        int degree = 4;

        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);

        PolyKernel kernel = new PolyKernel(feats_train, feats_train, degree, false);

        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();
        int degree = 4;

        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);

        PolyKernel kernel = new PolyKernel(feats_train, feats_train, degree, false);

        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();
    }
Esempio n. 6
0
    static void Main(string[] argv)
    {
        modshogun.init_shogun_with_defaults();
        int degree = 4;

        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);

        PolyKernel kernel = new PolyKernel(feats_train, feats_train, degree, false);

        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();
    }
Esempio n. 7
0
    internal static ArrayList run(IList para)
    {
        bool reverse = false;
        modshogun.init_shogun_with_defaults();
        int N = (int)((int?)para[0]);
        int M = (int)((int?)para[1]);
        double pseudo = (double)((double?)para[2]);
        int order = (int)((int?)para[3]);
        int gap = (int)((int?)para[4]);

        string[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat");
        string[] fm_test_dna = Load.load_dna("../data/fm_test_dna.dat");
        DoubleMatrix label_train_dna = Load.load_labels("../data/label_train_dna.dat");

        ArrayList fm_hmm_pos_builder = new ArrayList();
        ArrayList fm_hmm_neg_builder = new ArrayList();
        for(int i = 0; i < label_train_dna.Columns; i++)
        {
            if (label_train_dna.get(i) == 1)
            {
                fm_hmm_pos_builder.Add(fm_train_dna[i]);
            }
            else
            {
                fm_hmm_neg_builder.Add(fm_train_dna[i]);
            }
        }

        int pos_size = fm_hmm_pos_builder.Count;
        int neg_size = fm_hmm_neg_builder.Count;
        string[] fm_hmm_pos = new string[pos_size];
        string[] fm_hmm_neg = new string[neg_size];
        for (int i = 0; i < pos_size; i++)
        {
            fm_hmm_pos[i] = (string)fm_hmm_pos_builder[i];
        }
        for (int i = 0; i < neg_size; i++)
        {
            fm_hmm_pos[i] = (string)fm_hmm_neg_builder[i];
        }

        StringCharFeatures charfeat = new StringCharFeatures(fm_hmm_pos, DNA);
        StringWordFeatures hmm_pos_train = new StringWordFeatures(charfeat.get_alphabet());
        hmm_pos_train.obtain_from_char(charfeat, order-1, order, gap, reverse);

        HMM pos = new HMM(hmm_pos_train, N, M, pseudo);
        pos.baum_welch_viterbi_train(BW_NORMAL);

        charfeat = new StringCharFeatures(fm_hmm_neg, DNA);
        StringWordFeatures hmm_neg_train = new StringWordFeatures(charfeat.get_alphabet());
        hmm_neg_train.obtain_from_char(charfeat, order-1, order, gap, reverse);

        HMM neg = new HMM(hmm_neg_train, N, M, pseudo);
        neg.baum_welch_viterbi_train(BW_NORMAL);

        charfeat = new StringCharFeatures(fm_train_dna, DNA);
        StringWordFeatures wordfeats_train = new StringWordFeatures(charfeat.get_alphabet());
        wordfeats_train.obtain_from_char(charfeat, order-1, order, gap, reverse);

        charfeat = new StringCharFeatures(fm_test_dna, DNA);
        StringWordFeatures wordfeats_test = new StringWordFeatures(charfeat.get_alphabet());
        wordfeats_test.obtain_from_char(charfeat, order-1, order, gap, reverse);

        pos.set_observations(wordfeats_train);
        neg.set_observations(wordfeats_train);
        FKFeatures feats_train = new FKFeatures(10, pos, neg);
        feats_train.set_opt_a(-1);
        PolyKernel kernel = new PolyKernel(feats_train, feats_train, 1, true);
        DoubleMatrix km_train = kernel.get_kernel_matrix();

        HMM pos_clone = new HMM(pos);
        HMM neg_clone = new HMM(neg);
        pos_clone.set_observations(wordfeats_test);
        neg_clone.set_observations(wordfeats_test);
        FKFeatures feats_test = new FKFeatures(10, pos_clone, neg_clone);
        feats_test.set_a(feats_train.get_a());
        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 result;
    }