I am trying to detect the communities in a temporal network, that is, i want to detect communities at different time stamp and for that I am using Dataframe for filtering the data according to time.
For time, t=0, i want to plot the graph, I am using matplotlib for this purpose and also I am using igraph for the algorithms.
However, if I have n edges it is using 2n nodes when nodes are few. When I try to take only the unique vertices, it is showing the error vertex id invalid and if I let the code take 2n nodes then it is taking the vertices not even there in the time stamp. The graph formed is not meaningful as well
Related
I have a list of cities (nodes) plotted in a 2D plane each given by an X,Y coordinate.
I now want to add roads (edges) to it, but the roads cannot intersect. I want to create the most number of roads possible. By count, not by total length.
In more general graph theory parlance, I think I want the maximum number of edges (or regions?? maybe it's the same thing), where edges do not intersect in 2-dimensions, for a given set of Nodes at X,Y points.
In a brief view of NetworkX, it seems that they generate Graphs by making "nodes" but nodes can be "anywhere" and cannot force nodes to be at a certain location with respect to each other (they have abstracted too far!).
Edit: networkx add_node with specific position
suggests that you can plot them in a given location. #Stef thanks!!
Am i thinking about the problem correctly?
Can I visualize using some python package my Nodes/edges, where this package can automatically calculate the proper edges given a set of nodes?
Is automatically finding the maximum number of non-intersecting edges a thing (and what is this called so I can find out more about it?)
Very possibly similar to this question, but this question wasn't really answered and from 8 years ago (Algorithm for finding minimal cycle basis of planar graph)
I have two separate lists of nodes and stations. Each list consists of Node (or station) ID, x-coordinate, and y-coordinate. I pick up a random set of nodes and connect them to generate a graph network using NetworkX based on a certain distance between them. I select a random set of stations. I have shared the data and code at Data and Code
Now, I want to extend the graph network in a way that each edge should be within a certain distance from the station. I want to keep the shape (topology) of the initial network as it is but want to zoom (or scale/extend) the network to make it close to the stations. I am not sure how can I extend the graph to meet the aforementioned conditions/constraints. The stations can be regarded as forming an overlay network and the base network is being extended based on this overlay network. Here is a figure to show the desired network. Any help in this regard is very much appreciated.
Network Diagram
I am looking to generate a random planar graph in python with around 20 vertices. I checked out this planar graph generator but two problems emerged:
The algorithm on the aforementioned GitHub project seems a bit too overkill to generate a random planar graph that doesn’t have those many edges
Because it’s meant to generate massive graph, that algorithm is very complex, and therefore also a bit clunky and difficult to use
With that said, is there a simpler way to randomly generate a relatively small planar graph in python?
Create required number of nodes
Assign random x,y locations to the nodes.
WHILE nodes with no connected edges
Select N a random node with no edge
LOOP select M a different node at random
IF edge N-M does NOT intersect previous edges
Add N-M edge to graph
BREAK out of LOOP
I have a couple of NetworkX graphs that have similar structures but vastly different edge lengths.
First image:
Second Image:
Note that they both have clusters of 4 nodes that have very different edge lengths. Is this just a random occurrence or is there something significant to it? Note that red edges are pages, blue edges are students, and the edges represent views (If there is an edge between the nodes, that means the student viewed that page). Edges also have the number of views (frequency) encoded within them (Black is less than 5 views, Blue is more than 5 views)
There is no well-defined interpretation of the length of the edges.
The networkx default uses spring_layout. This attempts to find an arrangement which has closely connected nodes close together. It does this by effectively treating the nodes as repelling objects and the edges as springs. It starts with the nodes in random locations and then lets them move around according to these assumptions.
I'm trying to draw a networkx graph with weighted edges, but right now I'm having some difficulty.
As the title suggests, this graph is really huge:
Number of Nodes: 103362
Number of Edges: 1419671
And when I try to draw this graph with the following code:
pos = nx.spring_layout(G)
nx.draw(G, node_color='#A0CBE2',edge_color='#BB0000',width=2,edge_cmap=plt.cm.Blues,with_labels=False)
plt.savefig("edge_colormap.png") # save as png
plt.show() # display
(This is just me testing functionality, not my desired end result). I get the error:
ValueError: array is too big.
It's triggered from the spring_layout algorithm. Any idea what's causing this? Even when I use a different pos algorithm I get the same error, how can I avoid it (if I can)?
On another note, I want to colour the edges based on their weight. As you can see there are a lot of edges and probably a wide range of weights, what is the best way to do this?
Thanks for your patience.
EDIT FROM MY COMMENT:
I'm trying to investigate the density of the data I have. Basically I am looking at 50,000 matches each containing 10 players, and whenever two players meet in a game I +1 to the weight of the edge between them. The idea is that my end result will show me the strength of my data set. In my mind I want the heaviest edges at the centre and as we move out from the centre the data is less densely connected.
The problem lies in the spring_layout approach. With this many nodes it will take a while to calculate where all of them should go with respect to one another. With this many nodes I would suggest either figuring out the x,y positions yourself or plot much smaller subgraphs. (<5000 nodes or your computer might be a bit sluggish for a while.
Here is what 1000 nodes from an erdos_renyi_graph (randomly chosen edges) looks like.
It pulled off 2 nodes to highlight.
Next is what 1500 looks like
It got a little more detail. Now with 7-8 interesting nodes.
There isn't much to be gained by so many edges and so many nodes on a graph. And what happens if you don't like the output, you would need to re-run it again.
To get x,y positions of each node take a look at this. in NetworkX show graph with nodes at exact (x,y) position. Result is rotated