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