network-analysis

Target must be a dense double array of node indices. How to Solve?

左心房为你撑大大i 提交于 2019-12-11 02:08:25
问题 I am trying to build a network graph with word adjacency data. But I am getting the error "Target must be a dense double array of node indices". Following is my code: fileName = 'adjnoun.gml'; inputfile = fopen(fileName); A=[]; l=0; k=1; while 1 % Get a line from the input file tline = fgetl(inputfile); % Quit if end of file if ~ischar(tline) break end nums = regexp(tline,'\d+','match'); %get number from string if length(nums) if l==1 l=0; A(k,2)=str2num(nums{1}); k=k+1; continue; end A(k,1)

How to efficiently calculate triad census in undirected graph in python

☆樱花仙子☆ 提交于 2019-12-06 17:22:27
问题 I am calculating triad census as follows for my undirected network . import networkx as nx G = nx.Graph() G.add_edges_from( [('A', 'B'), ('A', 'C'), ('D', 'B'), ('E', 'C'), ('E', 'F'), ('B', 'H'), ('B', 'G'), ('B', 'F'), ('C', 'G')]) from itertools import combinations #print(len(list(combinations(G.nodes, 3)))) triad_class = {} for nodes in combinations(G.nodes, 3): n_edges = G.subgraph(nodes).number_of_edges() triad_class.setdefault(n_edges, []).append(nodes) print(triad_class) It works fine

How to efficiently calculate triad census in undirected graph in python

◇◆丶佛笑我妖孽 提交于 2019-12-04 22:53:32
I am calculating triad census as follows for my undirected network . import networkx as nx G = nx.Graph() G.add_edges_from( [('A', 'B'), ('A', 'C'), ('D', 'B'), ('E', 'C'), ('E', 'F'), ('B', 'H'), ('B', 'G'), ('B', 'F'), ('C', 'G')]) from itertools import combinations #print(len(list(combinations(G.nodes, 3)))) triad_class = {} for nodes in combinations(G.nodes, 3): n_edges = G.subgraph(nodes).number_of_edges() triad_class.setdefault(n_edges, []).append(nodes) print(triad_class) It works fine with small networks. However, now I have a bigger network with approximately 4000-8000 nodes. When I

Explain Mike Bostock Node-Parsing Loop [duplicate]

五迷三道 提交于 2019-12-01 20:30:32
This question already has an answer here: variable declaration conditional syntax 3 answers I'm relatively new to JavaScript and d3, but I'm really interested in force-directed layouts. In Mike Bostock's force-directed visualizations, he tends to parse nodes from a list of links using the following code (or similar): var links = [ {source: "A", target: "B"}, {source: "B", target: "C"}, {source: "C", target: "A"}]; var nodes = {}; links.forEach(function(link) { link.source = nodes[link.source] || (nodes[link.source] = {name: link.source}); link.target = nodes[link.target] || (nodes[link.target]

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

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

﹥>﹥吖頭↗ 提交于 2019-11-29 19:05:16
问题 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

build word co-occurence edge list in R

流过昼夜 提交于 2019-11-29 04:50:33
I have a chunk of sentences and I want to build the undirected edge list of word co-occurrence and see the frequency of every edge. I took a look at the tm package but didn't find similar functions. Is there some package/script I can use? Thanks a lot! Note: A word doesn't co-occur with itself. A word which appears twice or more co-occurs with other words for only once in the same sentence. DF: sentence_id text 1 a b c d e 2 a b b e 3 b c d 4 a e 5 a 6 a a a OUTPUT word1 word2 freq a b 2 a c 1 a d 1 a e 3 b c 2 b d 2 b e 2 c d 2 c e 1 d e 1 It's convoluted so there's got to be a better