本文整理汇总了C++中Arc::get_log_prob方法的典型用法代码示例。如果您正苦于以下问题:C++ Arc::get_log_prob方法的具体用法?C++ Arc::get_log_prob怎么用?C++ Arc::get_log_prob使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arc
的用法示例。
在下文中一共展示了Arc::get_log_prob方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: viterbi
//.........这里部分代码省略.........
// Log probabilities should be base e, i.e., natural
// logarithms.
//
// Here is an example of the syntax for accessing a chart
// cell log prob:
//
// logProb = chart(frmIdx, stateIdx).get_log_prob();
//
// Here is an example of setting the contents of a chart cell:
//
// chart(frmIdx, stateIdx).assign(logProb, arcId);
//
// Fill in Viterbi algorithm here.
//
// The code for calculating the final probability and
// the best path is provided for you below.
// Start Viterbi algorithm
// Allocate a matrix for storing the log probability for the each current state giving the previous state
// G(cur_state,pre_state) = chart(frmIdx-1,pre_state)*transformpro*gmmProb
matrix<double> G;
G.resize(stateCnt,stateCnt);
for(int rowIndex=0; rowIndex<stateCnt; ++rowIndex)
for(int colIndex=0; colIndex<stateCnt; ++colIndex)
G(rowIndex,colIndex) = g_zeroLogProb;
vector<double> maxProb(stateCnt); // store the max value for each row of the G matrix
vector<int> maxIndex(stateCnt); // store the Index of the max element for each row of the G matrix
// Initialize start state i.e. chart(0,(0 .. stateCnt - 1))
for(int stateIdx=0; stateIdx<stateCnt; ++stateIdx)
if(stateIdx==graph.get_start_state())
chart(0,stateIdx).assign(0,-1);
else
chart(0,stateIdx).assign(g_zeroLogProb,-1);
// End
for(int frmIdx=0; frmIdx<frmCnt; ++frmIdx){
for(int stateIdx=0; stateIdx<stateCnt; ++stateIdx){
int arcCnt = graph.get_arc_count(stateIdx); // Get number of outgoing arcs for the stateIdx
int arcId = graph.get_first_arc_id(stateIdx); // Get arc ID of the first outgoing arc
for(int arcIdx=0; arcIdx<arcCnt;++arcIdx)
{
Arc arc;
arcId = graph.get_arc(arcId,arc);
int dstState = arc.get_dst_state(); // get the destination state of the stateIdx
double transProb = arc.get_log_prob();
int gmmId = arc.get_gmm();
double gmmProb = gmmProbs(frmIdx,gmmId);
G(dstState,stateIdx) = chart(frmIdx, stateIdx).get_log_prob() + transProb + gmmProb;
}
}
for(int curStaIdx=0; curStaIdx<stateCnt; ++curStaIdx){
maxProb[curStaIdx] = g_zeroLogProb;
maxIndex[curStaIdx] = -1;
for(int preStaIdx=0; preStaIdx<stateCnt; ++preStaIdx)
{
if(G(curStaIdx,preStaIdx) > maxProb[curStaIdx]){
maxProb[curStaIdx] = G(curStaIdx,preStaIdx);
int arcCnt = graph.get_arc_count(preStaIdx); // Get number of outgoing arcs for the stateIdx
int arcId = graph.get_first_arc_id(preStaIdx); // Get arc ID of the first outgoing arc
for(int arcIdx=0; arcIdx<arcCnt;++arcIdx)
{
Arc arc;
arcId = graph.get_arc(arcId,arc);
int dstState = arc.get_dst_state(); // get the destination state of the stateIdx
if(dstState==curStaIdx)
maxIndex[curStaIdx] = arcId-1;
}
}
}
}
// assign the chart(frmIdx+1,0 .. stateCnt - 1)
for(int stateIdx=0; stateIdx<stateCnt; ++stateIdx){
chart(frmIdx+1,stateIdx).assign(maxProb[stateIdx],maxIndex[stateIdx]);
}
// clear the matrix G and the vectors
for(int rowIndex=0; rowIndex<stateCnt; ++rowIndex)
for(int colIndex=0; colIndex<stateCnt; ++colIndex)
G(rowIndex,colIndex) = g_zeroLogProb;
for(int i=0; i<stateCnt; ++i){
maxProb[i] = g_zeroLogProb;
maxIndex[i] = -1;
}
}
// END_LAB
// The code for calculating the final probability and
// the best path is provided for you.
return viterbi_backtrace(graph, chart, outLabelList, doAlign);
}