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();
    }
Ejemplo n.º 2
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;
    }
    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();
    }
    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();
    }