我正在尝试在Mac osx上使用python 2.7的ghmm python模块。我已经成功安装了所有东西,并且可以在python环境中导入ghmm,但是我运行它时(从ghmm'tutorial')出现错误(可以在http://ghmm.sourceforge.net/UnfairCasino.py中找到UnfairCasino):
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。程序不好,不好!没有适合您的Cookie。
python(52313,0x7fff70940cc0)malloc:*对象0x74706d6574744120错误:未分配指针
*在malloc_error_break中设置一个断点进行调试
中止陷阱
当我将ghmm.py记录器设置为“ DEBUG”时,该日志将立即打印出以下内容:
GHMM ghmm.py:2333-HMM.viterbi()-开始
GHMM ghmm.py:849-EmissionSequence.asSequenceSet()-开始>
GHMM ghmm.py:862-EmissionSequence.asSequenceSet()-结束>
追溯(最近一次通话):
发射文件“ /Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/logging/init.py”,第842行
msg = self.format(记录)
文件“ /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()
getMessage中的文件“ /Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/logging/init.py”,第328行
味精=味精%self.args
TypeError:在字符串格式化期间并非所有参数都已转换
从文件ghmm.py登录,行1159
追溯(最近一次通话):
发射文件“ /Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/logging/init.py”,第842行
msg = self.format(记录)
文件“ /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()
getMessage中的文件“ /Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/logging/init.py”,第328行
味精=味精%self.args
TypeError:在字符串格式化期间并非所有参数都已转换
从文件ghmm.py,第949行记录
GHMM ghmm.py:2354-HMM.viterbi()-结束
GHMM ghmm.py:1167-del SequenceSubSet>
因此,我怀疑这与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项目看起来有点死了,但是希望这足够简单,可以帮助任何在困境中使用该库的人。
关于python - GHMM-在NULL指针上尝试了m_free,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12163086/