StochHMM  v0.34
Flexible Hidden Markov Model C++ Library and Application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Private Attributes
StochHMM::alt_simple_stochTable Class Reference

#include <stochTable.h>

List of all members.

Classes

struct  stoch_val

Public Member Functions

 alt_simple_stochTable (size_t states, size_t seq_length)
 ~alt_simple_stochTable ()
void push (size_t pos, size_t st, size_t st_to, float val)
void push_ending (size_t st_to, float val)
void traceback (traceback_path &path)
void finalize ()
std::string stringify ()
void print ()

Private Attributes

size_t states
size_t seq_length
std::vector< std::vector
< std::vector< stoch_val > > > * 
table
std::vector< stoch_valending

Detailed Description

Definition at line 97 of file stochTable.h.


Constructor & Destructor Documentation

StochHMM::alt_simple_stochTable::alt_simple_stochTable ( size_t  states,
size_t  seq_length 
)

Definition at line 353 of file stochTable.cpp.

References seq_length, and states.

: states(st), seq_length(length){
table = new (std::nothrow) std::vector<std::vector<std::vector<stoch_val> > > ;
table->resize(seq_length,std::vector<std::vector<stoch_val> > (states, std::vector<stoch_val>()));
}
StochHMM::alt_simple_stochTable::~alt_simple_stochTable ( )

Definition at line 358 of file stochTable.cpp.

References table.

{
delete table;
}

Member Function Documentation

void StochHMM::alt_simple_stochTable::finalize ( )

Finalized stochTable Normalizes the traceback pointer values and calculates the previous cell iterator within the previous position segment. This speeds up the the referencing necessary for tracebacks across the traceback table.

Definition at line 376 of file stochTable.cpp.

References StochHMM::addLog(), ending, seq_length, and states.

Referenced by StochHMM::trellis::simple_simple_stochastic_viterbi().

{
double sum(-INFINITY);
//For each position in the sequence we want to normalize the viterbi/forward values
//for the state from previous states
for(size_t position=0; position < seq_length;++position){
for(size_t state=0; state < states; ++state){
if ((*table)[position][state].size() > 0 ){
sum = -INFINITY;
for(size_t value=0; value < (*table)[position][state].size(); value++){
sum = addLog(sum,(double) (*table)[position][state][value].prob);
}
for(size_t value=0; value < (*table)[position][state].size();value++){
(*table)[position][state][value].prob = exp((*table)[position][state][value].prob-sum);
}
}
}
}
sum = -INFINITY;
for(size_t i=0;i<ending.size();i++){
sum = addLog(sum,(double) ending[i].prob);
}
for(size_t i=0;i<ending.size();i++){
ending[i].prob=exp(ending[i].prob-sum);
}
return;
}
void StochHMM::alt_simple_stochTable::print ( )

Definition at line 464 of file stochTable.cpp.

References stringify().

{
std::cout << stringify() << std::endl;
return;
}
void StochHMM::alt_simple_stochTable::push ( size_t  pos,
size_t  st,
size_t  st_to,
float  val 
)

Definition at line 362 of file stochTable.cpp.

Referenced by StochHMM::trellis::simple_simple_stochastic_viterbi().

{
(*table)[pos][state].push_back(stoch_val(state_to,val));
return;
}
void StochHMM::alt_simple_stochTable::push_ending ( size_t  st_to,
float  val 
)

Definition at line 367 of file stochTable.cpp.

References ending.

Referenced by StochHMM::trellis::simple_simple_stochastic_viterbi().

{
ending.push_back(stoch_val(state_to,val));
return;
}
std::string StochHMM::alt_simple_stochTable::stringify ( )

Definition at line 448 of file stochTable.cpp.

References seq_length, and states.

Referenced by print().

{
std::stringstream str;
for(size_t position = 0; position < seq_length-1; position++){
str << position ;
for(size_t state = 0; state < states; state++){
for (size_t val = 0; val < (*table)[position][state].size();val++){
str << "\t" << state << ":" << (*table)[position][state][val].previous_state << " : " << (*table)[position][state][val].prob ;
}
}
str << "\n";
}
return str.str();
}
void StochHMM::alt_simple_stochTable::traceback ( traceback_path path)

Traceback through the table using the traceback probabilities

Parameters:
[out]pathReference to traceback_path

Definition at line 412 of file stochTable.cpp.

References ending, StochHMM::traceback_path::push_back(), SIZE_MAX, and UINT16_MAX.

{
double random((double)rand()/((double)(RAND_MAX)+(double)(1)));
double cumulative_prob(0.0);
uint16_t state_prev(UINT16_MAX);
//Get traceback from END state
for(size_t i = 0; i< ending.size(); ++i){
cumulative_prob += (ending)[i].prob;
if (random <= cumulative_prob){
state_prev = ending[i].previous_state;
path.push_back(state_prev);
break;
}
}
//For the rest of the table traceback to the beginning of the sequence
for(size_t position = table[state_prev].size()-1; position != SIZE_MAX ; --position){
random = (double)rand()/((double)(RAND_MAX)+(double)(1));
cumulative_prob = 0;
for (size_t st = 0; st < (*table)[position][state_prev].size(); st++){
cumulative_prob+=(*table)[position][state_prev][st].prob;
if (random <= cumulative_prob){
state_prev = (*table)[position][state_prev][st].previous_state;
path.push_back(state_prev);
break;
}
}
}
return;
}

Member Data Documentation

std::vector<stoch_val> StochHMM::alt_simple_stochTable::ending
private

Definition at line 119 of file stochTable.h.

Referenced by finalize(), push_ending(), and traceback().

size_t StochHMM::alt_simple_stochTable::seq_length
private

Definition at line 117 of file stochTable.h.

Referenced by alt_simple_stochTable(), finalize(), and stringify().

size_t StochHMM::alt_simple_stochTable::states
private

Definition at line 116 of file stochTable.h.

Referenced by alt_simple_stochTable(), finalize(), and stringify().

std::vector<std::vector<std::vector<stoch_val> > >* StochHMM::alt_simple_stochTable::table
private

Definition at line 118 of file stochTable.h.

Referenced by ~alt_simple_stochTable().


The documentation for this class was generated from the following files: