void HMM::setEmissionPropability(array1D mean, array1D std){ assert(mean.size() >= this->stateCount); assert(std.size() >= this->stateCount); for (unsigned int i = 0; i < this->stateCount; i += 1){ this->setEmissionPropability(mean[i], std[i], i); } }
void simulateHMM( array1D &data, std::vector<unsigned int> &state, const array2D transition, const std::vector<GaussState> states, const unsigned int dataSize ){ const unsigned int statesCount = states.size(); data.resize(dataSize); state.resize(dataSize); state[0] = std::rand() % statesCount; data[0] = states[state[0]].random(); for (unsigned int t = 1; t < dataSize; t += 1){ double r = (double) rand() / (double) RAND_MAX; unsigned int s; for (s = 0; s < statesCount; s += 1){ r -= transition[state[t - 1]][s]; if (r <= 0){ break; } } if (s == 3){ s = 2; } state[t] = s; data[t] = states[state[t]].random(); } };
double hiddenMarkovModel::normaliseArray(array1D &arr){ double sum = 0; for (unsigned int i = 0, end = arr.size(); i < end; i += 1){ sum += arr[i]; } rescaleArray(arr, sum); return sum; };
void hiddenMarkovModel::rescaleArray(array1D &arr, double factor){ for (unsigned int i = 0, end = arr.size(); i < end; i += 1){ arr[i] /= factor; } };
void HMM::getBinningRange(array1D &range){ range.resize(2); range[0] = this->binner->getMin(); range[1] = this->binner->getMax(); }