Is there a equivalent of igraph for MATLAB? - networking

Hi
I am looking for igraph possibly something similar for MATLAB to compute common network paramerers like clustering coefficient,
Thank YOU

You could try the Matlab interface to the Boost Graph Library, which includes clustering coefficient, minimum spanning tree, shortest paths, etc.
http://www.stanford.edu/~dgleich/programs/matlab_bgl/
http://www.mathworks.com/matlabcentral/fileexchange/10922

Related

Sum up shortest paths in a weighted network

I have a graph with 340 nodes and 700 links. As for performance indicator of the network, I want to compute the sum of all weighted shortest paths in my network.
I tried the all_shortest_paths command from the igraph package. But my system doesn't have enough RAM to store the resulting matrix.
Can someone recommend a package or code which computes the sum of all shortest paths? (So the big matrix is not needed?)
For unweighted networks is the command mean_distance, which does basically something similar!?
You could try the package dodgr. With
dodgr_dists(graph)
you can generate a square matrix of distances between your nodes (more info).
Note: This will only work if your graph is directed.

Network Detection using Spectral Clustering, are there any good function in R?

I currently have an adjacency matrix I would like to perform spectral clustering on to determine the community each node belongs to. I have looked around, but there do not look to be implementations in either igraph or other packages.
Another issue is determining how many clusters you want. I was wondering if R has any packages that might help one find the optimal number of clusters to break an adjacency matrix into? Thanks.
I cannot advise for R, however, I can suggest this example implementation of Spectral Clustering using Python and Networkx (which is comparable to iGraph). It should not be hard to translate this into R.
For an introduction to Spectral Clustering see lectures 28-34 here and this paper.

Clustering algorithm for unweighted graphs

I am having unweighted and undirected graph as my network which is basically the network of proteins.I want to cluster this graph and divide this graph in to disjoint clusters. Can any 1 suggest clustering algorithms which i can apply on the biological network which is unweighted and undirected graph.
Several graph partitioning algorithms exist, they use different paradigm to tackle the same problem.
The most common is the Louvain's method optimizing Newman's modularity.
In python using Networkx as graph library you can use community to partition your graph.
The fastest graph partitioning uses Metis. It is based hierarchical graph coarsening.
You also have N-cut originally designed to segment images.
Finally, you can partition graphs using stochastic block-model techniques. A very good python implementation of Louvain and several block-model techniques can be found in Graph-tool.
My favorite is the latter, it is fast (based on the Boost graph library), relatively easy to use and tuneable.
EDIT: Note that in graph-tool, what we call Louvain modularity is indeed Newman's algorithm, the docs are here.

Graph Shortest Paths w/Dynamic Weights (Repeated Dijkstra? Distance Vector Routing Algorithm?) in R / Python / Matlab

I have a graph of a road network with avg. traffic speed measures that change throughout the day. Nodes are locations on a road, and edges connect different locations on the same road or intersections between 2 roads. I need an algorithm that solves the shortest travel time path between any two nodes given a start time.
Clearly, the graph has dynamic weights, as the travel time for an edge i is a function of the speed of traffic at this edge, which depends on how long your path takes to reach edge i.
I have implemented Dijkstra's algorithm with
edge weights = (edge_distance / edge_speed_at_start_time)
but this ignores that edge speed changes over time.
My questions are:
Is there a heuristic way to use repeated calls to Dijkstra's algorithm to approximate the true solution?
I believe the 'Distance Vector Routing Algorithm' is the proper way to solve such a problem. Is there a way to use the Igraph library or another library in R, Python, or Matlab to implement this algorithm?
EDIT
I am currently using Igraph in R. The graph is an igraph object. The igraph object was created using the igraph command graph.data.frame(Edges), where Edges looks like this (but with many more rows):
I also have a matrix of the speed (in MPH) of every edge for each time, which looks like this (except with many more rows and columns):
Since I want to find shortest travel time paths, then the weights for a given edge are edge_distance / edge_speed. But edge_speed changes depending on time (i.e. how long you've already driven on this path).
The graph has 7048 nodes and 7572 edges (so it's pretty sparse).
There exists an exact algorithm that solves this problem! It is called time-dependent Dijkstra (TDD) and runs about as fast as Dijkstra itself.
Unfortunately, as far as I know, neither igraph nor NetworkX have implemented this algorithm so you will have to do some coding yourself.
Luckily, you can implement it yourself! You need to adapt Dijkstra in single place.
In normal Dijkstra you assign the weight as follows:
With dist your current distance matrix, u the node you are considering and v its neighbor.
alt = dist[u] + travel_time(u, v)
In time-dependent Dijkstra we get the following:
current_time = start_time + dist[u]
cost = weight(u, v, current_time)
alt = dist[u] + cost
TDD Dijkstra was described by Stuart E. Dreyfus. An appraisal of some shortest-path
algorithms. Operations Research, 17(3):395–412, 1969
Currently, much faster heuristics are already in use. They can be found with the search term: 'Time dependent routing'.
What about igraph package in R? You can try get.shortest.paths or get.all.shortest.paths function.
library(igraph)
?get.all.shortest.paths
get.shortest.paths()
get.all.shortest.paths()# if weights are NULL then it will use Dijkstra.

Cluster adjacency matrix of different sizes

I have created adjacency matrix for directed graphs of different sizes. I have around 30,000 matrices, each on a separate text file. How can I cluster them, is there any tools available. What is the best way to represent a directed graph for clustering.
Thank you.
What exactly do you want to achieve? Group similar matrices, right?
With k-means, you will not have much fun here. The adjacency matrices are binary; interpreting them as huge vectors and computing an L-p-norm distance (e.g. Euclidean distance) on them, then computing average matrixes - which is what k-means does - doesn't sound sensible to me. Plus, you will likely be bitten by the curse of dimensionality. The high number of dimensions will make all matrixes appear similar.
For pretty much any clustering algorithm, the first question you as the "domain expert" will have to answer is: what makes two adjacency matrixes similar? Once you have formalized this, you will be able to run many clustering algorithms, including classic single-link clustering, DBSCAN or OPTICS.
I would try k-means and voronoi-diagrams. It can be by computed with a minimal spanning tree and by looking for the longest edges. Then you can compute the different cluster with the traditional k-means using the mst edges as center. Another possiblity would be a hierarchical cluster for example a space-filling-curve. See for example: https://stats.stackexchange.com/questions/1475/visualization-software-for-clustering.
You can find some ideas for graph features/statistics here:
http://networkx.lanl.gov/reference/algorithms.html

Resources