图形工具推理的属性错误

2024-04-19 23:58:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Python图形工具库对图形进行一些推断,我引用了下面的链接,其中显示了API和一些示例。 https://graph-tool.skewed.de/static/doc/inference.html#graph_tool.inference.BlockState

我的代码如下所示,其中g是在上一步中定义的有向边加权图。你知道吗

g.save(graph_file_name)
g = graph_tool.load_graph(file_name)
state = BlockState(g, B=276, deg_corr = True)
pv = None
state.mcmc_sweep(niter=1000)
for i in range(1000):
    ds, nmoves = state.mcmc_sweep(niter=10)
    pv = state.collect_vertex_marginals(pv)
pv = state.collect_vertex_marginals(pv)
print mf_entropy(g, pv)

graph_draw(g)

根据API,BlockState构造函数应该返回一个BlockState obj,其函数有collect\u vertex\u marginals和mcmc\u sweep()。但是,我得到以下错误:

AttributeError: 'BlockState' object has no attribute 'mcmc_sweep'

我只是忽略了什么吗?我没有看到任何版本问题(例如,过时的API),所以我有点迷惑。谢谢!你知道吗


Tags: nameapi图形toolfilegraphvertexcollect