本文整理汇总了C++中Arc::get_word方法的典型用法代码示例。如果您正苦于以下问题:C++ Arc::get_word方法的具体用法?C++ Arc::get_word怎么用?C++ Arc::get_word使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arc
的用法示例。
在下文中一共展示了Arc::get_word方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: viterbi_backtrace
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **
* Routine for Viterbi backtrace.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
double viterbi_backtrace(const Graph& graph, matrix<VitCell>& chart,
vector<int>& outLabelList, bool doAlign)
{
int frmCnt = chart.size1() - 1;
int stateCnt = chart.size2();
// Find best final state.
vector<int> finalStates;
int finalCnt = graph.get_final_state_list(finalStates);
double bestLogProb = g_zeroLogProb;
int bestFinalState = -1;
for (int finalIdx = 0; finalIdx < finalCnt; ++finalIdx)
{
int stateIdx = finalStates[finalIdx];
if (chart(frmCnt, stateIdx).get_log_prob() == g_zeroLogProb)
continue;
double curLogProb = chart(frmCnt, stateIdx).get_log_prob() +
graph.get_final_log_prob(stateIdx);
if (curLogProb > bestLogProb)
bestLogProb = curLogProb, bestFinalState = stateIdx;
}
if (bestFinalState < 0)
throw runtime_error("No complete paths found.");
// Do backtrace, collect appropriate labels.
outLabelList.clear();
int stateIdx = bestFinalState;
for (int frmIdx = frmCnt; --frmIdx >= 0; )
{
assert((stateIdx >= 0) && (stateIdx < stateCnt));
int arcId = chart(frmIdx + 1, stateIdx).get_arc_id();
Arc arc;
graph.get_arc(arcId, arc);
assert((int) arc.get_dst_state() == stateIdx);
if (doAlign)
{
if (arc.get_gmm() < 0)
throw runtime_error("Expect all arcs to have GMM.");
outLabelList.push_back(arc.get_gmm());
}
else if (arc.get_word() > 0)
outLabelList.push_back(arc.get_word());
stateIdx = graph.get_src_state(arcId);
}
if (stateIdx != graph.get_start_state())
throw runtime_error("Backtrace does not end at start state.");
reverse(outLabelList.begin(), outLabelList.end());
return bestLogProb;
}