taynaud / python-louvain

Louvain Community Detection
BSD 3-Clause "New" or "Revised" License
965 stars 200 forks source link

`best_partition` `weight` cannot be set to `None`, but `"None"` #73

Closed ma-ji closed 3 years ago

ma-ji commented 4 years ago

I need the algorithm to take the graph as unweighted, but the weight parameter cannot be set to None, only string is accepted. I'm currently set as "None" and it works. But probably improvements can be made in the source codes?

~/anaconda3/envs/py36/lib/python3.6/site-packages/community/community_louvain.py in best_partition(graph, partition, weight, resolution, randomize, random_state)
    247                                 resolution,
    248                                 randomize,
--> 249                                 random_state)
    250     return partition_at_level(dendo, len(dendo) - 1)
    251 

~/anaconda3/envs/py36/lib/python3.6/site-packages/community/community_louvain.py in generate_dendrogram(graph, part_init, weight, resolution, randomize, random_state)
    350     status_list.append(partition)
    351     mod = new_mod
--> 352     current_graph = induced_graph(partition, current_graph, weight)
    353     status.init(current_graph, weight)
    354 

~/anaconda3/envs/py36/lib/python3.6/site-packages/community/community_louvain.py in induced_graph(partition, graph, weight)
    409         com2 = partition[node2]
    410         w_prec = ret.get_edge_data(com1, com2, {weight: 0}).get(weight, 1)
--> 411         ret.add_edge(com1, com2, **{weight: w_prec + edge_weight})
    412 
    413     return ret

TypeError: add_edge() keywords must be strings
aj-cmsc commented 4 years ago

how modularity value is calculated for unweighted graph?

ma-ji commented 4 years ago

how modularity value is calculated for unweighted graph?

Just set all weights to 1?

taynaud commented 3 years ago

Hello, for unweighted graphs, all weights are assumed to be 1. In fact if you specify a weight key which does not exist, all weights are assumed to be 1. Even if one specific link have no weight set it will be 1.

aj-cmsc commented 3 years ago

Thanks for your reply

On Sun, 27 Dec, 2020, 9:20 PM Thomas Aynaud, notifications@github.com wrote:

Hello, for unweighted graphs, all weights are assumed to be 1. In fact if you specify a weight key which does not exist, all weights are assumed to be 1. Even if one specific link have no weight set it will be 1.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/taynaud/python-louvain/issues/73#issuecomment-751483227, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANB2WCONH6MVBBTDECG4ICLSW5JTVANCNFSM4T4I3YVQ .