Weighted clustering coefficient

Hi,

I have been trying to calculate both the global and local clustering coefficients for a weighted network. Based on the documentation and a few previous discussions in the forum, it appears that the weighted clustering coefficient should be in the range of [0,1], right? However, what I get is always > 1. Could anyone help clarify?

A sample network is attached (it is already a simple undirected network):
sample.csv (33.7 KB)

And here is the code I used:

df_edgelist = pd.read_csv('sample.csv')
# normalize edge weight (which is the S000 column) according to the documentation
df_min_max_scaled = df_edgelist.copy() 
column = 'S000'
df_min_max_scaled[column] = (df_min_max_scaled[column] - df_min_max_scaled[column].min()) / (df_min_max_scaled[column].max() - df_min_max_scaled[column].min())     

# create a graph and calculate clustering coefficient        
g = Graph(directed=False)
ep_flow = g.new_ep("float") # define a new edge property map representing normalized edge weight
ep_dist = g.new_ep("float")
vp_name = g.new_vp("int")
vp_name = g.add_edge_list(df_min_max_scaled.to_numpy(), hashed=True, eprops=[ep_flow, ep_dist]) 

c_w, num_tria_w, num_triples_w = global_clustering(g, weight = ep_flow, ret_counts=True)
gcc_w = c_w[0]

The code for calculating local clustering coefficient is very similar.

Another question is that how is local clustering coefficient calculated for weighted networks? It is not clearly defined in the documentation. However, it was clearly documented for the global clustering coefficient.

Thank you!

Hi, this is a bug! Thanks for spotting it! I have fixed it now in the newest git version.

Hi Tiago,

Thanks for the quick fix. Just to clarify. I typically simply install graph-tool using conda. You said you updated the newest git version. How do I get that? A simple conda install would work as well?

A follow up question is how local clustering coefficient is calculated for weighted networks. I do not see much description in the documentation.

Many thanks!

You need to wait until a new release is made, but I just pushed one last night which is already available in conda. So you need only to upgrade.

I’ve also updated the documentation to explain how the weighted local clustering is computed: local_clustering — graph-tool 2.65 documentation