-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkov_state.cpp
More file actions
29 lines (26 loc) · 853 Bytes
/
markov_state.cpp
File metadata and controls
29 lines (26 loc) · 853 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
#include "markov_state.h"
void markov_state::init( markov_state next[2] ) {
for( int i = 0; i < 2; ++i ) {
count[i] = 0.2f; // An initial value for the very first state
this->next[i] = &next[i];
}
}
float markov_state::total_count() {
float total_count = 0.0f;
for ( int i = 0; i < 2; ++i ) {
total_count += count[i];
}
return total_count;
}
// On initialisation clone the state as per DMC cloning rules
void markov_state::init( int byte, markov_state *parent, markov_state *cloned_from ) {
for( int i = 0; i < 2; ++i ) {
count[i] = 0.0f;
}
float ratio = parent->count[byte] / cloned_from->total_count();
for ( int i = 0; i < 2; ++i ) {
count[i] = cloned_from->count[i] * ratio;
cloned_from->count[i] -= count[i];
next[i] = cloned_from->next[i];
}
}