问题描述
我正在使用 NDlib 尝试对图上的独立级联扩散过程进行建模。我正在尝试使用 config.add_model_parameter('Infected',{0,10,100})
设置一些初始种子节点(此时我的其余代码与找到的教程示例 here 相同)但是当我收到错误 UserWarning: Initial infection missing: a random sample of 5% of graph nodes will be set as infected warnings.warn('Initial infection missing: a random sample of 5% of graph nodes will be set as infected')
然后运行 model.set_initial_status(config)
行。我不确定这是如何发生的,因为在链接的文档中它说可以通过两个选项定义初始感染状态,第一个选项是教程中使用的选项,第二个是我试图指定的选项。有谁知道为什么它似乎无法识别我的初始种子节点?
我使用的完整代码是这样的:
g = nx.erdos_renyi_graph(1000,0.05,seed=1)
model = ep.IndependentCascadesModel(g)
config = mc.Configuration()
# config.add_model_parameter('fraction_infected',0)
config.add_model_parameter('Infected',100})
threshold = 0.01
for e in g.edges():
config.add_edge_configuration("threshold",e,threshold)
model.set_initial_status(config) # this line triggers the warning
解决方法
对于 ndlib,你应该使用 add_model_initial_configuration
而不是 add_model_parameter
,请看这个例子:https://ndlib.readthedocs.io/en/latest/reference/mconf/Mconf.html#status-configuration