调用马尔可夫链时出错

时间:2018-04-25 04:13:12

标签: python

我正在开发一个调用马尔可夫链模块的项目。我已经删除了数据并编写了一个基本的文本生成文件,但是一直收到我不理解的错误。我的代码如下:

from markov_python.cc_markov import MarkovChain

mc = MarkovChain()
mc.add_file('C:\EclipseWorkspaces\csse120\markov_chain\src\lyrics.txt')
mc.add_string('shape')

print mc.generate_text(10) 

我得到的错误是:

Traceback (most recent call last):
  File "C:\EclipseWorkspaces\csse120\markov_chain\src\run.py", line 14, in <module>
    print mc.generate_text(10) 
  File "C:\EclipseWorkspaces\csse120\markov_chain\src\markov_python\cc_markov.py", line 61, in generate_text
    idx = random.randint(0, len(self.lookup_dict)-1)
  File "C:\Python27\lib\random.py", line 244, in randint
    return self.randrange(a, b+1)
  File "C:\Python27\lib\random.py", line 220, in randrange
    raise ValueError, "empty range for randrange() (%d,%d, %d)" % (istart, istop, width)
ValueError: empty range for randrange() (0,0, 0)

以下是它回拨的代码:

def generate_text(self, max_length=20):
    context = deque()
    output = []
    if len(self.lookup_dict) > 0:
        self.__seed_me(rand_seed=len(self.lookup_dict))

    idx = random.randint(0, len(self.lookup_dict)-1)
    chain_head = list(self.lookup_dict.keys()[idx])
    context.extend(chain_head)

不确定该怎么做。请指教。

0 个答案:

没有答案