igraph

igraph: why is add_edge function so slow ompared to add_edges?

倾然丶 夕夏残阳落幕 提交于 2019-11-30 14:11:18
i am surprised that: import igraph import random, time start_time = time.time() G = igraph.Graph(directed = True) G.add_vertices(10000) for i in range(30000): G.add_edge(random.randint(0,9999), random.randint(0,9999)) print "done in " + str(int(time.time() - start_time)) + " seconds" returns done in 63 seconds while import igraph import random, time start_time = time.time() G = igraph.Graph(directed = True) G.add_vertices(10000) edges = [] for i in range(30000): edges += [(random.randint(0,9999), random.randint(0,9999))] G.add_edges(edges) print "done in " + str(int(time.time() - start_time))

Output shapefile for the igraph network in R

送分小仙女□ 提交于 2019-11-30 13:58:06
Hello I have a network in R using the igraph library Vertices: 616 Edges: 6270 Directed: TRUE No graph attributes. Vertex attributes: name, Lat, Lon. Edge attributes: V3. How can I generate two shapefiles for the Vertices and the Edges using the Lat, Lon info in the vertex? You can do this using the sp and maptools packages. There are handy functions writePointsShape() and writeLinesShape() in maptools that will write to the ESRI shapefile format. Before doing this, it is necessary to extract the lat/lon information from the graph vertices and put it into a SpatialPoints object for the

Visualize Parse Tree Structure

柔情痞子 提交于 2019-11-30 13:57:07
I would like to display the parsing (POS tagging) from openNLP as a tree structure visualization. Below I provide the parse tree from openNLP but I can not plot as a visual tree common to Python's parsing . install.packages( "http://datacube.wu.ac.at/src/contrib/openNLPmodels.en_1.5-1.tar.gz", repos=NULL, type="source" ) library(NLP) library(openNLP) x <- 'Scroll bar does not work the best either.' s <- as.String(x) ## Annotators sent_token_annotator <- Maxent_Sent_Token_Annotator() word_token_annotator <- Maxent_Word_Token_Annotator() parse_annotator <- Parse_Annotator() a2 <- annotate(s,

igraph - Neighbors as subgraph - make_ego_graph() as single graph

拟墨画扇 提交于 2019-11-30 13:26:42
I'd like to construct a subgraph of a graph of a directed network with all the vertices sharing a certain vertex attribute (say, V(Grph)$year == "1952") and their first-order (immediate) neighbors, based only on the out-degree. I've tried ego() , make_ego_graph() , neighbors() , and adjacent_vertices() . For instance, CitGraph <- make_ego_graph(Grph, 1, nodes = which(V(Grph)$year=="1952"), mode = "out") yields a list of graphs (and not a single comprehensive one) and surprisingly takes two hours for 50k vertices in this year and 150k neighbors being pointed to. One approach I could think of

Plotting communities with python igraph

走远了吗. 提交于 2019-11-30 09:49:49
I have a graph g in python-igraph. I can get a VertexCluster community structure with the following: community = g.community_multilevel() community.membership gives me a list of the group membership of all the vertices in the graph. My question is really simple but I haven't found a python-specific answer on SO. How can I plot the graph with visualization of its community structure? Preferably to PDF, so something like layout = g.layout("kk") plot(g, "graph.pdf", layout=layout) # Community detection? Thanks a lot. You can pass your VertexClustering object directly to the plot function; it will

Specified edge lengths on networkx/igraph (Python)

萝らか妹 提交于 2019-11-30 09:16:05
I wanted to visualize a network with the data I have and would like to graph them with specific edge lengths. I use Python, and I've tried networkx and igraph to plot but all seem to assign fixed edge lengths. a.) I wonder if I did the codes wrong or the packages aren't really capable. How do you properly implement specified edge lengths for networkx or igraph? b.) If networkx and igraph can't do it, what package could you possibly suggest? (Preferably one that can carry over 80 thousand nodes.) Thanks! doug This should work: import networkx as NX import pygraphviz as PG G = PG.AGraph() nlist

How do I lengthen edges in an igraph network plot (layout=fruchterman.reingold)?

我的梦境 提交于 2019-11-30 08:05:33
Trying to do a network plot in R. How do I lengthen edges in a network graph using IGraph? I actually want to use the fruchterman-reingold layout. Is there some way I can make that force-based algorithm "springier" so that my vertices are further apart? thanks. You can control the Fruchterman-Reingold algorithm using the layout.fruchterman.reingold function. see: help('layout.fruchterman.reingold') . A setup that I often use and gets you a little more spacing is: l <- layout.fruchterman.reingold(g,niter=500,area=vcount(g)^2.3,repulserad=vcount(g)^2.8) plot(g,layout=l) where g is your graph

Get contagion chain from adjacency matrix, r, igraph

我的梦境 提交于 2019-11-30 07:42:30
Q.I have a erdos.reyni graph. I infect a vertex and want to see what sequence of vertices the disease would follow? igraph has helful functions like get.adjacency(), neighbors(). Details. This is the adjacency matrix with vertex names instead of 0,1 flags and i'm trying to get the contagion chain out of it. Like the flow/sequence of an epidemic through a graph if a certain vertex is infected. Let's not worry about infection probabilities here (assume all vertices hit are infected with probability 1). So suppose I hit vertex 1 (which is row 1 here). We see that it has outgoing links to vertex 4

All paths of length L from node n using python

二次信任 提交于 2019-11-30 07:41:22
问题 Given a graph G, a node n and a length L, I'd like to collect all (non-cyclic) paths of length L that depart from n. Do you have any idea on how to approach this? By now, I my graph is a networkx.Graph instance, but I do not really care if e.g. igraph is recommended. Thanks a lot! 回答1: I would just like to expand on Lance Helsten's excellent answer: The depth-limited search searches for a particular node within a certain depth (what you're calling the length L), and stops when it finds it. If

Find distance of route from get.shortest.paths()

有些话、适合烂在心里 提交于 2019-11-30 07:35:55
I'm using the igraph package in R to do something rather simple: Calculate the shortest distance between two nodes in my network. Is there a straightforward way to extract the distance of a path calculated via get.shortest.paths() ? Here is some reproducible code that exemplifies my problem: ## reproducible code: df2 = rbind(c(234,235,21.6), c(234,326,11.0), c(235,241,14.5), c(326,241,8.2), c(241,245,15.3), c(234,245,38.46)) df2 = as.data.frame(df2) names(df2) = c("start_id","end_id","newcost") require(igraph) g2 <- graph.data.frame(df2, directed=FALSE) class(g2) print(g2, e=TRUE, v=TRUE) ##