I used networkx to generate my directed graph. I want to use greedy_modularity_communities(G, weight=None) to find communities in my graph.
As it is mentioned in Networkx documentation I am importing the following modules.
from networkx.algorithms import community
from networkx.algorithms.community import greedy_modularity_communities
but I get an error:
ImportError: cannot import name 'greedy_modularity_communities'
As you can see from the URL you linked, the docs you're looking at are from "latest", and on the top left of the page you can see the version that those docs are from is "2.2rc1.dev_20180504030509", which is a release candidate for version 2.2 which hasn't been released yet.
If you want, you could install the development version as explained in the networkx docs, after which it should work:
>>> import networkx
>>> networkx.__version__
'2.2rc1.dev_20180521153746'
>>> from networkx.algorithms.community import greedy_modularity_communities
>>> print(greedy_modularity_communities.__doc__)
Find communities in graph using Clauset-Newman-Moore greedy modularity
maximization. This method currently supports the Graph class and does not
consider edge weights.
Greedy modularity maximization begins with each node in its own community
and joins the pair of communities that most increases modularity until no
such pair exists.
[...]
but as usual, you should be aware of the dangers of using prerelease versions of software packages: there are often bugs which haven't yet been fixed and testing which isn't complete. Coder beware.
The newest version of networkx seems to have moved greedy_modularity_communities to the modularity_max module, as seen here.
This is not yet included in the version of the package you'll install via PIP, so if you require this function you may want to try the latest dev version.
Related
I have a graph with 480k nodes and 34M edges. I want to create node embeddings using Node2Vec on this graph. But, It is not even able to calculate transition probabilities. I am using a Google Cloud Machine with 32 cores and 120 GB RAM. Infrastructure is not the problem, the problem is that the function _precompute_probabilities in the node2vec pip library is not paraller. It is using only a single thread to calculate the transition probabilities. Is there a way to make this parallel or is they any other parallel version of Node2Vec ?
TLDR
To compute embeddings on large graphs use GRAPE.
pip install grape
Example:
from grape import Graph
from grape.embedders import Node2VecGloVeEnsmallen
graph = Graph.from_csv(
## The path to the edges list tsv
edge_path="edges.csv",
sources_column="source",
destinations_column="destination",
directed=False,
)
embedding = Node2VecGloVeEnsmallen().fit_transform(graph)
Longer answer
To solve this issue, we developed GRAPE, our Rust library with Python bindings. We needed to run node2vec on big graphs and the libraries we found weren't fast enough. We re-implemented and optimized many models, including Node2vec's, from the ground up without using Tensorflow or Pytorch.
Here's some benchmarks on our server with 12 cores (24 threads) and 128GB of ram.
Info about the tested graphs:
WikiEN has 130M edges and 17M nodes.
CTD has 45M edges and 100K nodes.
PheKnowLator has 7M edges and 800K nodes.
Here's the tutorial on how to load your own custom graph, we support CSV-like formats:
https://github.com/AnacletoLAB/grape/blob/main/tutorials/Loading_a_Graph_in_Ensmallen.ipynb
and here's the complete tutorial on how to run and visualize node2vec with Glove on a given graph:
https://github.com/AnacletoLAB/grape/blob/main/tutorials/Using_Node2Vec_GloVe_to_embed_Cora.ipynb
Our paper is still under review ( https://arxiv.org/abs/2110.06196 ) and we are just two developers, so, if you need any help contact us on Discord, Github, or Twitter #GRAPElib.
I found a library Graph2Vec, it uses a CSR Matrix to generate walks instead of jumping from node to node in memory. It is way faster than Node2Vec.
Link: https://www.singlelunch.com/2019/08/01/700x-faster-node2vec-models-fastest-random-walks-on-a-graph/
Github: https://github.com/VHRanger/graph2vec
Also, you can refer to this issue and try the mentioned libraries:
https://github.com/aditya-grover/node2vec/issues/10
I've tried https://github.com/eliorc/node2vec with the "temp_folder" property. Thought I didn't feel that it was much faster, so I ended up with the version with CSR Matrices.
Oh... was it yourself, who answered the question? :)
Good to know, thank you for the tip
I have created a Redisgraph and I am able to execute queries on it using Redisinsight and redis-cli. Now, I want to create graph-embeddings using Node2vec. But, I am not able to pass redisgraph in Node2vec(). It is showing error that the passed graph is of 'dict' type. All the Node2vec tutorials that I found use Networkx graph to create graph embeddings. Is there any way to use Node2vec on redis-graph, or some way to convert redis-graph to networkx graph ?
I assume we'll be able to provide a networkx integration, I'm not familiar with networkx, there's an open issue on the matter, It would be wonderful if such an integration would be contributed by the open source community, I'll be glad to provide assistance.
I'm a R newbie.
is there a way i can calculate
(x+x^2+x^3)^2
in R?
so i will get the result:
x^6+2 x^5+3 x^4+2 x^3+x^2
I get an Error: object 'x' not found.
Thanks!
R isn't well suited for this. Some interface packages to languages and libraries that are better at this do exist, such as rSymPy, which allows you to access the SymPy Python library for symbolic mathematics (you'll need to install both). In a similar vein, Ryacas links to the yacas algebra system.
Those interfaces are useful if you need symbolic manipulation as part of an R workflow. Otherwise, consider using the original tools. The ones above are open source and freely available, while other free use alternatives also exist, such as the proprietary web based Wolfram Alpha (for limited use).
I am new to the OpenMDAO framework and currently using the 1.5.0 version. I'm interested in generating a Pareto front for Zitzler–Deb–Thiele's functions using the same.
I found a solution for the legacy version here which uses 'pareto_filter' but was unable to locate the same in the new version.
So, how do I set up a multi-objective problem to generate pareto front in 1.x version?
Thanks to all.
You should be able to us NSGA2 from pyopt-sparse directly in OpenMDAO. You just install the pyopt-sparse package and OpenMDAO has a driver already built in that will let you use it. Then you pick NSGA2 as your optimizer.
The only issue is that, if you look at the source, that driver is currently labeled as single-objective. So you should change that line to True, so that you can specify multiple objectives.
We haven't tested NSGA2 via the pyopt-sparse. So it might take a little bit of hacking around to get it to work. If you'd prefer to us the regular pyopt package, you should be able to start with our current pyopt-sparse wrapper and make some small changes to get it to work.
I compiled Julia 0.1 from the source code on my Ubuntu 12.04. It is my first time try with Julia actually.
The compilation got through to the end with no problem but some warnings.
When I try to execute the plot command , here comes the problem,
julia> plot(x->sin(x^2)/x, -2pi,2pi)
ERROR: plot not defined
Did the compilation go wrong somewhere or Do I have to install extra package to plot in Julia?
Thanks
The web-based graphics are outdated and unmaintained (though there's work in progress to get the next generation of web graphics working). Plotting alternatives include the Winston or Gadfly packages at https://github.com/nolta/Winston.jl and https://github.com/dcjones/Gadfly.jl which you can install simply using the Pkg.add("Winston") (or Pkg.add("Gadfly") commands). For documentation and usage examples please refer to the linked repositories.
For MATLAB-style plotting under Julia, type once
Pkg.add("PyPlot")
to install the PyPlot package, which gives you access to Python's matplotlib library. Then try e.g.
using PyPlot
x = -2pi:0.1:2pi;
plot(x, sin(x.^2)./x);
OK I found the solution myself,
Julia uses a web REPL to provide some basic graphics capabilities. Just have to follow the steps here:
https://github.com/JuliaLang/julia#web-repl
Julian Schrittwieser also has a library based on MathGL:
http://www.furidamu.org/blog/2012/02/26/plotting-with-julia/
I am not sure whether it is still under maintenance by the author.
As of right now (a few years passed since the question was asked so the ecosystem has matured), the package I would suggest for easy quick plots would be Gadfly, with some use of PyPlot for publication quality graphs that require a lot of control.
To install, just type
Pkg.add("Gadfly")
in a Julia command line, and to use, type:
using Gadfly
plot([sin, cos], 0, 25)
PyPlot is still the preferred plotting option for when you want a lot of control over your graphs, but it is a wrapper for a Python library and is slightly less user-friendly. It also requires a working python install on your system.