我正试图在mac-osx上使用ghmm-python模块和python 2.7。我已经成功地安装了所有的东西,并且我可以在python环境中导入ghmm,但当我运行这个程序时(从ghmm"教程"中)会出现错误(UnfairCasino可以在这里找到http://ghmm.sourceforge.net/UnfairCasino.py):
from ghmm import *
from UnfairCasino import test_seq
sigma = IntegerRange(1,7)
A = [[0.9, 0.1], [0.3, 0.7]]
efair = [1.0 / 6] * 6
eloaded = [3.0 / 13, 3.0 / 13, 2.0 / 13, 2.0 / 13, 2.0 / 13, 1.0 / 13]
B = [efair, eloaded]
pi = [0.5] * 2
m = HMMFromMatrices(sigma, DiscreteDistribution(sigma), A, B, pi)
v = m.viterbi(test_seq)
具体来说,我得到了这个错误:
GHMM GHMM.py:148-sequence.c:GHMM_dseq_free(1199):在NULL指针上尝试m_free。糟糕的程序,糟糕!没有饼干给你。python(52313,0x7fff70940cc0)malloc:*对象0x74706d6574744120的错误:未分配释放的指针*在malloc_error_break中设置断点进行调试中止陷阱
当我将ghmm.py记录器设置为"DEBUG"时,日志会在之前打印出以下内容:
GHMM GHMM.py:2333-HMM.viterbi()-开始
GHMM GHMM.py:849-EmissionSequence.asSequenceSet()--beging>
GHMM GHMM.py:862-发射序列.asSequenceSet()--end>
追踪(最近一次通话):
文件"/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/logging/init.py",第842行,在发射中
msg=自身格式(记录)
文件"/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/logging/init.py",第719行,格式为
返回fmt.format(记录)
文件"/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/logging/init.py",第464行,格式为
record.message=record.getMessage()
文件"/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/logging/init.py",第328行,在getMessage 中
msg=msg%self.args
TypeError:在字符串格式化期间,并非所有参数都已转换
从文件ghmm.py第1159行记录
追踪(最近一次通话):
文件"/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/logging/init.py",第842行,在发射中
msg=自身格式(记录)
文件"/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/logging/init.py",第719行,格式为
返回fmt.format(记录)
文件"/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/logging/init.py",第464行,格式为
record.message=record.getMessage()
文件"/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/logging/init.py",第328行,在getMessage 中
msg=msg%self.args
TypeError:在字符串格式化期间,并非所有参数都已转换
从文件ghmm.py第949行记录
GHMM GHMM.py:2354-HMM.viterbi()-结束
GHMM GHMM.py:1167-del序列子集>
因此,我怀疑这与Viterbi函数完成后删除序列的方式有关,但我不确定这是否意味着我需要修改Python代码、C代码,或者我是否需要以不同的方式编译ghmm和包装器。任何帮助/建议都将不胜感激,因为我在过去的4天里一直在努力让这个图书馆工作。
考虑到这个问题的年龄,你可能已经转向了其他问题,但这似乎是我发现的唯一相关的结果。问题是,由于python函数"EmissionSequence::asSequenceSet"的执行方式有些奇怪,因此正在发生双重释放。如果你看看ghmm.py是如何实现的(第845-863行)
def asSequenceSet(self):
"""
@returns this EmissionSequence as a one element SequenceSet
"""
log.debug("EmissionSequence.asSequenceSet() -- begin " + repr(self.cseq))
seq = self.sequenceAllocationFunction(1)
# checking for state labels in the source C sequence struct
if self.emissionDomain.CDataType == "int" and self.cseq.state_labels is not None:
log.debug("EmissionSequence.asSequenceSet() -- found labels !")
seq.calloc_state_labels()
self.cseq.copyStateLabel(0, seq, 0)
seq.setLength(0, self.cseq.getLength(0))
seq.setSequence(0, self.cseq.getSequence(0))
seq.setWeight(0, self.cseq.getWeight(0))
log.debug("EmissionSequence.asSequenceSet() -- end " + repr(seq))
return SequenceSetSubset(self.emissionDomain, seq, self)
这可能会引发一些危险信号,因为它似乎有点深入C(我不确定,我还没有深入研究)。
无论如何,如果你稍微看一下这个函数,还有另一个叫做"sequenceSet"的函数:
def sequenceSet(self):
"""
@return a one-element SequenceSet with this sequence.
"""
# in order to copy the sequence in 'self', we first create an empty SequenceSet and then
# add 'self'
seqSet = SequenceSet(self.emissionDomain, [])
seqSet.cseq.add(self.cseq)
return seqSet
它似乎有着相同的目的,但实施方式不同。无论如何,如果您将ghmm.py中的"EmissionSequence::asSequenceSet"的主体替换为:
def asSequenceSet(self):
"""
@returns this EmissionSequence as a one element SequenceSet
"""
return self.sequenceSet();
然后重建/重新安装ghmm模块,代码将在不崩溃的情况下运行,您应该能够继续您的快乐之路。我不确定这是否可以作为修复程序提交,因为ghmm项目看起来有点死了,但希望这足够简单,可以帮助任何处于困境的人使用这个库。