[mlpack-git] [mlpack/mlpack] expression vector subscript out of range (#706)
gallup
notifications at github.com
Mon Jun 27 04:03:51 EDT 2016
` 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<typename Distribution>
void HMM<Distribution>::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
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/mlpack/mlpack/issues/706
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.cc.gatech.edu/pipermail/mlpack-git/attachments/20160627/a180c1dd/attachment-0001.html>
More information about the mlpack-git
mailing list