plateform stringclasses 1
value | repo_name stringlengths 13 113 | name stringlengths 3 74 | ext stringclasses 1
value | path stringlengths 12 229 | size int64 23 843k | source_encoding stringclasses 9
values | md5 stringlengths 32 32 | text stringlengths 23 843k |
|---|---|---|---|---|---|---|---|---|
github | prashanthvarma/Complex-Networks-Analysis-master | kmin_neighbors.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/kmin_neighbors.m | 542 | utf_8 | f02d9ee6a2689ef31cba4541c74be12e | % Finds the number of "kmin"-neighbors (k links away at a minimum) for every node
% If nodes are k-links away due to loops (so they appear as m-neighbours, m<k), they are not counted
% INPUTS: adjacency matrix, node index, k - number of links
% OUTPUTS: vector of "kmin"-neighbors indices
% GB, May 16, 2011
function kn... |
github | prashanthvarma/Complex-Networks-Analysis-master | distance_distribution.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/distance_distribution.m | 803 | utf_8 | 20ab339d624338f2a9b279c42df51ddd | % The number of pairs of nodes at a distance x, divided by the total number of pairs n(n-1)
% Source: Mahadevan et al, "Systematic Topology Analysis and Generation Using Degree Correlations"
% Note: The cumulative distance distribution (hop-plot) can be obtained by using ddist(i)=length(find(dij<=i)); in line 18 inste... |
github | prashanthvarma/Complex-Networks-Analysis-master | astar_search.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/astar_search.m | 3,582 | utf_8 | 528ff641877279dc012bed23ea2d9d21 | function [d pred f]=astar_search(A,s,h,varargin)
% ASTAR_SEARCH Perform a heuristically guided (A*) search on the graph.
%
% [d pred rank]=astar_search(A,s,h,optionsu) returns the distance map,
% search tree and f-value of each node in an astar_search.
% The search begins at vertex s. The heuristic h guides the searc... |
github | prashanthvarma/Complex-Networks-Analysis-master | rewire_assort.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/rewire_assort.m | 1,285 | utf_8 | 50bed6900e436bbf3a8619ab5f5d2c39 | % Degree-preserving random rewiring
% Every rewiring increases the assortativity (pearson coefficient)
% Note 1: There are rare cases of neutral rewiring (coeff stays the same within numerical error)
% Note 2: Assume unweighted undirected graph
% INPUTS: edgelist, el and number of rewirings, k
% OUTPUTS: rewired edgeli... |
github | prashanthvarma/Complex-Networks-Analysis-master | closeness.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/closeness.m | 583 | utf_8 | 2d726747852d36fe9860055241eba9d9 | % Computes the closeness centrality for every vertex: 1/sum(dist to all other nodes)
% For disconnected graphs can use: sum_over_t(2^-d(i,t)), idea Dangalchev (2006)
% C(i)=sum(2.^(-d)) if graph is disconnected, but sum w/o d(i)
% INPUTs: graph representation (adjacency matrix nxn)
% OUTPUTs: vector of centralities, nx... |
github | prashanthvarma/Complex-Networks-Analysis-master | bfs.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/bfs.m | 530 | utf_8 | 002b0227dfd8bfcbca8413aa599cd7ae | % Implementation of breadth-first-search of a graph
% INPUTs: adjacency list, starting node index
% OUTPUTs: BFS tree, in adjacency list format (directed)
function T=BFS(adjL,i0)
discovered=[i0];
q=[i0];
T=cell(length(adjL),1);
while not(isempty(q))
j=q(1); q=q(2:length(q)); % pop the front
neigh=adjL{j};
... |
github | prashanthvarma/Complex-Networks-Analysis-master | pdf_cdf_rank.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/pdf_cdf_rank.m | 1,109 | utf_8 | 0c22030962884c353715e29b2901273b | % Compute the pdf, cdf and rank distributions for a sequence of values
% INPUTS: sequence of values: x, size 1xn, 'plot' - 'on' or 'off'
% OUTPUTS: pdf, cdf and rank distribution values
% Note: pdf = frequency, cdf = cumulative frequency, rank = log-log scale of the sorted sequence
% GB, Last Updated: June 27, 2007
fu... |
github | prashanthvarma/Complex-Networks-Analysis-master | getEdges.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/getEdges.m | 889 | utf_8 | 08031761752379ee53bc6809359690d7 | % Return the list of edges for varying representation types
% Inputs: graph structure (matrix or cell or struct) and type of structure (string)
% Outputs: edge list
% 'type' can be: 'adj','edgelist','adjlist' (neighbor list),'inc' (incidence matrix)
% Note: symmetric edges will both twice, also in undirected graphs, (i... |
github | prashanthvarma/Complex-Networks-Analysis-master | node_betweenness_slow.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/node_betweenness_slow.m | 1,066 | utf_8 | 5f8168b479a5b61c967cbf627b10961c | % Betweenness centrality measure: number of shortest paths running though a
% vertex. Compute for all vertices.
% Note: Valid for a general graph. Using 'number of shortest paths through a node' definition
% INPUTS: adjacency (distances) matrix (nxn)
% OUTPUTS: betweeness vector for all vertices (nx1)
%
% GB, Oct... |
github | prashanthvarma/Complex-Networks-Analysis-master | louvain_community_finding.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/louvain_community_finding.m | 3,058 | utf_8 | f2982cf49fcdc343214336347a463879 | % Implementation of a community finding algorithm by Blondel et al
% Source: "Fast unfolding of communities in large networks", July 2008
% https://sites.google.com/site/findcommunities/
% Note: This is just the first step of the Louvain community
% finding algorithm, to extract fewer communities, need to repeat with t... |
github | prashanthvarma/Complex-Networks-Analysis-master | subgraph.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/subgraph.m | 330 | utf_8 | 4ba2f72c47d99789be72f75e8364658a | % This function outputs the adjacency matrix of a subgraph given the
% supergraph and the node set of the subgraph
% INPUTs: adj - supergraph adjacency matrix, S - vector of subgraph node indices
% OUTPUTs: adj_sub - adjacency matrix of the subgraph
% GB, January 5, 2006
function adj_sub = subgraph(adj,S)
adj_sub = ... |
github | prashanthvarma/Complex-Networks-Analysis-master | fabrikant_model.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/fabrikant_model.m | 1,566 | utf_8 | 93627d3d44a3bf2c9fd15a1d26166500 | % Implements the Fabrikant model of internet growth
% Source: Fabrikant et al, "Heuristically Optimized Trade-offs: A New Paradigm for Power Laws in the Internet"
% Note: Assume the first point to be the center - easy to change by setting p(1,:) = [x0,y0]
% INPUTS: n - number of points, parameter alpha, [0,inf), plt='o... |
github | prashanthvarma/Complex-Networks-Analysis-master | loops4.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/loops4.m | 1,091 | utf_8 | c5ed30f9a6713c0e726abd5d96d1b34e | % Finds loops of length 4 in a graph; Note: Quite basic and slow, but works
% INPUTs: adj - adjacency matrix of graph
% OUTPUTs: number of loops of size 4
% Note: assumes undirected graph
% Other functions used: adj2adjL.m
% Last Updated: May 25, 2010, originally April 2006
function l4 = loops4(adj)
n = size(adj,1); ... |
github | prashanthvarma/Complex-Networks-Analysis-master | graph_from_degree_sequence.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/graph_from_degree_sequence.m | 617 | utf_8 | d25557ddc5bbe8caec9cdf70d155f1b8 | % Constructing a graph from a given degree sequence: deterministic
% This is the Havel-Hakimi algorithm
% Inputs: a graphic degree sequence, [d1,d2, ... dn], where di is the degree of the ith node
% Outputs: adjacency matrix, nxn
function adj = graph_from_degree_sequence(seq)
adj = zeros(length(seq));
while sum(seq)... |
github | prashanthvarma/Complex-Networks-Analysis-master | shortest_pathDP.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/shortest_pathDP.m | 1,211 | utf_8 | 64f76e40106bdfb150b64eb984d86d4e | % Shortest path algorithm using Dynamic Programming
% Valid for directed/undirected network
% Disclaimer: if links have weights, they are treated as distances
% INPUTs: L - (cost/path lengths matrix), s - (start/source node), t - (end/destination node)
% OUTPUTS:
% route - sequence of nodes on optimal path, at c... |
github | prashanthvarma/Complex-Networks-Analysis-master | newman_eigenvector_method.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/newman_eigenvector_method.m | 2,449 | utf_8 | c644c0965473981204128ef8e7a0acd6 | % Find the "optimal" number of communities given a network using an eigenvector method
% Source: MEJ Newman: Finding community structure using the eigenvectors of matrices, arXiv:physics/0605087
% Newman, "Modularity and community structure in networks", arxiv.org/pdf/physics/0602124v1
% Q=(s^T)Bs, Bij=Aij-kikj/2m
% Bi... |
github | prashanthvarma/Complex-Networks-Analysis-master | isbipartite.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/isbipartite.m | 1,187 | utf_8 | c2cca322f3915127fbd714a012363f29 | % Test whether a graph is bipartite, if yes, return the two vertex sets
% Inputs: graph in the form of adjancency list (neighbor list, see adj2adjL.m)
% Outputs: True/False (boolean), empty set (if False) or two sets of vertices
% Note: This only works for undirected graphs
% Last updated: April 28, 2011
function [isi... |
github | prashanthvarma/Complex-Networks-Analysis-master | iseulerian.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/iseulerian.m | 847 | utf_8 | 05fd6318292b4d14184b0a0f897bc58e | % Check if a graph is Eulerian, i.e. it has an Eulerian circuit
% "A connected undirected graph is Eulerian if and only if every graph vertex has an even degree."
% "A connected directed graph is Eulerian if and only if every graph vertex has equal in- and out- degree."
% Note: Assume that the graph is connected.
% INP... |
github | prashanthvarma/Complex-Networks-Analysis-master | kregular.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/kregular.m | 1,471 | utf_8 | 1c1c4b70c88e6e91315f10f8f920ae67 | % Create a k-regular graph
% INPUTs: n - # nodes, k - degree of each vertex
% OUTPUTs: el - edge list of the k-regular undirected graph
% GB, Last updated: January 12, 2011
function eln = kregular(n,k)
el={};
if k>n-1; fprintf('a simple graph with n nodes and k>n-1 does not exist\n'); return; end
if mod(k,2)==1 & mo... |
github | prashanthvarma/Complex-Networks-Analysis-master | laplacian_matrix.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/laplacian_matrix.m | 605 | utf_8 | d71625ae2828704dba7f77756190e5ca | % The Laplacian matrix defined for a *simple* graph
% (the difference b/w the diagonal degree and the adjacency matrices)
% Note: This is not the normalized Laplacian
% INPUTS: adjacency matrix
% OUTPUTs: Laplacian matrix
function L=laplacian_matrix(adj)
L=diag(sum(adj))-adj;
% NORMALIZED Laplacian =============
... |
github | prashanthvarma/Complex-Networks-Analysis-master | iscomplete.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/iscomplete.m | 453 | utf_8 | 946fe6b7530f0d9bf2613bff525fb3a7 | % Checks whether a (sub)graph is complete, i.e. whether every node is
% linked to every other node. Only defined for unweighted graphs.
% INPUTS: adjacency matrix, adj, nxn
% OUTPUTS: Boolean variable, true/false
% GB, Last Updated: October 1, 2009
function S=iscomplete(adj)
S=false; % default
adj=adj>0; % remove w... |
github | prashanthvarma/Complex-Networks-Analysis-master | master_equation_growth_model.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/master_equation_growth_model.m | 1,103 | utf_8 | fd280633ec899bb361cf320177cc28ac | % "Master equation" growth model, as in "Evolution of Networks" by Dorogovtsev, Mendez
% Note: probability of attachment: (q(i)+ma)/((1+a)mt), q(i)-indegree of i, a=const, t - time step (# nodes)
% INPUTS: number of nodes n, m - # links to add at each step, a=constant
% OUTPUTS: adjacency matrix, nxn
% Last updated by ... |
github | prashanthvarma/Complex-Networks-Analysis-master | symmetrize.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/symmetrize.m | 292 | utf_8 | bc8994ec798d3780fca60fee20d06f4b | % Symmetrize a non-symmetric matrix
% For matrices in which mat(i,j)~=mat(j,i), the larger (nonzero) value is chosen
% INPUTS: a matrix - nxn
% OUTPUT: corresponding symmetric matrix - nxn
% Last Updated: October 1, 2009
function adj_sym = symmetrize(adj)
adj_sym = max(adj,transpose(adj)); |
github | prashanthvarma/Complex-Networks-Analysis-master | preferential_attachment.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/preferential_attachment.m | 1,453 | utf_8 | a9e6c6b9678bcdd62ed7391151d0d2b9 | % Routine implementing a simple preferential attachment (B-A) model for network growth
% The probability that a new vertex attaches to a given old vertex is proportional to the (total) vertex degree
% Vertices arrive one at a time
% INPUTs: n - final (desired) number of vertices, m - # edges to attach at every step
% O... |
github | prashanthvarma/Complex-Networks-Analysis-master | rewire.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/rewire.m | 1,573 | utf_8 | c76d6462de35d66608c1a8c22edbee35 | % Degree-preserving random rewiring
% Note 1: Assume unweighted undirected graph
% INPUTS: edgelist, el (mx3) and number of rewirings, k
% OUTPUTS: rewired edgelist
function el = rewire(el,k)
rew=0;
while rew<k
% pick two random edges
ind = randi(length(el),1,2);
edge1=el(ind(1),:); edge2=el(ind(2),:);
... |
github | prashanthvarma/Complex-Networks-Analysis-master | pajek2edgeL.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/pajek2edgeL.m | 903 | utf_8 | 409dcc303d61e9f3d5f30620fff04847 | % This program extracts an edge list from a pajek text (.net) file
% INPUT: .net (or .txt) filename, n - number of nodes in the graph
% OUTPUT: edge list, mx3, m - # edges
% GB, October 7, 2009
function el=pajek2edgeL(filename,n)
[e1,e2,e3] = textread(filename,'%6d%6d%6d','headerlines',n+2);
el=[e1,e2,e3];
% ALTERNA... |
github | prashanthvarma/Complex-Networks-Analysis-master | graph_energy.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/graph_energy.m | 364 | utf_8 | 6f654d7fa6023413fa7374f035722f00 | % Graph energy defined as: the sum of the absolute values of the real components of the eigenvalues
% Source: Gutman, The energy of a graph, Ber. Math. Statist. Sekt. Forsch-ungszentram Graz. 103 (1978) 1?22.
% INPUTs: adjacency matrix (nxn)
% OUTPUTs: graph energy
function G=graph_energy(adj)
[~,e]=eig(adj); % e ar... |
github | prashanthvarma/Complex-Networks-Analysis-master | edgeL2cyto.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/edgeL2cyto.m | 659 | utf_8 | 9c5a5753b03e8b4b5989655914d3ef83 | % Write an edgelist structure m x [node 1, node 2, link] to Cytoscape input format (.txt or any text extension works)
% In Cytoscape the column separator option is semi-colon ";". If desired, this is easy to change below in line 15.
% INPUTs: edgelist - mx3 matrix, m = number of edges, file name string
% OUTPUTs: text ... |
github | prashanthvarma/Complex-Networks-Analysis-master | add_edge_weights.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/add_edge_weights.m | 637 | utf_8 | a985e07602ef4a8cd5f2420091995fbe | % Add multiple edges in an edgelist
% INPUTS: original (non-compact) edgelist
% OUTPUTS: final compact edgelist (no row repetitions)
% GB, Last updated: October 7, 2009
function elc=add_edge_weights(el)
el2=[el(:,1), el(:,2)]; % make the edge list searchable w/o the weights
visited=[]; % mark visited edge... |
github | prashanthvarma/Complex-Networks-Analysis-master | leaf_nodes.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/leaf_nodes.m | 461 | utf_8 | 79836b7b803d42f6375d4b281441906d | % Return the leaf nodes of the graph - degree 1 nodes
% Note: For a directed graph, leaf nodes are those with a single incoming edge
% Note 2: There could be other definitions of leaves ex: farthest away from a given root node
% Note 3: Nodes with self-loops are not considered leaf nodes.
% Input: adjacency matrix
% Ou... |
github | prashanthvarma/Complex-Networks-Analysis-master | dot_matrix_plot.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/dot_matrix_plot.m | 1,917 | utf_8 | f54e10363b5c6f53457d53c2d9c0d364 | % Draws the matrix as a column/row sorted square dot-matrix pattern
% INPUTs: adj - adjacency matrix representation of the graph
% OUTPUTs: plot
% Note: Change colors and marker types in lines 41, 48, 55 and 62
% Other routines used: degrees.m, sort_nodes_by_max_neighbor_degree.m,
% eigencentrality... |
github | prashanthvarma/Complex-Networks-Analysis-master | smooth_diameter.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/smooth_diameter.m | 984 | iso_8859_13 | 26dc10da73ca56920dbfac06ab58fca4 | % A relaxed/smoothed definition of diameter: the number "d" at which
% a threshold fraction "p" of pairs of nodes are at distance at most
% "d". Can be non-integer using interpolation.
% Idea: Leskovec et al, "Graphs over Time: Densification Laws, Shrinking Diameters and Possible Explanations"
% Input: adjacency matrix ... |
github | prashanthvarma/Complex-Networks-Analysis-master | ave_neighbor_deg.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/ave_neighbor_deg.m | 591 | utf_8 | ec6df6502dc82cbfc5b71e4c6a0145ed | % Computes the average degree of neighboring nodes for every vertex
% Note: Works for weighted degrees also
% INPUTs: adjacency matrix
% OUTPUTs: average neighbor degree vector nx1
% Other routines used: degrees.m, kneighbors.m
% GB, Last updated: May 21, 2010
function ave_n_deg=ave_neighbor_deg(adj)
ave_n_deg=zeros(... |
github | prashanthvarma/Complex-Networks-Analysis-master | edgeL2adj.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/edgeL2adj.m | 453 | utf_8 | 2b1501cce9776d243bf7f88cd7a56bed | % Converts edge list to adjacency matrix
% INPUTS: edgelist: mx3
% OUTPUTS: adjacency matrix nxn
% Note: information about nodes is lost: indices only (i1,...in) remain
% GB, Last updated: October 6, 2009
function adj=edgeL2adj(el)
nodes=sort(unique([el(:,1) el(:,2)])); % get all nodes, sorted
adj=zeros(numel(nodes))... |
github | prashanthvarma/Complex-Networks-Analysis-master | vertex_eccentricity.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/vertex_eccentricity.m | 288 | utf_8 | b2fc6d45bf236555f3af935eab315f90 | % Vertex eccentricity - the maximum distance to any other vertex
% Input: adjacency matrix
% Output: vector of eccentricities
% Other routines used: simple_dijkstra.m
function ec=vertex_eccentricity(adj)
n=size(adj,1);
ec=zeros(1,n);
for s=1:n; ec(s)=max( simple_dijkstra(adj,s) ); end |
github | prashanthvarma/Complex-Networks-Analysis-master | nested_hierarchies_model.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/nested_hierarchies_model.m | 2,356 | utf_8 | 8de57170e7960601c8407225bc2d3f00 | % Based on: Sales-Pardo et al, "Extracting the hierarchical organization of complex systems", PNAS, Sep 25, 2007; vol.104; no.39
% Supplementary material: http://www.pnas.org/content/suppl/2008/02/27/0703740104.DC1/07-03740SItext.pdf
% INPUTs: N: number of nodes; L: number of hierarchy levels; [G1,G2,..,GL]: number of... |
github | prashanthvarma/Complex-Networks-Analysis-master | isregular.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/isregular.m | 351 | utf_8 | da563083fce0314c8aae55df2d467399 | % Checks whether a graph is regular, i.e. every node has the same degree.
% Note: Defined for unweighted graphs only.
% INPUTS: adjacency matrix nxn
% OUTPUTS: Boolean, yes/no
% GB, Last updated: October 1, 2009
function S=isregular(adj)
S=false;
degs=sum(adj>0); % remove weights and sum columns
if degs == degs(1)*... |
github | prashanthvarma/Complex-Networks-Analysis-master | numnodes.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/numnodes.m | 225 | utf_8 | f8b37d444a8e65749e9477d89b8f0ffe | % Returns the number of nodes, given an adjacency list
% also works for an adjacency matrix
% INPUTs: adjacency list: {i:j_1,j_2 ..}
% OUTPUTs: number of nodes
% GB, February 19, 2006
function n = numnodes(L)
n = length(L); |
github | prashanthvarma/Complex-Networks-Analysis-master | weighted_clust_coeff.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/weighted_clust_coeff.m | 1,195 | utf_8 | 21ae917626ef00a6d0dffa5696439371 | % Weighted clustering coefficient
% Source: Barrat, The architecture of complex weighted networks
% INPUTS: weighted adjacency matrix
% OUTPUTs: vector of node weighted clustering coefficients
% Other routines used: degrees.m, kneighbors.m
function wC=weighted_clust_coeff(adj)
[deg,~,~]=degrees(adj);
n=size(adj,1); ... |
github | prashanthvarma/Complex-Networks-Analysis-master | pajek2adj.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/pajek2adj.m | 337 | utf_8 | 8ab7f3a8796a5b0925550050453baa82 | % This program extracts an adjacency matrix from a pajek text (.net) file
% INPUT .net text filename, n - number of nodes in the graph
% OUTPUT: adjacency matrix, nxn, n - # nodes
% Other routines used: pajek2edgeL.m, edgeL2adj.m
% GB, October 7, 2009
function adj = pajek2adj(filename,n)
el=pajek2edgeL(filename,n);
a... |
github | prashanthvarma/Complex-Networks-Analysis-master | adj2str.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/adj2str.m | 595 | utf_8 | 7af12888ae0ae39e140ffde4655c8f1e | % Converts an adjacency matrix to a one-line string representation
% INPUTS: adjacency matrix, nxn
% OUTPUTS: string
% The nomenclature used to construct the string is arbitrary. Here we use
% .i1.j1.k1,.i2.j2.k2,....
% Other routines used: kneighbors.m
% GB, Last updated: October 6, 2009
function str=adj2str(adj)
% ... |
github | prashanthvarma/Complex-Networks-Analysis-master | graph_radius.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/graph_radius.m | 223 | utf_8 | f5629cdf8d404dc212e5efc714bf7327 | % The minimum vertex eccentricity is the graph radius
% Inputs: adjacency matrix (nxn)
% Outputs: graph radius
% Other routines used: vertex_eccentricity.m
function Rg=graph_radius(adj)
Rg=min( vertex_eccentricity(adj) ); |
github | prashanthvarma/Complex-Networks-Analysis-master | grid_graph.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/grid_graph.m | 2,474 | utf_8 | bd3a3e48fad748a8b3b57dab5570c97c | function [A coords] = grid_graph(varargin)
% GRID_GRAPH Generate a grid graph or hypergrid graph
%
% [A xy] = grid_graph(m,n) generates a grid graph with m vertices along the
% x axis and n vertices along the y axis. The xy output gives the 2d
% coordinates of each vertex.
% [A xyz] = grid_graph(m,n,k) generates a ... |
github | prashanthvarma/Complex-Networks-Analysis-master | average_degree.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/average_degree.m | 291 | utf_8 | 9c6a5314b85c245f9e756b03f464ae46 | % Computes the average degree of a node in a graph, defined as 2*num_edges
% divided by the num_nodes (every edge is counted in degrees twice).
% Other routines used: numnodes.m, numedges.m
% GB, Last Update: October 1, 2009
function k=average_degree(adj)
k=2*numedges(adj)/numnodes(adj); |
github | prashanthvarma/Complex-Networks-Analysis-master | issymmetric.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/issymmetric.m | 260 | utf_8 | 63bcd46eded9d2a755bd5cc8cd2252ce | % Checks whether a matrix is symmetric (has to be square)
% Check whether mat=mat^T
% INPUTS: adjacency matrix
% OUTPUTS: boolean variable, {0,1}
% GB, October 1, 2009
function S = issymmetric(mat)
S = false; % default
if mat == transpose(mat); S = true; end |
github | prashanthvarma/Complex-Networks-Analysis-master | random_graph.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/random_graph.m | 3,604 | utf_8 | 7738900e50e4d9b0ff3b36e20a8d5dd2 | % Random graph construction routine with various models
% INPUTS: N - number of nodes
% p - probability, 0<=p<=1, for all other inputs, p is not considered
% E - fixed number of edges
% distribution - probability distribution: use the "connecting-stubs model" generation model
% degr... |
github | prashanthvarma/Complex-Networks-Analysis-master | rich_club_metric.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/rich_club_metric.m | 592 | utf_8 | b3d6ab40bb3db925ed4a83d6fc44c5ac | % Compute the rich club metric for a graph
% INPUTs: adjacency matrix, nxn, k - threshold number of links
% OUTPUTs: rich club metric
% Source: Colizza, Flammini, Serrano, Vespignani, "Detecting rich-club ordering in complex networks", Nature Physics, vol 2, Feb 2006
% Other routines used: degrees.m, subgraph.m, numedg... |
github | prashanthvarma/Complex-Networks-Analysis-master | canonical_nets.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/canonical_nets.m | 7,870 | utf_8 | fb940a6a350a1415e208dbe26cd3e524 | % Build edge lists for simple canonical graphs, ex: trees and lattices
% INPUTS: number of nodes, net type, branch factor (for trees only)
% Types can be 'line','circle','star','btree','tree','htree','trilattice','sqlattice','hexlattice', 'clique'
% OUTPUTS: edgelist (mx3); additional outputs possible, see specific gr... |
github | prashanthvarma/Complex-Networks-Analysis-master | link_density.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/link_density.m | 365 | utf_8 | c9c4172fa311ac246e2c586512937f34 | % Computes the link density of a graph, defined as num_edges divided by
% num_nodes(num_nodes-1)/2 where the latter is the max possible num edges.
% The graph needs to be non-trivial (more than 1 node).
% Other routines used: numnodes.m, numedges.m
% GB, Last Update: October 1, 2009
function d=link_density(adj)
n = ... |
github | prashanthvarma/Complex-Networks-Analysis-master | node_betweenness_faster.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/node_betweenness_faster.m | 1,027 | utf_8 | 047db628add2afc52c81089ebe73b72d | % Betweenness centrality measure: number of shortest paths running though a vertex
% Compute for all vertices, using Dijkstra's algorithm, using 'number of shortest paths through a node' definition
% Note: Valid for a general (connected) graph.
% INPUTS: adjacency (distances) matrix (nxn)
% OUTPUTS: betweeness vector ... |
github | prashanthvarma/Complex-Networks-Analysis-master | s_metric.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/s_metric.m | 892 | utf_8 | 30ec94b507e61843e17234816e9c4c15 | % The sum of products of degrees across all edges
% Source: "Towards a Theory of Scale-Free Graphs: Definition, Properties, and Implications", by Li, Alderson, Doyle, Willinger
% Note: The total degree is used regardless of whether the graph is directed or not.
% INPUTs: adjacency matrix
% OUTPUTs: s-metric
% Other rou... |
github | prashanthvarma/Complex-Networks-Analysis-master | graph_complement.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/graph_complement.m | 249 | utf_8 | a384a97b3c90415e4054885e21986650 | % Returns the complement of a graph
% INPUTs: adj - original graph adjacency matrix
% OUTPUTs: complement graph adjacency matrix
% Note: Assumes no multiedges
% GB, February 2, 2006
function adj_c = graph_complement(adj)
adj_c=ones(size(adj))-adj; |
github | prashanthvarma/Complex-Networks-Analysis-master | fiedler_vector.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/fiedler_vector.m | 253 | utf_8 | fda4aa10cf56f040a9e649bf9e4532fd | % The vector corresponding to the second smallest eigenvalue of the Laplacian matrix
% INPUTs: adjacency matrix (nxn)
% OUTPUTs: fiedler vector (nx1)
function fv=fiedler_vector(adj)
[V,D]=eig(laplacian_matrix(adj));
[ds,Y]=sort(diag(D));
fv=V(:,Y(2)); |
github | prashanthvarma/Complex-Networks-Analysis-master | dijkstra.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/dijkstra.m | 1,449 | utf_8 | ffcb3bb02ca50fa647781eeb3d444e19 | % INPUTS: adj - adjacency matrix, s - source node, target - target node
% OUTPUTS: distance, d and path, P (from s to target)
% Note: if target==[], then dist and P include all distances and paths from s
% Other routines used: adj2adjL.m, purge.m
% GB, Last Updated: Dec 22, 2009
function [dist,P]=dijkstra(adj,s,target... |
github | prashanthvarma/Complex-Networks-Analysis-master | eigencentrality.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/eigencentrality.m | 332 | utf_8 | 09b026358150b0bed5936cf3895792cd | % The ith component of the eigenvector corresponding to the greatest
% eigenvalue gives the centrality score of the ith node in the network.
% INPUTs: adjacency matrix
% OUTPUTs: eigen(-centrality) vector
% GB, Last Updated: October 14, 2009
function x=eigencentrality(adj)
[V,D]=eig(adj);
[max_eig,ind]=max(diag(D));... |
github | prashanthvarma/Complex-Networks-Analysis-master | tarjan.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/tarjan.m | 1,733 | utf_8 | 5aa83caadb4ce4f54f81101a104b715a | % Find the giant stronly connected component in a directed graph
% Source: Tarjan, R. E. (1972), "Depth-first search and linear graph algorithms", SIAM Journal on Computing 1 (2): 146-160
% Input: graph, set of nodes and edges, in adjacency list format, ex: L{1}=[2], L{2]=[1] is the 1-2 edge
% Outputs: set of strongly ... |
github | prashanthvarma/Complex-Networks-Analysis-master | PriceModel.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/PriceModel.m | 1,029 | utf_8 | 0c38c192336268b44a6e887e656266f9 | % Routine implementing the Price model for network growth
% Notes:
% p_k - fraction of vertices with degree k
% probability a new vertex attaches to any of the degree-k vertices is
% (k+1)p_k/(m+1), where m - mean number of new citations per vertex
% Source: "The Structure and Function of Complex Networks", M.E.... |
github | prashanthvarma/Complex-Networks-Analysis-master | forestFireModel.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/forestFireModel.m | 1,853 | utf_8 | 4394a4fa96bdeff6b9ade7183dc95cca | % Implementation of the forest fire model by Leskovec et al
% Source: Graphs over Time: Densification Laws, Shrinking Diameters and Possible Explanations
% Inputs: forward burning probability p in [0,1],
% backward burning ratio r, in [1,inf),
% T - number of nodes
% Outputs: adjacency list of the cons... |
github | prashanthvarma/Complex-Networks-Analysis-master | random_modular_graph.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/random_modular_graph.m | 1,249 | utf_8 | e5fb109d3f9460992e128747731e1441 | % Build a random modular graph, given number of modules, and link density
% INPUTs: number of nodes, number of modules, total link density,
% and proportion of links within modules compared to links across
% OUTPUTs: adjacency matrix, modules to which the nodes are assigned
% GB, Last updated: October 19, 2009
... |
github | prashanthvarma/Complex-Networks-Analysis-master | istree.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/istree.m | 335 | utf_8 | 1fc3d238ecd94ba0772235494fa35085 | % Check whether a graph is a tree
% Source: "Intro to Graph Theory" by Bela Bollobas
% INPUTS: adjacency matrix
% OUTPUTS: Boolean variable
% Other routines used: isconnected.m, numedges.m, numnodes.m
% GB, Last Updated: June 19, 2007
function S=istree(adj)
S=false;
if isconnected(adj) & numedges(adj)==numnodes(adj)... |
github | prashanthvarma/Complex-Networks-Analysis-master | adj2simple.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/adj2simple.m | 407 | utf_8 | 64d978907cd90f0c39f378d82bdcd75d | % Convert an adjacency matrix of a general graph to the adjacency matrix of
% a simple graph (no loops, no double edges) - great for quick data clean up
% INPUTS: adjacency matrix
% OUTPUTs: adjacency matrix of the corresponding simple graph
% GB, Last updated: October 4, 2009
function adj=adj2simple(adj)
adj=adj>0; ... |
github | prashanthvarma/Complex-Networks-Analysis-master | adj2pajek.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/adj2pajek.m | 2,167 | utf_8 | fbd109998af47215482b493fd4ae48b5 | % Converts an adjacency matrix representation to a Pajek .net read format
% INPUT: an adjacency matrix, [nxn], a filename, [string], node coordinates (optional)
% OUTPUT: text format of Pajek readable .net (or .txt) file in the same directory
% Note 1: If node coordinates are not provided, random numbers between 0 and ... |
github | prashanthvarma/Complex-Networks-Analysis-master | edgeL2pajek.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/edgeL2pajek.m | 1,339 | utf_8 | e6160be8b26e7528d88528abe916aeac | % Converts an edgelist matrix representation to a Pajek .net readable format
% INPUT: an edgelist matrix, [mx3], a filename, [string]
% OUTPUT: text format of Pajek readable .net file
% See also: adj2pajek.m
% Other routines used: edgeL2adj.m, issymmetric.m
% EXAMPLE
% *Vertices 4
% 1 "14" ... |
github | prashanthvarma/Complex-Networks-Analysis-master | num_loops.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/num_loops.m | 546 | utf_8 | ee658d8413f05f4412b7e1b10a52597a | % Calculate the number of independent loops (use G=m-n+c)
% where G = num loops, m - num edges, n - num nodes, c - num_connected_components
% This is also known as the "cyclomatic number" or the number of edges that need to be removed so that the graph cannot have cycles.
% INPUTS: adjacency matrix
% OUTPUTs: number of... |
github | prashanthvarma/Complex-Networks-Analysis-master | numedges.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/numedges.m | 702 | utf_8 | 5c2bb553a2573d9236da193cca248115 | % Returns the total number of edges given the adjacency matrix
% Valid for both directed and undirected, simple or general graph
% INPUTs: adjacency matrix
% OUTPUTs: m - total number of edges/links
% Other routines used: selfloops.m, issymmetric.m
% GB, Last Updated: October 1, 2009
function m = numedges(adj)
sl=sel... |
github | prashanthvarma/Complex-Networks-Analysis-master | loops3.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/loops3.m | 252 | utf_8 | 35f24b3703dd3af444eb87be8fea84b4 | % Calculates number of loops of length 3
% INPUTs: adj - adjacency matrix
% OUTPUTs: L3 - number of triangles (loops of length 3)
% Valid for an undirected network
% GB, April 6, 2006
function L3 = loops3(adj)
L3 = trace(adj^3)/6; % trace(adj^3)/3! |
github | prashanthvarma/Complex-Networks-Analysis-master | graph_dual.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/graph_dual.m | 1,239 | utf_8 | 3c6fe1d0999b16a091e2e5815f6dccda | % Finds the dual of a graph; a dual is the inverted nodes-edges graph
% This is also called the line graph, adjoint graph or the edges adjacency
% INPUTs: adjacency (neighbor) list representation of the graph (see adj2adjL.m)
% OUTPUTs: adj (neighbor) list of the corresponding dual graph and cell array of edges
% Note:... |
github | prashanthvarma/Complex-Networks-Analysis-master | isgraphic.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/isgraphic.m | 753 | utf_8 | 85d75fa8e9a5a26eb1854a366c09c9f7 | % Check whether a sequence of number is graphical, i.e. a graph with this degree sequence exists
% INPUTs: a sequence (vector) of numbers
% OUTPUTs: boolean, true or false
% Note: not generalized to directed graph degree sequences
% Source: Erdős, P. and Gallai, T. "Graphs with Prescribed Degrees of Vertices" [Hungaria... |
github | prashanthvarma/Complex-Networks-Analysis-master | pajek2xyz.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/pajek2xyz.m | 761 | utf_8 | 44651c6186cbff3c43cef36d33e51136 | % Read x,y,z node coordinates from a pajek .net file - useful for plotting in Matlab
% INPUTS: filename, string format
% OUTPUTS: x,y,z coordinate vectors
% GB, Last updated: October 7, 2009
function [x,y,z]=pajek2xyz(filename)
f=fopen(filename,'r');
C = textscan(f, '%s');
c=C{1};
ind_edges=find(ismember(c, '*Edges'... |
github | prashanthvarma/Complex-Networks-Analysis-master | edgeL2simple.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/edgeL2simple.m | 531 | utf_8 | 6ad7e81c0762dfcff4f8d37b0c7a8f40 | % Convert an edge list of a general graph to the edge list of a simple
% graph (no loops, no double edges) - great for quick data clean up
% INPUTS: edgelist (mx3), m - number of edges
% OUTPUTs: edge list of the corresponding simple graph
% Note: Assumes all node pairs [n1,n2,x] occur once; if else see add_edge_weigh... |
github | prashanthvarma/Complex-Networks-Analysis-master | sort_nodes_by_sum_neighbor_degrees.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/sort_nodes_by_sum_neighbor_degrees.m | 996 | utf_8 | de0a508e63c114f561adac24e52ec319 | % Sort nodes by degree, and where there's equality, by sum of neighbor degrees and then neighbors' neighbors degree and so on
% Ideas from s-max algorithm by Li et al 2005 "Towards a theory of scale-free graphs"
% and Guo, Chen, Zhou, "Fingerprint for Network Topologies"
% INPUTS: adjacency matrix, 0s and 1s
% OUTPUTS:... |
github | prashanthvarma/Complex-Networks-Analysis-master | inc2adj.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/inc2adj.m | 960 | utf_8 | b67cad22bb8006a5b50503db8497f470 | % Converts an incidence matrix representation to an adjacency
% matrix representation for an arbitrary graph
% INPUTs: incidence matrix, nxm
% OUTPUTs: adjacency matrix, nxn
% GB, October 5, 2009
function adj = inc2adj(inc)
m = size(inc,2); % number of edges
adj = zeros(size(inc,1)); % initialize adjacency matrix
i... |
github | prashanthvarma/Complex-Networks-Analysis-master | giant_component.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/giant_component.m | 410 | utf_8 | 9535f8036ed3b419209e8e4accfa717f | % extract giant component from a network
% INPUTS: adjacency matrix
% OUTPUTS: giant comp matrix and node indeces
% Other routines used: find_conn_comp.m, subgraph.m
% GB, Last Updated: October 2, 2009
function [GC,gc_nodes]=giant_component(adj)
comps=find_conn_comp(adj);
L=[];
for k=1:length(comps); L=[L, length(c... |
github | prashanthvarma/Complex-Networks-Analysis-master | isdirected.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/isdirected.m | 257 | utf_8 | 9596db5950cb34227826089f2d4e655c | % Using the matrix transpose function
% INPUTS: adjacency matrix
% OUTPUTS: boolean variable
% GB, Last updated: October 1, 2009
function S=isdirected(adj)
S = true;
if adj==transpose(adj); S = false; end
% one-liner alternative: S=not(issymmetric(adj)); |
github | prashanthvarma/Complex-Networks-Analysis-master | purge.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/purge.m | 333 | utf_8 | 5dc4f1d9a4a932043bdbf41957a35b67 | % Removes a subset from a set, but preserves order of elements
% Similar to setdiff - which sorts the elements
% INPUTs: original set A, subset to remove B
% OUTPUTs: set Anew = A-B
% GB, Last updated: October 12, 2009
function Anew = purge(A,B)
Anew = [];
for a=1:numel(A);
if isempty(find(B==A(a))); Anew=[Anew, A... |
github | prashanthvarma/Complex-Networks-Analysis-master | str2adj.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/str2adj.m | 1,037 | utf_8 | f9941058e03f1fef255a9eeb5e7f7725 | % Converts a string graph representation to an adjacency matrix
% Note: The string nomenclature is arbitrary
% INPUTs: string variable of the format: .i1.j1.k1,.i2.j2.k2,....
% OUTPUTs: adjacency matrix, nxn
% Note 1: Valid for a general graph
% Note 2: This is the reverse routine for adj2str.m
% GB, October 6, 2009
f... |
github | prashanthvarma/Complex-Networks-Analysis-master | simple_dijkstra.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/simple_dijkstra.m | 766 | utf_8 | 44d0861a75a60d83726084ec89876b94 | % Implements a simple version of the Dijkstra shortest path algorithm
% Returns the distance from a single vertex to all others, doesn't save the path
% INPUTS: adjacency matrix (adj), start node (s)
% OUTPUTS: shortest path length from start node to all other nodes
% Note: works with a weighted/directed matrix
% GB, L... |
github | prashanthvarma/Complex-Networks-Analysis-master | adj2inc.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/adj2inc.m | 1,272 | utf_8 | 21544e6dfbfc390e4e20340f90e0781c | % Convert adjacency matrix to an incidence matrix
% Valid for directed/undirected, simple/not simple graph
% INPUTs: adjacency matrix, NxN, N - number of nodes
% OUTPUTs: incidence matrix: N x number of edges
% Other routines used: isdirected.m
% GB, Last Updated: July 10, 2011
function inc = adj2inc(adj)
n=length(ad... |
github | prashanthvarma/Complex-Networks-Analysis-master | num_conn_comp.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/num_conn_comp.m | 431 | utf_8 | 1084d55de1f452459b7372b438df4554 | % Calculate the number of connected components using the Laplacian
% eigenvalues - counting the number of zeros
% INPUTS: adjacency matrix
% OUTPUTs: positive integer - number of connected components
% Other routines used: graph_spectrum.m
% GB, Last updated: October 22, 2009
function nc=num_conn_comp(adj)
s=graph_sp... |
github | prashanthvarma/Complex-Networks-Analysis-master | DoddsWattsSabel.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/DoddsWattsSabel.m | 1,956 | utf_8 | de99f63df9741eb23edf8bef62a6fdea | % Add random cross-links on top of a perfect hierarchy
% Non-backbone edges are added with probability P(i,j)=e^(-Dij/lambda)*e^(-xij/ksi),
% where Dij is the level of the lowest common ancestor and xij is the "organizational" distance
% Source: Dodds, Watts, Sabel, "Information exchange and the robustness of organ... |
github | prashanthvarma/Complex-Networks-Analysis-master | multiedges.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/multiedges.m | 211 | utf_8 | c636b62463bc702f4115c0099a6a82d5 | % counts the number of multiple edges in the graph
% INPUT: adjacency matrix
% OUTPUT: interger, number of multiple edges
% Last Updated: GB, October 1, 2009
function mE=multiedges(adj)
mE=length(find(adj>1)); |
github | prashanthvarma/Complex-Networks-Analysis-master | graph_spectrum.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/graph_spectrum.m | 228 | utf_8 | eddf752487b9e372f365d999cf69b4f3 | % The eigenvalues of the Laplacian of the graph
% INPUTs: adjacency matrix
% OUTPUTs: laplacian eigenvalues, sorted
function s=graph_spectrum(adj)
[v,D]=eig(laplacian_matrix(adj));
s=-sort(-diag(D)); % sort in decreasing order |
github | prashanthvarma/Complex-Networks-Analysis-master | min_span_tree.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/min_span_tree.m | 1,157 | utf_8 | bcabcd05b8a4da735ddc67e60ff3ebb5 | % Prim's minimal spanning tree algorithm
% Prim's alg idea:
% start at any node, find closest neighbor and mark edges
% for all remaining nodes, find closest to previous cluster, mark edge
% continue until no nodes remain
% INPUTS: graph defined by adjacency matrix
% OUTPUTS: matrix specifying minimum spanning tree ... |
github | prashanthvarma/Complex-Networks-Analysis-master | num_conn_triples.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/num_conn_triples.m | 544 | utf_8 | 110de16713b263ee2d37f676fea0c610 | % Counts the number of connected triples in a graph
% INPUTs: adjacency matrix
% OUTPUTs: integer - num conn triples
% Other routines used: kneighbors.m, loops3.m
% Note: works for undirected graphs only
% GB, Last updated: October 9, 2009
function c=num_conn_triples(adj)
c=0; % initialize
for i=1:length(adj)
n... |
github | prashanthvarma/Complex-Networks-Analysis-master | adjL2adj.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/adjL2adj.m | 343 | utf_8 | db90beccb8ed769b1516201fed70f899 | % Convert an adjacency list to an adjacency matrix
% INPUTS: adjacency list: {n}
% OUTPUTS: adjacency matrix nxn
% Note: Assume that if node i has no neighbours, L{i}=[];
% GB, Last updated: October 6, 2009
function adj=adjL2adj(adjL)
adj = zeros(length(adjL));
for i=1:length(adjL)
for j=1:length(adjL{i}); adj(i... |
github | prashanthvarma/Complex-Networks-Analysis-master | edge_betweenness.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/edge_betweenness.m | 3,838 | utf_8 | 82d506b662223f087f3105c6194d2f3b | % Edge betweenness routine, based on shortest paths
% INPUTs: edgelist, mx3, m - number of edges
% OUTPUTs: w - betweenness per edge
% Note: Valid for undirected graphs only
% Source: Newman, Girvan, "Finding and evaluating community structure in networks"
% Other routines used: adj2edgeL.m, numnodes.m, numedges.m, kne... |
github | prashanthvarma/Complex-Networks-Analysis-master | el2geom.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/el2geom.m | 1,535 | utf_8 | d1c4fe1b13a8ab684f79a13c860f6692 | % Plot geometry based on extended edgelist
% INPUTS: extended edgelist el[i,:]=[n1 n2 m x1 y1 x2 y2]
% OUTPUTS: geometry plot, higher-weight links are thicker and lighter
% Note 1: m - edge weight; (x1,y1) are the Euclidean coordinates of n1, (x2,y2) - n2 resp.
% Note 2: Easy to change colors and corresponding edge we... |
github | prashanthvarma/Complex-Networks-Analysis-master | ave_path_length.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/ave_path_length.m | 485 | utf_8 | b239a8493a131f840feeff93355722bb | % Compute average path length for a network - the average shortest path
% INPUTS: adjL - matrix of weights/distances between nodes
% OUTPUTS: average path length: the average of the shortest paths between every two edges
% Note: works for directed/undirected networks
% GB, December 8, 2005
function l = ave_path_length... |
github | prashanthvarma/Complex-Networks-Analysis-master | rewire_disassort.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/rewire_disassort.m | 1,255 | utf_8 | 269669174b4cd7fa67f9dc956c0ea991 | % Degree-preserving random rewiring
% Every rewiring decreases the assortativity (pearson coefficient)
% Note 1: There are rare cases of neutral rewiring (coeff stays the same within numerical error)
% Note 2: Assume unweighted undirected graph
% INPUTS: edgelist, el and number of rewirings, k
% OUTPUTS: rewired edgeli... |
github | prashanthvarma/Complex-Networks-Analysis-master | radial_plot.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/radial_plot.m | 3,422 | utf_8 | 871c4d0f094d2eba426fb6e795354d1e | % Plots nodes radially out from a given center. Equidistant nodes
% have the same radius, but different angles. Works best as a quick
% visualization for trees, or very sparse graphs.
% Note 1: No spring-energy method implemented.
% Note 2: If a center node is not specified, the nodes are ordered by
% sum of neighbor ... |
github | prashanthvarma/Complex-Networks-Analysis-master | isweighted.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/isweighted.m | 307 | utf_8 | 045573a6f9b4cb8c72cf9e81a45b9be7 | % Check whether a graph is weighted, i.e not all edges are 0,1.
% INPUTS: edge list, m x 3, m: number of edges, [node 1, node 2, edge weight]
% OUTPUTS: Boolean variable, yes/no
% GB, Last updated: October 1, 2009
function S=isweighted(el)
S=true;
if numel( find(el(:,3)==1) ) == size(el,1); S=false; end |
github | prashanthvarma/Complex-Networks-Analysis-master | graph_similarity.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/graph_similarity.m | 737 | utf_8 | 82376ec972ae128e0bfd27d7b48028a8 | % Computes the similarity matrix between two graphs
% Ref: "A measure of similarity between graph vertices:
% applications to synomym extraction and web searching"
% Blondel, SIAM Review, Vol. 46, No. 4, pp. 647-666
% Inputs: A, B - two graphs adjacency matrices, mxm and nxn
% Outputs: S - similarity matrix, mxn
% Last... |
github | prashanthvarma/Complex-Networks-Analysis-master | adjL2edgeL.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/adjL2edgeL.m | 272 | utf_8 | c24ec53465dbf161886a1ec25a4a3d8d | % Converts adjacency list to an edge list
% INPUTS: adjacency list
% OUTPUTS: edge list
% GB, Last Updated: October 6, 2009
function el = adjL2edgeL(adjL)
el = []; % initialize edgelist
for i=1:length(adjL)
for j=1:length(adjL{i}); el=[el; i, adjL{i}(j), 1]; end
end |
github | prashanthvarma/Complex-Networks-Analysis-master | diameter.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/diameter.m | 335 | utf_8 | d9992d55ce6f495d679b7df0cb7a76c7 | % The longest shortest path between any two nodes nodes in the network
% INPUTS: adjacency matrix, adj
% OUTPUTS: network diameter, diam
% Other routines used: simple_dijkstra.m
% GB, Last updated: June 8, 2010
function diam = diameter(adj)
diam=0;
for i=1:size(adj,1)
d=simple_dijkstra(adj,i);
diam = max([max... |
github | prashanthvarma/Complex-Networks-Analysis-master | adj2adjL.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/adj2adjL.m | 411 | utf_8 | 9dcd7d329d1123d1909bdb66ba283327 | % Converts an adjacency graph representation to an adjacency list
% Valid for a general (directed, not simple) network model, but edge
% weights get lost in the conversion.
% INPUT: an adjacency matrix, NxN, N - # of nodes
% OUTPUT: cell structure for adjacency list: x{i_1}=[j_1,j_2 ...]
% GB, October 1, 2009
function... |
github | prashanthvarma/Complex-Networks-Analysis-master | num_star_motifs.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/num_star_motifs.m | 503 | utf_8 | 0bfa482372798254d4aded546946d37e | % Calculates the number of star motifs of given (subgraph) size
% Easily extendible to return the actual stars as k-tuples of nodes
% INPUTs: adjacency matrix of original graph, k - size of the star motif
% OUTPUTs: number of stars with k nodes (k-1 spokes)
% Other routines used: degrees.m
% Note: star of size 1 is the... |
github | prashanthvarma/Complex-Networks-Analysis-master | isconnected.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/isconnected.m | 1,802 | utf_8 | d49e273550e7e55a897c208f835673ad | % Determine if a graph is connected
% INPUTS: adjacency matrix
% OUTPUTS: Boolean variable {0,1}
% Note: this only works for undirected graphs
% Idea by Ed Scheinerman, circa 2006, source: http://www.ams.jhu.edu/~ers/matgraph/
% routine: matgraph/@graph/isconnected.m
function S = is... |
github | prashanthvarma/Complex-Networks-Analysis-master | modularity_metric.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/modularity_metric.m | 1,568 | utf_8 | 072dbf35dc30ed72bebe7c8ad86361bc | % Computing the modularity for a given module/commnunity break-down
% Defined as: Q=sum_over_modules_i (eii-ai^2) (eq 5) in Newman and Girvan.
% eij = fraction of edges that connect community i to community j, ai=sum_j (eij)
% Source: Newman, M.E.J., Girvan, M., "Finding and evaluating community structure in networks"
... |
github | prashanthvarma/Complex-Networks-Analysis-master | adj2edgeL.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/adj2edgeL.m | 369 | utf_8 | 726a2ad04d68d1c368b86a70730fc234 | % Converts adjacency matrix (nxn) to edge list (mx3)
% INPUTS: adjacency matrix: nxn
% OUTPUTS: edge list: mx3
% GB, Last updated: October 2, 2009
function el=adj2edgeL(adj)
n=length(adj); % number of nodes
edges=find(adj>0); % indices of all edges
el=[];
for e=1:length(edges)
[i,j]=ind2sub([n,n],edges(e)); % node... |
github | prashanthvarma/Complex-Networks-Analysis-master | degrees.m | .m | Complex-Networks-Analysis-master/Assignment/Exercise 1/Code/degrees.m | 522 | utf_8 | a84c21eaa099ed34ba358bab5707d4f5 | % Compute the total degree, in-degree and out-degree of a graph based on
% the adjacency matrix; should produce weighted degrees, if the input matrix is weighted
% INPUTS: adjacency matrix
% OUTPUTS: degree, indegree and outdegree sequences
% GB, Last Updated: October 2, 2009
function [deg,indeg,outdeg]=degrees(adj)
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.