用于 add_edge() 方法的 python netwokx 权重归一化

问题描述

我使用 networkx 来构建推荐图。我使用此代码将节点和边添加到图中,使用从文件中读取的推荐数据:

self.driver.find_element_by_xpath("((//span[@class='bog'])[2])").click()

其中 ustr、cstr、istr 和 t 是从文件(数据集)中读取的推荐数据。

当我尝试绘制具有关联权重的边时:export const postFeedback = (firstname,lastname,telnum,email,agree,contactType,message) => (dispatch) => { const Feedback = { firstname: firstname,lastname: lastname,telnum: telnum,email: email,agree: agree,contactType: contactType,message: message } //Feedback.date = new Date().toISOString(); //Feedback.id = new id().toISOString(); return fetch(baseUrl + 'Feedback',{ method: 'POST',body: JSON.stringify(Feedback),headers: { 'Content-Type': 'application/json' },credentials: 'same-origin' }) .then(response => { if (response.ok) { return response; } else { var error = new Error('Error' + response.status + ': ' + response.statusText); error.response = response; throw error; } },error => { var errmess = new Error(error.message); throw errmess; }) .then(response => response.json()) .then((res)=>alert('Your data posted\n: ' + res.id )) .catch(error => { console.log('Error while posting data',error.message); alert('Error while posting data: \nError' + error.message); }); 我得到了这个结果:

graph = networkx.Digraph()

graph.add_node(ustr,node_type='u')
graph.add_node(istr,node_type='i')
graph.add_node(cstr,node_type='c')
graph.add_edge(ustr,istr,weight=1,w_init=1,time=t)
graph.add_edge(istr,ustr,time=t)
graph.add_edge(cstr,cstr,time=t)
graph.add_edge(ustr,time=t)

当我用很少的节点和边样本手动尝试时,所有权重都有 1 作为值,如 graph.edges(data='weight',default=1) 方法中指定的那样。

所以我想了解为什么权重没有像指定的那样设置为 1? networkx 是否有任何方法或公式来计算这些权重值?

完整代码在这里Github code of the project

提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)