StochHMM
v0.34
Flexible Hidden Markov Model C++ Library and Application
Main Page
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
stochTable.h
Go to the documentation of this file.
1
//
2
// stoch_table.h
3
// StochHMM
4
//
5
// Created by Paul Lott on 2/4/13.
6
// Copyright (c) 2013 Korf Lab, Genome Center, UC Davis, Davis, CA. All rights reserved.
7
//
8
9
#ifndef __StochHMM__stoch_table__
10
#define __StochHMM__stoch_table__
11
12
#include <iostream>
13
#include <sstream>
14
#include <string>
15
#include <vector>
16
#include "
stochMath.h
"
17
#include "
traceback_path.h
"
18
#include "
sparseArray.h
"
19
20
namespace
StochHMM {
21
22
/*! \class stochTable
23
* Stochastic table stores stochastic values in a vector. Data structure is
24
* implemented to reduce the memory that would be needed if we allocated a 2D
25
* table with all the transitions. This lookup table is 1D and only stores
26
* those values which we add. Each the value are stores
27
* (Current state, Previous State, Score as P(X)). In addition, the indices
28
* of each state and position are recorded so that they can be referenced
29
* quickly. So the memory size necessary to store the values for a sparsely
30
* connected model are greatly reduce. However, the time to recreate the table
31
* is increased because it doesn't allocate the memory up front, but rather
32
* pushes values as they are recorded.
33
*/
34
class
stochTable
{
35
public
:
36
37
/*! \struct stoch_value;
38
* Structure used to store the traceback values (Current state,
39
* Previous State, Traceback probability). Also includes the iterator of
40
* the previous state (which iterator is the previous state in relation
41
* to all states in the last position
42
*/
43
struct
stoch_value
{
44
stoch_value
(uint16_t
id
, uint16_t prev,
float
p):
state_id
(id),
state_prev
(prev),
prob
(p){}
45
uint16_t
state_id
;
46
uint16_t
state_prev
;
47
uint16_t
prev_cell
;
48
float
prob
;
49
};
50
51
52
stochTable
(
size_t
);
53
~stochTable
();
54
void
push
(
size_t
pos,
size_t
st,
size_t
st_to,
float
val);
55
std::string
stringify
();
56
void
print
();
57
void
finalize
();
58
size_t
get_state_position
(
size_t
pos,uint16_t);
59
60
void
traceback
(
traceback_path
& path);
61
62
private
:
63
size_t
last_position
;
64
std::vector<stoch_value>*
state_val
;
65
std::vector<size_t>*
position
;
66
};
67
68
69
70
// //Alternate StochTable using sparseArray
71
// class alt_stochTable{
72
// public:
73
// struct stoch_val{
74
// stoch_val(uint16_t prev, float p): previous_state(prev), prob(p){}
75
// uint16_t previous_state;
76
// float prob;
77
// };
78
//
79
// alt_stochTable(size_t states, size_t seq_length);
80
// ~alt_stochTable();
81
//
82
// void push(size_t pos, size_t st, size_t st_to, float val);
83
// void push_ending(size_t st_to,float val);
84
// void traceback(traceback_path& path);
85
// void finalize();
86
// std::string stringify();
87
// void print();
88
//
89
// private:
90
// size_t states;
91
// size_t seq_length;
92
// std::vector< sparseArray<std::vector<stoch_val> > >* table;
93
// std::vector<stoch_val> ending;
94
//
95
// };
96
97
class
alt_simple_stochTable
{
98
public
:
99
struct
stoch_val
{
100
stoch_val
(uint16_t prev,
float
p):
previous_state
(prev),
prob
(p){}
101
uint16_t
previous_state
;
102
float
prob
;
103
};
104
105
alt_simple_stochTable
(
size_t
states
,
size_t
seq_length
);
106
~alt_simple_stochTable
();
107
108
void
push
(
size_t
pos,
size_t
st,
size_t
st_to,
float
val);
109
void
push_ending
(
size_t
st_to,
float
val);
110
void
traceback
(
traceback_path
& path);
111
void
finalize
();
112
std::string
stringify
();
113
void
print
();
114
115
private
:
116
size_t
states
;
117
size_t
seq_length
;
118
std::vector<std::vector<std::vector<stoch_val> > >*
table
;
119
std::vector<stoch_val>
ending
;
120
};
121
122
123
124
}
125
126
#endif
/* defined(__StochHMM__stoch_table__) */
Generated on Tue Jul 30 2013 13:23:12 for StochHMM by
1.8.1