public static void Main() {
	
	modshogun.init_shogun_with_defaults();
	int order = 3;
	int gap = 0;
	bool reverse = false;
	bool use_sign = false;

	String[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat");
	String[] fm_test_dna = Load.load_dna("../data/fm_test_dna.dat");

	StringCharFeatures charfeat = new StringCharFeatures(EAlphabet.DNA);
	charfeat.set_features(fm_train_dna);
	StringUlongFeatures feats_train = new StringUlongFeatures(charfeat.get_alphabet());
	feats_train.obtain_from_char(charfeat, order-1, order, gap, reverse);
	SortUlongString preproc = new SortUlongString();
	preproc.init(feats_train);
	feats_train.add_preprocessor(preproc);
	feats_train.apply_preprocessor();

	StringCharFeatures charfeat_test = new StringCharFeatures(EAlphabet.DNA);
	charfeat_test.set_features(fm_test_dna);
	StringUlongFeatures feats_test = new StringUlongFeatures(charfeat.get_alphabet());
	feats_test.obtain_from_char(charfeat_test, order-1, order, gap, reverse);
	feats_test.add_preprocessor(preproc);
	feats_test.apply_preprocessor();

	CommUlongStringKernel kernel = new CommUlongStringKernel(feats_train, feats_train, use_sign);

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

    }
	public static void Main() {
		modshogun.init_shogun_with_defaults();
		int order = 3;
		int gap = 0;
		bool reverse = false;
		bool use_sign = false;

		String[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat");
		String[] fm_test_dna = Load.load_dna("../data/fm_test_dna.dat");
		double[] fm_test_real = Load.load_labels("../data/fm_test_real.dat");

		StringCharFeatures charfeat = new StringCharFeatures(EAlphabet.DNA);
		charfeat.set_features(fm_train_dna);
		StringWordFeatures feats_train = new StringWordFeatures(charfeat.get_alphabet());
		feats_train.obtain_from_char(charfeat, order-1, order, gap, reverse);
		SortWordString preproc = new SortWordString();
		preproc.init(feats_train);
		feats_train.add_preprocessor(preproc);
		feats_train.apply_preprocessor();

		StringCharFeatures charfeat_test = new StringCharFeatures(EAlphabet.DNA);
		charfeat_test.set_features(fm_test_dna);
		StringWordFeatures feats_test = new StringWordFeatures(charfeat.get_alphabet());
		feats_test.obtain_from_char(charfeat_test, order-1, order, gap, reverse);
		feats_test.add_preprocessor(preproc);
		feats_test.apply_preprocessor();

		HammingWordDistance distance = new HammingWordDistance(feats_train, feats_train, use_sign);

		double[,] dm_train = distance.get_distance_matrix();
		distance.init(feats_train, feats_test);
		double[,] dm_test = distance.get_distance_matrix();
	}
    static void Main(string[] argv)
    {
        modshogun.init_shogun_with_defaults();
        int order = 3;
        int gap = 0;
        bool reverse = false;

        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 fm_test_real = Load.load_numbers("../data/fm_test_real.dat");

        StringCharFeatures charfeat = new StringCharFeatures(DNA);
        charfeat.set_features(fm_train_dna);
        StringWordFeatures feats_train = new StringWordFeatures(charfeat.get_alphabet());
        feats_train.obtain_from_char(charfeat, order-1, order, gap, reverse);
        SortWordString preproc = new SortWordString();
        preproc.init(feats_train);
        feats_train.add_preprocessor(preproc);
        feats_train.apply_preprocessor();

        StringCharFeatures charfeat_test = new StringCharFeatures(DNA);
        charfeat_test.set_features(fm_test_dna);
        StringWordFeatures feats_test = new StringWordFeatures(charfeat.get_alphabet());
        feats_test.obtain_from_char(charfeat_test, order-1, order, gap, reverse);
        feats_test.add_preprocessor(preproc);
        feats_test.apply_preprocessor();

        ManhattanWordDistance distance = new ManhattanWordDistance(feats_train, feats_train);

        DoubleMatrix dm_train = distance.get_distance_matrix();
        distance.init(feats_train, feats_test);
        DoubleMatrix dm_test = distance.get_distance_matrix();
        modshogun.exit_shogun();
    }
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        int  order   = 3;
        int  gap     = 0;
        bool reverse = false;

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

        StringCharFeatures charfeat = new StringCharFeatures(EAlphabet.DNA);

        charfeat.set_features(fm_train_dna);
        StringWordFeatures feats_train = new StringWordFeatures(charfeat.get_alphabet());

        feats_train.obtain_from_char(charfeat, order - 1, order, gap, reverse);
        SortWordString preproc = new SortWordString();

        preproc.init(feats_train);
        feats_train.add_preprocessor(preproc);
        feats_train.apply_preprocessor();

        StringCharFeatures charfeat_test = new StringCharFeatures(EAlphabet.DNA);

        charfeat_test.set_features(fm_test_dna);
        StringWordFeatures feats_test = new StringWordFeatures(charfeat.get_alphabet());

        feats_test.obtain_from_char(charfeat_test, order - 1, order, gap, reverse);
        feats_test.add_preprocessor(preproc);
        feats_test.apply_preprocessor();

        ManhattanWordDistance distance = new ManhattanWordDistance(feats_train, feats_train);

        double[,] dm_train = distance.get_distance_matrix();
        distance.init(feats_train, feats_test);
        double[,] dm_test = distance.get_distance_matrix();

        foreach (double item in dm_train)
        {
            Console.Write(item);
        }

        foreach (double item in dm_test)
        {
            Console.Write(item);
        }

        modshogun.exit_shogun();
    }
	public static void Main() {
		bool reverse = false;
		modshogun.init_shogun_with_defaults();
		int order = 3;
		int gap = 4;

		String[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat");

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

		Histogram histo = new Histogram(feats);
		histo.train();

		double[] histogram = histo.get_histogram();

		foreach(double item in histogram) {
			Console.Write(item);
		}
		//int  num_examples = feats.get_num_vectors();
		//int num_param = histo.get_num_model_parameters();

		//double[,] out_likelihood = histo.get_log_likelihood();
		//double out_sample = histo.get_log_likelihood_sample();

		modshogun.exit_shogun();
	}
	public static void Main() {
		bool reverse = false;
		modshogun.init_shogun_with_defaults();
		int order = 3;
		int gap = 4;

		String[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat");

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

		LinearHMM hmm = new LinearHMM(feats);
		hmm.train();

		hmm.get_transition_probs();

		int  num_examples = feats.get_num_vectors();
		int num_param = hmm.get_num_model_parameters();
		for (int i = 0; i < num_examples; i++)
			for(int j = 0; j < num_param; j++) {
			hmm.get_log_derivative(j, i);
		}

		double[] out_likelihood = hmm.get_log_likelihood();
		double out_sample = hmm.get_log_likelihood_sample();

	}
Exemple #7
0
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        bool reverse = false;
        int  order   = 3;
        int  gap     = 0;

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

        StringCharFeatures charfeat    = new StringCharFeatures(fm_train_dna, EAlphabet.DNA);
        StringWordFeatures feats_train = new StringWordFeatures(charfeat.get_alphabet());

        feats_train.obtain_from_char(charfeat, order - 1, order, gap, reverse);

        charfeat = new StringCharFeatures(fm_test_dna, EAlphabet.DNA);
        StringWordFeatures feats_test = new StringWordFeatures(charfeat.get_alphabet());

        feats_test.obtain_from_char(charfeat, order - 1, order, gap, reverse);

        SortWordString preproc = new SortWordString();

        preproc.init(feats_train);
        feats_train.add_preprocessor(preproc);
        feats_train.apply_preprocessor();
        feats_test.add_preprocessor(preproc);
        feats_test.apply_preprocessor();

        CommWordStringKernel kernel = new CommWordStringKernel(feats_train, feats_train, false);

        double[,] km_train = kernel.get_kernel_matrix();
        kernel.init(feats_train, feats_test);
        double[,] km_test = kernel.get_kernel_matrix();
    }
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();

        bool reverse = false;
        int  order   = 3;
        int  gap     = 0;
        int  degree  = 2;

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

        StringCharFeatures charfeat    = new StringCharFeatures(fm_train_dna, EAlphabet.DNA);
        StringWordFeatures feats_train = new StringWordFeatures(charfeat.get_alphabet());

        feats_train.obtain_from_char(charfeat, order - 1, order, gap, false);

        charfeat = new StringCharFeatures(fm_test_dna, EAlphabet.DNA);
        StringWordFeatures feats_test = new StringWordFeatures(charfeat.get_alphabet());

        feats_test.obtain_from_char(charfeat, order - 1, order, gap, false);

        PolyMatchWordStringKernel kernel = new PolyMatchWordStringKernel(feats_train, feats_train, degree, true);

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

        modshogun.exit_shogun();
    }
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();

        bool reverse = false;
        int order = 3;
        int gap = 0;
        int degree = 2;

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

        StringCharFeatures charfeat = new StringCharFeatures(fm_train_dna, EAlphabet.DNA);
        StringWordFeatures feats_train = new StringWordFeatures(charfeat.get_alphabet());
        feats_train.obtain_from_char(charfeat, order-1, order, gap, false);

        charfeat = new StringCharFeatures(fm_test_dna, EAlphabet.DNA);
        StringWordFeatures feats_test = new StringWordFeatures(charfeat.get_alphabet());
        feats_test.obtain_from_char(charfeat, order-1, order, gap, false);

        PolyMatchWordStringKernel kernel = new PolyMatchWordStringKernel(feats_train, feats_train, degree, true);
        double[,] km_train = kernel.get_kernel_matrix();
        kernel.init(feats_train, feats_test);
        double[,] km_test=kernel.get_kernel_matrix();
    }
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();

        bool reverse = false;
        int order = 3;
        int gap = 0;

        String[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat");
        String[] fm_test_dna = Load.load_dna("../data/fm_test_dna.dat");

        StringCharFeatures charfeat = new StringCharFeatures(fm_train_dna, EAlphabet.DNA);
        StringWordFeatures feats_train = new StringWordFeatures(charfeat.get_alphabet());
        feats_train.obtain_from_char(charfeat, order-1, order, gap, false);

        charfeat = new StringCharFeatures(fm_test_dna, EAlphabet.DNA);
        StringWordFeatures feats_test = new StringWordFeatures(charfeat.get_alphabet());
        feats_test.obtain_from_char(charfeat, order-1, order, gap, false);

        BinaryLabels labels = new BinaryLabels(Load.load_labels("../data/label_train_dna.dat"));

        PluginEstimate pie = new PluginEstimate();
        pie.set_labels(labels);
        pie.set_features(feats_train);
        pie.train();

        SalzbergWordStringKernel kernel = new SalzbergWordStringKernel(feats_train, feats_train, pie, labels);
        double[,] km_train = kernel.get_kernel_matrix();
        kernel.init(feats_train, feats_test);
        pie.set_features(feats_test);
        BinaryLabels.obtain_from_generic(pie.apply()).get_labels();
        double[,] km_test=kernel.get_kernel_matrix();

        modshogun.exit_shogun();
    }
    internal static ArrayList run(IList para)
    {
        bool reverse = false;
        modshogun.init_shogun_with_defaults();
        int order = (int)((int?)para[0]);
        int gap = (int)((int?)para[1]);

        string[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat");

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

        Histogram histo = new Histogram(feats);
        histo.train();

        histo.get_histogram();

        int num_examples = feats.get_num_vectors();
        int num_param = histo.get_num_model_parameters();

        DoubleMatrix out_likelihood = histo.get_log_likelihood();
        double out_sample = histo.get_log_likelihood_sample();

        ArrayList result = new ArrayList();
        result.Add(histo);
        result.Add(out_sample);
        result.Add(out_likelihood);
        modshogun.exit_shogun();
        return result;
    }
    internal static ArrayList run(IList para)
    {
        bool reverse = false;
        modshogun.init_shogun_with_defaults();

        int order = (int)((int?)para[0]);
        int gap = (int)((int?)para[1]);
        int degree = (int)((int?)para[2]);

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

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

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

        PolyMatchWordStringKernel kernel = new PolyMatchWordStringKernel(feats_train, feats_train, degree, true);
        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 result;
    }
    public static void Main()
    {
        bool reverse = false;

        modshogun.init_shogun_with_defaults();
        int order = 3;
        int gap   = 4;

        String[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat");

        StringCharFeatures charfeat = new StringCharFeatures(fm_train_dna, EAlphabet.DNA);
        StringWordFeatures feats    = new StringWordFeatures(charfeat.get_alphabet());

        feats.obtain_from_char(charfeat, order - 1, order, gap, reverse);

        Histogram histo = new Histogram(feats);

        histo.train();

        double[] histogram = histo.get_histogram();

        foreach (double item in histogram)
        {
            Console.Write(item);
        }
        //int  num_examples = feats.get_num_vectors();
        //int num_param = histo.get_num_model_parameters();

        //double[,] out_likelihood = histo.get_log_likelihood();
        //double out_sample = histo.get_log_likelihood_sample();

        modshogun.exit_shogun();
    }
    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_cubes("../data/fm_train_cube.dat");

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

        HMM hmm = new HMM(feats, N, M, pseudo);
        hmm.train();
        hmm.baum_welch_viterbi_train(BW_NORMAL);

        int num_examples = feats.get_num_vectors();
        int num_param = hmm.get_num_model_parameters();
        for (int i = 0; i < num_examples; i++)
        {
            for(int j = 0; j < num_param; j++)
            {
            hmm.get_log_derivative(j, i);
        }
        }

        int best_path = 0;
        int best_path_state = 0;
        for(int i = 0; i < num_examples; i++)
        {
            best_path += hmm.best_path(i);
            for(int j = 0; j < N; j++)
            {
                best_path_state += hmm.get_best_path_state(i, j);
            }
        }

        DoubleMatrix lik_example = hmm.get_log_likelihood();
        double lik_sample = hmm.get_log_likelihood_sample();

        ArrayList result = new ArrayList();
        result.Add(lik_example);
        result.Add(lik_sample);
        result.Add(hmm);
        modshogun.exit_shogun();
        return result;
    }
    public static void Main()
    {
        bool reverse = false;

        modshogun.init_shogun_with_defaults();
        int    N      = 1;
        int    M      = 512;
        double pseudo = 1e-5;
        int    order  = 3;
        int    gap    = 0;

        string[] fm_train_dna = Load.load_cubes("../data/fm_train_cube.dat");

        StringCharFeatures charfeat = new StringCharFeatures(fm_train_dna, EAlphabet.CUBE);
        StringWordFeatures feats    = new StringWordFeatures(charfeat.get_alphabet());

        feats.obtain_from_char(charfeat, order - 1, order, gap, reverse);

        HMM hmm = new HMM(feats, N, M, pseudo);

        hmm.train();
        hmm.baum_welch_viterbi_train(BaumWelchViterbiType.BW_NORMAL);

        int num_examples = feats.get_num_vectors();
        int num_param    = hmm.get_num_model_parameters();

        for (int i = 0; i < num_examples; i++)
        {
            for (int j = 0; j < num_param; j++)
            {
                hmm.get_log_derivative(j, i);
            }
        }

        int best_path       = 0;
        int best_path_state = 0;

        for (int i = 0; i < num_examples; i++)
        {
            best_path += (int)hmm.best_path(i);
            for (int j = 0; j < N; j++)
            {
                best_path_state += hmm.get_best_path_state(i, j);
            }
        }

        double[] lik_example = hmm.get_log_likelihood();
        double   lik_sample  = hmm.get_log_likelihood_sample();

        modshogun.exit_shogun();
    }
    public static void Main()
    {
        bool reverse = false;
        modshogun.init_shogun_with_defaults();
        int N = 1;
        int M = 512;
        double pseudo = 1e-5;
        int order = 3;
        int gap = 0;

        string[] fm_train_dna = Load.load_cubes("../data/fm_train_cube.dat");

        StringCharFeatures charfeat = new StringCharFeatures(fm_train_dna, EAlphabet.CUBE);
        StringWordFeatures feats = new StringWordFeatures(charfeat.get_alphabet());
        feats.obtain_from_char(charfeat, order-1, order, gap, reverse);

        HMM hmm = new HMM(feats, N, M, pseudo);
        hmm.train();
        hmm.baum_welch_viterbi_train(BaumWelchViterbiType.BW_NORMAL);

        int  num_examples = feats.get_num_vectors();
        int num_param = hmm.get_num_model_parameters();
        for (int i = 0; i < num_examples; i++)
            for(int j = 0; j < num_param; j++) {
            hmm.get_log_derivative(j, i);
        }

        int best_path = 0;
        int best_path_state = 0;
        for(int i = 0; i < num_examples; i++){
            best_path += (int)hmm.best_path(i);
            for(int j = 0; j < N; j++)
                best_path_state += hmm.get_best_path_state(i, j);
        }

        double[] lik_example = hmm.get_log_likelihood();
        double lik_sample = hmm.get_log_likelihood_sample();

        modshogun.exit_shogun();
    }
    internal static ArrayList run(IList para)
    {
        bool reverse = false;
        modshogun.init_shogun_with_defaults();

        int order = (int)((int?)para[0]);
        int gap = (int)((int?)para[1]);

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

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

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

        Labels labels = new Labels(Load.load_labels("../data/label_train_dna.dat"));

        PluginEstimate pie = new PluginEstimate();
        pie.set_labels(labels);
        pie.set_features(feats_train);
        pie.train();

        SalzbergWordStringKernel kernel = new SalzbergWordStringKernel(feats_train, feats_train, pie, labels);
        DoubleMatrix km_train = kernel.get_kernel_matrix();
        kernel.init(feats_train, feats_test);
        pie.set_features(feats_test);
        pie.apply().get_labels();
        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;
    }
    internal static void run(IList para)
    {
        bool reverse = false;
        modshogun.init_shogun_with_defaults();
        int order = (int)((int?)para[0]);
        int gap = (int)((int?)para[1]);

        string[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat");

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

        PositionalPWM ppwm = new PositionalPWM();
        ppwm.set_sigma(5.0);
        ppwm.set_mean(10.0);
        DoubleMatrix pwm = new DoubleMatrix(new double[][] {{0.0, 0.5, 0.1, 1.0}, {0.0, 0.5, 0.5, 0.0}, {1.0, 0.0, 0.4, 0.0}, {0.0, 0.0, 0.0, 0.0}});
        //ppwm.set_pwm(DoubleMatrix.log(pwm));
        ppwm.compute_w(20);
        DoubleMatrix w = ppwm.get_w();
        modshogun.exit_shogun();
    }
Exemple #19
0
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();

        bool reverse = false;
        int  order   = 3;
        int  gap     = 0;

        String[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat");
        String[] fm_test_dna  = Load.load_dna("../data/fm_test_dna.dat");

        StringCharFeatures charfeat    = new StringCharFeatures(fm_train_dna, EAlphabet.DNA);
        StringWordFeatures feats_train = new StringWordFeatures(charfeat.get_alphabet());

        feats_train.obtain_from_char(charfeat, order - 1, order, gap, false);

        charfeat = new StringCharFeatures(fm_test_dna, EAlphabet.DNA);
        StringWordFeatures feats_test = new StringWordFeatures(charfeat.get_alphabet());

        feats_test.obtain_from_char(charfeat, order - 1, order, gap, false);

        BinaryLabels labels = new BinaryLabels(Load.load_labels("../data/label_train_dna.dat"));

        PluginEstimate pie = new PluginEstimate();

        pie.set_labels(labels);
        pie.set_features(feats_train);
        pie.train();

        SalzbergWordStringKernel kernel = new SalzbergWordStringKernel(feats_train, feats_train, pie, labels);

        double[,] km_train = kernel.get_kernel_matrix();
        kernel.init(feats_train, feats_test);
        pie.set_features(feats_test);
        BinaryLabels.obtain_from_generic(pie.apply()).get_labels();
        double[,] km_test = kernel.get_kernel_matrix();

        modshogun.exit_shogun();
    }
    internal static ArrayList run(IList para)
    {
        bool reverse = false;
        modshogun.init_shogun_with_defaults();
        int order = (int)((int?)para[0]);
        int gap = (int)((int?)para[1]);

        string[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat");

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

        LinearHMM hmm = new LinearHMM(feats);
        hmm.train();

        hmm.get_transition_probs();

        int num_examples = feats.get_num_vectors();
        int num_param = hmm.get_num_model_parameters();
        for (int i = 0; i < num_examples; i++)
        {
            for(int j = 0; j < num_param; j++)
            {
            hmm.get_log_derivative(j, i);
        }
        }

        DoubleMatrix out_likelihood = hmm.get_log_likelihood();
        double out_sample = hmm.get_log_likelihood_sample();

        ArrayList result = new ArrayList();
        result.Add(hmm);
        result.Add(out_sample);
        result.Add(out_likelihood);
        modshogun.exit_shogun();
        return result;
    }
    internal static ArrayList run(IList para)
    {
        bool reverse = false;
        modshogun.init_shogun_with_defaults();
        int order = (int)((int?)para[0]);
        int gap = (int)((int?)para[1]);

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

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

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

        SortUlongString preproc = new SortUlongString();
        preproc.init(feats_train);
        feats_train.add_preprocessor(preproc);
        feats_train.apply_preprocessor();
        feats_test.add_preprocessor(preproc);
        feats_test.apply_preprocessor();

        CommUlongStringKernel kernel = new CommUlongStringKernel(feats_train, feats_train, false);

        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 result;
    }
    static void Main(string[] argv)
    {
        modshogun.init_shogun_with_defaults();
        int num = 10;
        int order = 7;
        int gap = 0;
        bool reverse = false;

        string[] POS = new string[141];
        for (int i = 0; i < 60; i++)
        {
            POS[i] = repeat("ACGT", 10);
        }
        for (int i = 61; i < 82; i++)
        {
            POS[i] = repeat("TTGT", 10);
        }
        for (int i = 83; i < 141; i++)
        {
            POS[i] = repeat("ACGT", 10);
        }

        string[] NEG = new string[141];
        for (int i = 0; i < 60; i++)
        {
            NEG[i] = repeat("ACGT", 10);
        }
        for (int i = 61; i < 82; i++)
        {
            NEG[i] = repeat("TTGT", 10);
        }
        for (int i = 83; i < 141; i++)
        {
            NEG[i] = repeat("ACGT", 10);
        }

        string[] POSNEG = new string[282];
        for (int i = 0; i < 141; i++)
        {
            POSNEG[i] = POS[i];
            POSNEG[i + 141] = NEG[i];
        }

        for(int i = 0; i < 10; i++)
        {
            Alphabet alpha = new Alphabet(DNA);
            StringCharFeatures traindat = new StringCharFeatures(alpha);
            traindat.set_features(POSNEG);
            StringWordFeatures trainudat = new StringWordFeatures(traindat.get_alphabet());
            trainudat.obtain_from_char(traindat, order-1, order, gap, reverse);
            SortWordString pre = new SortWordString();
            pre.init(trainudat);
            trainudat.add_preprocessor(pre);
            trainudat.apply_preprocessor();
            CommWordStringKernel spec = new CommWordStringKernel(10, false);
            spec.set_normalizer(new IdentityKernelNormalizer());
            spec.init(trainudat, trainudat);
            DoubleMatrix K = spec.get_kernel_matrix();
        }

        modshogun.exit_shogun();
    }
Exemple #23
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;
    }