Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xgao32 opened this issue Sep 13, 2021 · 8 comments

Comments

@xgao32
Copy link

xgao32 commented Sep 13, 2021

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
Copy link
Member

sauln commented Sep 13, 2021

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
Copy link
Author

xgao32 commented Sep 13, 2021

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
Copy link
Collaborator

deargle commented Sep 13, 2021

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

# Create links when clusters from different hypercubes have members with the same sample id.
candidates = itertools.combinations(nodes.keys(), 2)
for candidate in candidates:
# if there are non-unique members in the union
if (
len(set(nodes[candidate[0]]).intersection(nodes[candidate[1]]))
>= self.min_intersection
):
result[candidate[0]].append(candidate[1])
edges = [[x, end] for x in result for end in result[x]]
simplices = [[n] for n in nodes] + edges
return result, simplices
)

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

@xgao32
Copy link
Author

xgao32 commented Sep 14, 2021

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
Copy link
Author

xgao32 commented Sep 30, 2021

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

@deargle
Copy link
Collaborator

deargle commented Oct 11, 2021

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
Copy link
Author

xgao32 commented Oct 29, 2021

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
Copy link
Collaborator

deargle commented Oct 29, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants