scikit-tda / kepler-mapper

Kepler Mapper: A flexible Python implementation of the Mapper algorithm.
https://kepler-mapper.scikit-tda.org
MIT License
629 stars 182 forks source link

Idea - Convert networkx graph object or a graph in edge list format to a Mapper object #234

Open xgao32 opened 3 years ago

xgao32 commented 3 years ago

It would be nice if there is a way to turn a networkx graph or a graph in edge list format (something like a list of tuples (I,J,V) or a dataframe with 3 columns for the two vertices and edge weight) into a Mapper object.

I have a weighted graph and I would like to use Mapper to visualize the graph with different thresholds on the edge weights to determine when 2 vertices are connected.

sauln commented 3 years ago

Hey, that’s a great idea! I don’t think the implementation would be too tricky. Are you interested in giving it a shot? It would be a great first time contribution. I don’t have any bandwidth for this myself, but could help with reviews and releasing the changes once they’re implemented.

xgao32 commented 3 years ago

I might be interested if I knew more python. I would look into other graphing packages as well but Mapper has great visualization abilities which is very appealing.

deargle commented 3 years ago

Can you post an example networkx dataset, with what you'd want it to look like? I'm having a hard time imagining, I've never worked with networkx.

And do you know javascript? The edge-drawing logic is implemented both in python and also in javascript. Actually I just realized that the javascript PR was never merged. Here it is in javascript. https://github.com/scikit-tda/kepler-mapper/pull/231/files#diff-e18cbd76668f2d81f3de161789979b48d4d0892b76458ad212722d374a22cc39R633-R679 (and here is the same logic in python https://github.com/scikit-tda/kepler-mapper/blob/7dc4d0ad3a9020fe51ec7a52995b9593b9090bab/kmapper/nerve.py#L53-L65)

Also, fyi, the javascript visualization currently doesn't do anything with edge weights, but it could.

xgao32 commented 3 years ago

I made a simple example for a graph with 5 vertices and varying edge weights connecting every vertices. The drawing from networkx shows a complete graph. I would like to be able to play around with the threshold for the edge weight in Mapper to decide when to show two vertices are connected or not.

I cannot claim to understand javascript but I think if one adds an if statement to check that the edge weight between nodes i and j is above or below some threshold before line 646, then it will accomplish what I am thinking of.

xgao32 commented 3 years ago

This example of an interactive persistence diagram is very close to what I am thinking of.

deargle commented 2 years ago

How does an "edge weight" relate to kepler-mapper's "min intersection" argument? I suppose actually that your use-case doesn't use kmapper.map at all -- you're just using kmapper.visualize with your own graph (right?). Therefore, you don't have a concept of a "min intersection." It would be helpful to see where you use kmapper functions in your workflow.

xgao32 commented 2 years ago

This example of an interactive persistence diagram is very close to what I am thinking of.

The author of the example told me that the interactivity was just a series of pre-generated persistence diagrams and nothing was updated dynamically.

How does an "edge weight" relate to kepler-mapper's "min intersection" argument? I suppose actually that your use-case doesn't use kmapper.map at all -- you're just using kmapper.visualize with your own graph (right?). Therefore, you don't have a concept of a "min intersection." It would be helpful to see where you use kmapper functions in your workflow.

I should have specified that the vertices in my graph are associated with a real number in [0, M], where M is the max value of all vertex values in the graph. The graph is not complete and the edge weight between 2 vertices is the absolute difference between the 2 vertex values. All the vertices in the graph will be grouped according to their values, say one group for values in [0, a] and another for values in [a, M]. The "min intersection" can be some number delta so that some vertices will belong to the group [a - delta, a+ delta] and those vertices will "connect" the 2 vertices in the Mapper graph.

To summarize, edge weight is not directly related to min intersection from my description. I am primarily interested in seeing how the membership of the vertices in the Mapper graph changes with different thresholds on edge weights to decide when 2 vertices in the original graph is connected. Does this help?

deargle commented 2 years ago

I need to see exactly how and where in your flow you are currently using any code specifically from the kepler-mapper library.

I am guessing now that you're just using the plotlyviz stuff, which is totally separate from the .visualize javascript stuff.