當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python cugraph.link_prediction.woverlap.overlap_w用法及代碼示例

用法:

cugraph.link_prediction.woverlap.overlap_w(input_graph, weights, vertex_pair=None)

計算由邊連接的每對頂點之間或用戶指定的任意頂點對之間的加權重疊係數。重疊係數定義為兩組之間的交集體積除以它們中較小的體積的比率。在圖的上下文中,頂點的鄰域被視為一個集合。每條邊的重疊係數權重表示基於相鄰頂點的相對相似性的頂點之間的連接強度。如果指定了第一個但沒有指定第二個,反之亦然,將拋出異常。

參數

input_graphcugraph.Graph

cuGraph 圖形實例,應包含作為邊列表的連接信息(此算法不使用邊權重)。如果不存在鄰接列表,則將計算該鄰接列表。

weightscudf.DataFrame

指定要用於每個頂點的權重。頂點應由multi-column 頂點的多列表示。

權重[‘vertex’]cudf.Series

包含頂點標識符

權重[‘weight’]cudf.Series

包含頂點的權重

vertex_paircudf.DataFrame,可選(默認=無)

一個 GPU 數據幀,由代表頂點對的兩列組成。如果提供,則為給定的頂點對計算重疊係數,否則,為所有頂點對計算重疊係數。

返回

dfcudf.DataFrame

大小為 E(默認)的 GPU 數據幀或包含重疊係數的給定對(第一、第二)的大小。排序是相對於鄰接列表的,或者是由指定的頂點對給出的。

df[‘source’]cudf.Series

源頂點 ID

df[‘destination’]cudf.Series

目標頂點 ID

df[‘overlap_coeff’]cudf.Series

計算的源頂點和目標頂點之間的加權重疊係數。

例子

>>> import random
>>> M = cudf.read_csv(datasets_path / 'karate.csv', delimiter=' ',
...                   dtype=['int32', 'int32', 'float32'], header=None)
>>> G = cugraph.Graph()
>>> G.from_cudf_edgelist(M, source='0', destination='1')
>>> # Create a dataframe containing the vertices with their
>>> # corresponding weight
>>> weights = cudf.DataFrame()
>>> # Sample 10 random vertices from the graph and drop duplicates if
>>> # there are any to avoid duplicates vertices with different weight
>>> # value in the 'weights' dataframe
>>> weights['vertex'] = G.nodes().sample(n=10).drop_duplicates()
>>> # Reset the indices and drop the index column
>>> weights.reset_index(inplace=True, drop=True)
>>> # Create a weight column with random weights
>>> weights['weight'] = [random.random() for w in range(
...                      len(weights['vertex']))]
>>> df = cugraph.overlap_w(G, weights)

相關用法


注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cugraph.link_prediction.woverlap.overlap_w。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。