<p>`   mat observation;//obseration matrix<br>
    Row sequence;//label</p>

<pre><code>const size_t length = 75;
const size_t startState = 0;

HMM&lt;DiscreteDistribution&gt; hmm(2, DiscreteDistribution(4));

hmm.Generate(length, observation, sequence, startState);`
</code></pre>

<p>`template<br>
    void HMM::Generate(const size_t length,<br>
        arma::mat&amp; dataSequence,<br>
        arma::Row&amp; stateSequence,<br>
        const size_t startState) const<br>
    {<br>
        // Set vectors to the right size.<br>
        stateSequence.set_size(length);<br>
        dataSequence.set_size(dimensionality, length);</p>

<pre><code>    // Set start state (default is 0).
    stateSequence[0] = startState;

    // Choose first emission state.
    double randValue = ((double)rand() / (RAND_MAX)) + 1;


    // We just have to find where our random value sits in the probability
    // distribution of emissions for our starting state.
    dataSequence.col(0) = emission[startState].Random();

    // Now choose the states and emissions for the rest of the sequence.
    for (size_t t = 1; t &lt; length; t++)
    {
        // First choose the hidden state.
        randValue = ((double)rand() / (RAND_MAX)) + 1;


        // Now find where our random value sits in the probability distribution of
        // state changes.
        double probSum = 0;
        for (size_t st = 0; st &lt; transition.n_rows; st++)
        {
            probSum += transition(st, stateSequence[t - 1]);
            if (randValue &lt;= probSum)
            {
                stateSequence[t] = st;
                break;
            }
        }

        // Now choose the emission.
        dataSequence.col(t) = emission[stateSequence[t]].Random();
    }
}`
</code></pre>

<p>I found some reasons:dataSequence.col(t) = emission[stateSequence[t]].Random(); is error <br>
<a href="http://stackoverflow.com/questions/9100848/vector-subscript-out-of-range-error-in-c">http://stackoverflow.com/questions/9100848/vector-subscript-out-of-range-error-in-c</a></p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/mlpack/mlpack/issues/706">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe/AJ4bFB8rH2xsS_-Zh7uyFgPL0DYVAu0kks5qP4PngaJpZM4I-2L4">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFLFAsFY5_8qRmlwSaK0voDXYUgpNks5qP4PngaJpZM4I-2L4.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/mlpack/mlpack/issues/706"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>