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

	}
    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();
    }
Example #4
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_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();
    }
    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;
    }