Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression vector subscript out of range #706

Closed
gallupliu opened this issue Jun 27, 2016 · 2 comments
Closed

expression vector subscript out of range #706

gallupliu opened this issue Jun 27, 2016 · 2 comments

Comments

@gallupliu
Copy link

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

const size_t length = 75;
const size_t startState = 0;

HMM<DiscreteDistribution> hmm(2, DiscreteDistribution(4));

hmm.Generate(length, observation, sequence, startState);`

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

    // 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 < 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 < transition.n_rows; st++)
        {
            probSum += transition(st, stateSequence[t - 1]);
            if (randValue <= probSum)
            {
                stateSequence[t] = st;
                break;
            }
        }

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

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

@rcurtin
Copy link
Member

rcurtin commented Jul 1, 2016

Hi, I don't understand what the problem here is. Can you provide more information on what you were trying to do, what the problem was, what the output was, and so forth? I can't help out unless I know what the issue is.

Thanks,
Ryan

@rcurtin
Copy link
Member

rcurtin commented Jul 31, 2016

Closing for inactivity. Feel free to reopen/comment if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants