-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhiddenMarkovModel.cpp
108 lines (82 loc) · 2.47 KB
/
hiddenMarkovModel.cpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// hiddenMarkovModel.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
int _tmain(int argc, _TCHAR* argv[])
{
// only tests up to now
using namespace hiddenMarkovModel;
int dataSize = 5000;
double *data = new double[dataSize];
for (int i = 0; i < dataSize; i += 1){
data[i] = 1.0/(double)(i + 1);
}
std::vector<InitialEmissionProbability*> states(0);
states.push_back(new GaussState(0, 1));
states.push_back(new GaussState(1, 1));
// HMMConfiguration configuration;
// configuration.binningCount = 100;
// configuration.verbose = true;
// configuration.pauseAfterIteration = true;
HMMConfiguration configuration = HMMConfiguration::fromFile(std::ifstream("test.json"));
std::cout << "create model" << std::endl;
HMM model (data, std::vector<unsigned long>(2, dataSize/ 2), states, configuration);
array1D binnerRange(2, 0);
model.getBinningRange(binnerRange);
std::cout << "binning range: " << binnerRange[0] << " to " << binnerRange[1]<< std::endl;
std::cout << "set transition" << std::endl;
for (int i = 0; i < 2; i += 1){
for (int j = 0; j < 2; j += 1){
model.setTransition(0.5, i, j);
}
}
model.run();
std::vector<unsigned int> fittedStates (dataSize, 0);
model.viterbi(fittedStates);
delete data;
states.clear();
std::cout << "Hit enter to exit." << std::endl;
char in[1];
std::cin.read(in, 1);
return 0;
}
// hiddenMarkovModel.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//
/*
#include "stdafx.h"
#include "GMM.h"
#include <iostream>
#include <fstream>
int _tmain(int argc, _TCHAR* argv[])
{
// only tests up to now
using namespace hiddenMarkovModel;
unsigned int dataSize = 100000;
array1D data(dataSize);
std::vector<unsigned int> state(dataSize);
array2D transition(3, array1D(3, 0));
transition[0][0] = 0.8;
transition[0][1] = 0.1;
transition[0][2] = 0.1;
transition[1][0] = 0.2;
transition[1][1] = 0.6;
transition[1][2] = 0.2;
transition[2][0] = 0.1;
transition[2][1] = 0.1;
transition[2][2] = 0.8;
std::vector<GaussState> states(0);
states.push_back(GaussState(0, 20));
states.push_back(GaussState(50, 20));
states.push_back(GaussState(100, 20));
std::cout << "simulate data" << std::endl;
simulateHMM(data, state, transition, states, dataSize);
std::cout << "create model" << std::endl;
GMM model (data, states);
model.run();
std::cout << "Hit enter to exit." << std::endl;
char in[1];
std::cin.read(in, 1);
return 0;
}
*/