我试图了解C ++与python的接口:
第170行的g2p.py中有以下代码(为清楚起见已清除):
nBest = translator.nBestInit(left)
logLik, result = translator.nBestNext(nBest)
posterior = math.exp(logLik - nBest.logLikTotal) // ***This is the line in question***
print('%f' % (posterior))
使用第759行的sequitur.py:
def nBestInit(self, left):
left = self.sequitur.leftInventory.parse(left)
result = self.translator.nBestInit(left)
result.thisown = True
result.logLikBest = self.translator.nBestBestLogLik(result)
result.logLikTotal = self.translator.nBestTotalLogLik(result)
return result
def nBestNext(self, nBestContext):
logLik, joint = self.translator.nBestNext(nBestContext)
joint = self.unpackJoint(joint)
left, right = self.jointToLeftRight(joint)
return logLik, right
在此脚本中,LogLik在Probability.hh和翻译器函数中定义
在Translation.cc中。 nBestTotalLogLik
和nBestNext
都返回类类型LogProbability
。 LogProbability
有各种重载,均不会返回数值类型,例如:
inline LogProbability operator-(const LogProbability &lhs, const LogProbability &rhs)
我的问题是,在math.exp(logLik - nBest.logLikTotal)
行中,如何将表达式logLik - nBest.logLikTotal
评估为数值以供exp()处理?