src/CXX/math/baum-welch.hxx
baum_welch(
        model_t & model,
        bool      init_pi = false,
        bool      init_tr = false,
        bool      init_e  = false)
    :
        m_model(model)
    {
        if (!(init_pi || init_tr || init_e))
            return;  // no initialisation

        // Initialise states start probability
        if (init_pi) {
            auto pi = rand_p_vector(m_model.state_cnt());

            m_model.for_each_state([&pi](state_t & state) {
                state.value.p = pi[state.value.index];
            });
        }

        // Initialise transitions probability
        if (init_tr) {
            m_model.for_each_state([this](state_t & state) {
                auto A = rand_p_vector(m_model.transition_cnt_from(state));

                size_t ij = 0;
                m_model.for_each_trans_from(state,
                [&A,&ij](transition_t & trans) {
                    trans.value.p = A[ij++];
                });
            });
        }

        // Initialise emissions probability
        if (init_e) {
            m_model.for_each_state([this](state_t & state) {
                state.value.emit_p.set_rand();
            });
        }
    }
/**
     *  \brief Constructor
     *
     *  The constructor initialises the model parameters
     *  (states start probability and transitions probability)
     *  by random values if the \c init_pi and \c init_tr parameters
     *  are \c true, respectively.
     *  If at least one is \c true, the \c seed parameter may be used
     *  to specify the RNG seed
     *  (0 means that current time shall be used,
     *  -1 means not to seed the RNG, which is the default).
     *
     *  \param  model    Trained model
     *  \param  init_pi  Initialise states start probability
     *  \param  init_tr  Initialise transitions probability
     *  \param  init_e   Initialise emissions probability
     */
\brief Constructor
The constructor initialises the model parameters
(states start probability and transitions probability)
by random values if the \c init_pi and \c init_tr parameters
are \c true, respectively.
If at least one is \c true, the \c seed parameter may be used
to specify the RNG seed
(0 means that current time shall be used,
-1 means not to seed the RNG, which is the default).

\param  model    Trained model
\param  init_pi  Initialise states start probability
\param  init_tr  Initialise transitions probability
\param  init_e   Initialise emissions probability
\ brief Constructor The constructor initialises the model parameters ( states start probability and transitions probability ) by random values if the \ c init_pi and \ c init_tr parameters are \ c true respectively . If at least one is \ c true the \ c seed parameter may be used to specify the RNG seed ( 0 means that current time shall be used - 1 means not to seed the RNG which is the default ) . \ param model Trained model \ param init_pi Initialise states start probability \ param init_tr Initialise transitions probability \ param init_e Initialise emissions probability
baum_welch(
        model_t & model,
        bool      init_pi = false,
        bool      init_tr = false,
        bool      init_e  = false)
    :
        m_model(model)
    {
        if (!(init_pi || init_tr || init_e))
            return;  
        if (init_pi) {
            auto pi = rand_p_vector(m_model.state_cnt());
            m_model.for_each_state([&pi](state_t & state) {
                state.value.p = pi[state.value.index];
            });
        }
        if (init_tr) {
            m_model.for_each_state([this](state_t & state) {
                auto A = rand_p_vector(m_model.transition_cnt_from(state));
                size_t ij = 0;
                m_model.for_each_trans_from(state,
                [&A,&ij](transition_t & trans) {
                    trans.value.p = A[ij++];
                });
            });
        }
        if (init_e) {
            m_model.for_each_state([this](state_t & state) {
                state.value.emit_p.set_rand();
            });
        }
    }
baum_welch ( model_t & model , bool init_pi = false , bool init_tr = false , bool init_e = false ) : m_model ( model ) { if ( ! ( init_pi || init_tr || init_e ) ) return ; if ( init_pi ) { auto pi = rand_p_vector ( m_model . state_cnt ( ) ) ; m_model . for_each_state ( [ & pi ] ( state_t & state ) { state . value . p = pi [ state . value . index ] ; } ) ; } if ( init_tr ) { m_model . for_each_state ( [ this ] ( state_t & state ) { auto A = rand_p_vector ( m_model . transition_cnt_from ( state ) ) ; size_t ij = 0 ; m_model . for_each_trans_from ( state , [ & A , & ij ] ( transition_t & trans ) { trans . value . p = A [ ij ++ ] ; } ) ; } ) ; } if ( init_e ) { m_model . for_each_state ( [ this ] ( state_t & state ) { state . value . emit_p . set_rand ( ) ; } ) ; } }
\brief Constructor
  The constructor initialises the model parameters
  (states start probability and transitions probability)
  by random values if the \c init_pi and \c init_tr parameters
  are \c true, respectively.
\ brief Constructor The constructor initialises the model parameters ( states start probability and transitions probability ) by random values if the \ c init_pi and \ c init_tr parameters are \ c true respectively .
// no initialisation // Initialise states start probability // Initialise transitions probability // Initialise emissions probability