I need an algorithm that can find a tree decomposition given a graph in Python, the graphs will be small so it doesn't need to be very efficient. I have looked around but cannot find much on this at all. Anyone know of a package that can do this or some sudo code I could use to make my own?
Have you looked at networkx? See: https://networkx.github.io/documentation/latest/reference/algorithms/approximation.html
Related
I’m very new to Python and NetworkX but I recently have learned how to do a few things to achieve what I’m after.
My problem involves a 75-node, 144-edge graph (from adjacency list) that I need to find all simple cycles within.
I was able to generate the cycles once using this code:
import NetworkX as nx
import numpy as np
G = nx.read_adjlist(‘myList.dat’);
print(list(nx.simple_cycles(G.to_directed())));
This worked initially but I realized I had forgotten to add a couple edges. After modifying the adjacency list, I ran the code again, but this time it just hung and produced no output.
I also tried replacing nx.simple_cycles() with nx.all_simple_paths() without converting the graph to directed, generating all paths from a node to the node right next to it. This could’ve gotten me closer to my answer, but it also hung with no output.
I know the more nodes and edges, the more time it will take, but is there a way to break up the results so that they are actually produced or something similar?
It could also be helpful to generate all simple cycles of length n, since I could then go through each integer until I reach the largest cycles.
If there is no possible way to do this using the method I chose, what are some alternative ways I could go about solving this problem?
Thank you in advance to anyone to helps out :)
I want to do ranking in R and I want to use the RankBoost algorithm. However, there seems to be no packages for R or even for python. The closes package is RankAggreg but that doesn't use the RankBoost algorithm. How can there not be an already written package for an algorithm that has been widely used for ranking problems?
What can I do in this case? Is writing the whole algorithm from scratch my best shot?
Thank you
I am writing code in Python to analyze social networks with node and edge attributes. Currently, I am using the NetworkX package to generate the graphs. Is there any limit to the size (in terms of the number of nodes, edges) of the graph which can be generated using this package?
I am new to coding social network problems in Python and have recently come across another package called NetworKit for large networks, but am not sure at what size should NetworKit be a better option, could you please elaborate on difference in performance and functionality between the two packages?
Thanks for your reply in advance.
My suggestion:
Start w/ Networkx as it has a bigger community, it's well mainteined and documented... and the best of all... you can easily understand what it does as it's 100% done in Python.
It's true it's not exactly fast, but it will be fast enough for most of the calculations. If you are running calculations from your laptop it can be slow for intensive calculations (Eg: sigma/omega small worldness metrics) in big networks (> 10k nodes and >100k vertexes).
If you need to speed it up, then you can easily incorporate networKit in your code as it integrates very easily to networkx and pandas, but it has a much more limited library of algorithms.
Compare yourself:
NetworkX algorithms: https://networkx.github.io/documentation/stable/reference/algorithms/index.html
VS
NetworKit algorithms: https://networkit.github.io/dev-docs/python_api/modules.html
Is there any limit to the size (in terms of the number of nodes, edges) of the graph which can be generated using this package?
No. There is no limit. It is all dependent on your memory capacity and size.
could you please elaborate on difference in performance and functionality between the two packages?
I personally don't have any experience with NetworkKit, however here (by Timothy Lin) you can find a very good benchmarking analysis on different tools including networkx and networkkit. Check out its conclusion section:
As for recommendations on which package people should learn, I think picking up networkx is still important as it makes network science very accessible with a wide range of tools and capabilities. If analysis starts being too slow (and maybe that’s why you are here) then I will suggest taking a look at graph-tool or networkit to see if they contain the necessary algorithms for your needs.
I've been looking for a good way in Python to draw an abstract syntax tree to PNG. A combination of networkx and matplotlib seems to be able to do the job well enough to get by.
But I just noticed that https://scikit-learn.org/stable/modules/generated/sklearn.tree.export_graphviz.html does much better! This applies when using sklearn to generate a random forest; it is a function specific to the resulting decision trees.
Is there a way to supply an arbitrary tree to the above function, or to some version of the code behind it, to obtain the high-quality rendering?
You could use simple graphviz. There is examples how to draw your own data structures.
Is there any libraries similar to igraph where I can create a hypergraph. I am working with hypergraph now and wanted to use some HyperGraph libraries to work on.
MGtoolkit and its paper
pygraph
halp
PyMETIS
SageMath's implementation, 1, 2. SageMath is not a python library but more like a python distribution (ships python 2.7 currently) which lots of interesting libraries are pre-installed.
I hope we see NetworkX and igraph support also soon.
There's also HyperNetX which is able to represent and visualise hypergraphs.
It seems very accessible. They have a number of nice tutorials on their GitHub page.
However, when working with it I identified some issues:
Performance: The library struggles with graphs that have several thousand nodes. I recommend igraph instead, although it does not have explicit support for hypergraphs. It does offer functionality for bipartite graphs, though. I believe if no hyperedge is fully contained in another, you can work with a bipartite graph that is isomorphic to your given hypergraph?
I encountered an issue in which the ordering of nodes would not be deterministic, i.e. if you constructed the same graph several times and iterated over the nodes, they would be given to you in different orders. This can probably be worked around.