I have a complete weighted graph as you can see in the image below:
The Goal: My goal is to be able to choose the number of clusters and the number of vertices in each cluster using python's implementation of iGraph
What I've Tried So Far:
import igraph
import cairo
import numpy as np
# Import data (see below, I've included this file)
graph2 = igraph.Graph.Read_Ncol('10_graph.ncol')
# Assigns weights to weights1
weights1 = graph2.es["weight"]
# Converts it to undirected graph
graph2.to_undirected()
# 'graph2.to_undirected()' strips the graph of its weights
# so we restore them to the "weight" attribute after
graph2.es["weight"] = weights1
# Reduces the number of significant figures in each edge label
graph2.es["label"] = np.around(weights1, 2)
# Label all the vertices
graph2.vs["label"] = range(1, 11)
# Things I've tried: (uncomment only one at a time)
# Both return non-clustered graphs.
#community = graph2.community_spinglass(weights1)
community = graph2.community_leading_eigenvector(weights=graph2.es["weight"], clusters=3)
igraph.plot(community)
If the above code is run, you get as output the above image. You get the same image for both community-finding algorithms I've included. I've commented out one of them, so if you want to use the other one, go ahead and uncomment #community = graph2.community_spinglass(weights1)
.
The Problem(s):
- It looks like none of the graphs are being clustered the way I want them to.
- I pass
weights=graph2.es["weight"]
, the list of weights corresponding the vertices in the graph. - I also explicitly pass
clusters=3
tocommunity_leading_eigenvector()
- I am still not getting any clustering based on the edge weights of this graph.
- How to draw proper clusters, either by color, or location, or however iGraph handles differentiation of clusters?
- I pass
- I am unable to find any official documentation about how to choose the number of vertices in each cluster.
- Is there a way (even roundabout) to choose the number of vertices in each cluster? It doesn't have to be exact, but approximate.
10_graph.ncol
Here's the .ncol file I import to form the graph.
10_graph.ncol =
0 1 0.859412093436
0 2 0.696674188289
0 3 0.588339776278
0 4 0.5104097013
0 5 0.462457938906
0 6 0.427462387255
0 7 0.40350595007
0 8 0.382509071902
0 9 0.358689934558
1 2 0.912797848896
1 3 0.78532402562
1 4 0.681472223562
1 5 0.615574694967
1 6 0.567507619872
1 7 0.534715438785
1 8 0.506595029246
1 9 0.474297090248
2 3 0.941218154026
2 4 0.83850483835
2 5 0.759542327211
2 6 0.70025846718
2 7 0.659110815342
2 8 0.624313042633
2 9 0.584580479234
3 4 0.957468322138
3 5 0.886571688707
3 6 0.821838040975
3 7 0.772665012468
3 8 0.730820137423
3 9 0.684372167781
4 5 0.97372551117
4 6 0.92168855187
4 7 0.870589109091
4 8 0.823583870451
4 9 0.772154420843
5 6 0.98093419661
5 7 0.941236624882
5 8 0.895874086289
5 9 0.843755656833
6 7 0.985707938753
6 8 0.9523988462
6 9 0.906031710578
7 8 0.988193527182
7 9 0.955898136286
8 9 0.988293873257