-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsimulateHMM.cpp
More file actions
38 lines (34 loc) · 801 Bytes
/
simulateHMM.cpp
File metadata and controls
38 lines (34 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once
#include "typedefs.h"
#include "GaussState.h"
#include <random>
namespace hiddenMarkovModel{
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();
}
};
}