当前位置: 首页>>代码示例>>C++>>正文


C++ HMM::Save_Parameters方法代码示例

本文整理汇总了C++中HMM::Save_Parameters方法的典型用法代码示例。如果您正苦于以下问题:C++ HMM::Save_Parameters方法的具体用法?C++ HMM::Save_Parameters怎么用?C++ HMM::Save_Parameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HMM的用法示例。


在下文中一共展示了HMM::Save_Parameters方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: throw

shared_ptr< HMM<double> > Merge_Models(shared_ptr < HMM<double> > cpg, shared_ptr< HMM<double> > non_cpg, uint average_cpg_length, uint average_non_cpg_length)
{
    if (cpg->get_no_states() != non_cpg->get_no_states())
    {
        throw("Models states number must be same");
    }

    if (cpg->get_alphabet_size() != non_cpg->get_alphabet_size())
    {
        throw("Models alphabet size must be same");
    }

    double leave_cpg_probability = 1/(double)average_cpg_length;
    double stay_cpg_probability = 1 - leave_cpg_probability;
    double leave_non_cpg_probability = 1/(double)average_non_cpg_length;
    double stay_non_cpg_probability = 1 - leave_non_cpg_probability;

    //initial probabilities
    shared_ptr< HMMVector<double> > initial_probabilities(new HMMVector<double>(cpg->get_no_states()*2));
    uint i;
    for (i = 0; i < cpg->get_no_states(); ++i)
    {
        (*initial_probabilities)(i) = cpg->get_initial_probs()(i)/2;
    }
    for (uint j = 0; j < non_cpg->get_no_states(); ++j)
    {
        (*initial_probabilities)(j + i) = non_cpg->get_initial_probs()(j)/2;
    }

    //transition probabilities
    shared_ptr< HMMMatrix<double> > transition_probabilities(new HMMMatrix<double>(cpg->get_no_states()*2, cpg->get_no_states()*2));
    for (uint i = 0; i < transition_probabilities->get_no_rows(); ++i)
    {
        for (uint j = 0; j < transition_probabilities->get_no_columns(); ++j)
        {
            if (i < cpg->get_no_states() && j < cpg->get_no_states())
            {
                (*transition_probabilities)(i, j) = cpg->get_trans_probs()(i, j)*stay_cpg_probability;
            }
            if (i < cpg->get_no_states() && j >= cpg->get_no_states())
            {
                (*transition_probabilities)(i, j) = cpg->get_trans_probs()(i, j - cpg->get_no_states())*leave_cpg_probability;
            }
            if (i >= cpg->get_no_states() && j < cpg->get_no_states())
            {
                (*transition_probabilities)(i, j) = non_cpg->get_trans_probs()(i - cpg->get_no_states(), j)*leave_non_cpg_probability;
            }
            if (i >= cpg->get_no_states() && j >= cpg->get_no_states())
            {
                (*transition_probabilities)(i, j) =
                        non_cpg->get_trans_probs()(i - cpg->get_no_states(), j - cpg->get_no_states())*stay_non_cpg_probability;
            }
        }
    }

    //emission probabilities
    shared_ptr< HMMMatrix<double> > emission_probabilities(new HMMMatrix<double>(cpg->get_alphabet_size(), cpg->get_no_states()*2));
    for (uint i = 0; i < cpg->get_alphabet_size(); ++i)
    {
        for (uint j = 0; j < cpg->get_no_states()*2; ++j)
        {
            if (j < cpg->get_no_states())
            {
                (*emission_probabilities)(i, j) = cpg->get_emission_probs()(i, j);
            }
            else
            {
                (*emission_probabilities)(i, j) = non_cpg->get_emission_probs()(i, j - cpg->get_no_states());
            }
        }
    }

    HMM<double>* hmm = new HMM<double>(initial_probabilities, transition_probabilities, emission_probabilities);
    hmm->Save_Parameters();

    return shared_ptr< HMM<double> >(hmm);
}
开发者ID:dartlenin,项目名称:Cpg_Islands,代码行数:77,代码来源:main.cpp


注:本文中的HMM::Save_Parameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。