EVOLUTION-MANAGER
Edit File: scg.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: All-in-one Function for the SCG of Matrices and Graphs</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for scg {igraph}"><tr><td>scg {igraph}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>All-in-one Function for the SCG of Matrices and Graphs</h2> <h3>Description</h3> <p>This function handles all the steps involved in the Spectral Coarse Graining (SCG) of some matrices and graphs as described in the reference below. </p> <h3>Usage</h3> <pre> scg( X, ev, nt, groups = NULL, mtype = c("symmetric", "laplacian", "stochastic"), algo = c("optimum", "interv_km", "interv", "exact_scg"), norm = c("row", "col"), direction = c("default", "left", "right"), evec = NULL, p = NULL, use.arpack = FALSE, maxiter = 300, sparse = igraph_opt("sparsematrices"), output = c("default", "matrix", "graph"), semproj = FALSE, epairs = FALSE, stat.prob = FALSE ) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>X</code></td> <td> <p>The input graph or square matrix. Can be of class <code>igraph</code>, <code>matrix</code> or <code>Matrix</code>.</p> </td></tr> <tr valign="top"><td><code>ev</code></td> <td> <p>A vector of positive integers giving the indexes of the eigenpairs to be preserved. For real eigenpairs, 1 designates the eigenvalue with largest algebraic value, 2 the one with second largest algebraic value, etc. In the complex case, it is the magnitude that matters.</p> </td></tr> <tr valign="top"><td><code>nt</code></td> <td> <p>A vector of positive integers of length one or equal to <code>length(ev)</code>. When <code>algo</code> = “optimum”, <code>nt</code> contains the number of groups used to partition each eigenvector separately. When <code>algo</code> is equal to “interv_km” or “interv”, <code>nt</code> contains the number of intervals used to partition each eigenvector. The same partition size or number of intervals is used for each eigenvector if <code>nt</code> is a single integer. When <code>algo</code> = “exact_cg” this parameter is ignored.</p> </td></tr> <tr valign="top"><td><code>groups</code></td> <td> <p>A vector of <code>nrow(X)</code> or <code>vcount(X)</code> integers labeling each group vertex in the partition. If this parameter is supplied most part of the function is bypassed.</p> </td></tr> <tr valign="top"><td><code>mtype</code></td> <td> <p>Character scalar. The type of semi-projector to be used for the SCG. For now “symmetric”, “laplacian” and “stochastic” are available.</p> </td></tr> <tr valign="top"><td><code>algo</code></td> <td> <p>Character scalar. The algorithm used to solve the SCG problem. Possible values are “optimum”, “interv_km”, “interv” and “exact_scg”.</p> </td></tr> <tr valign="top"><td><code>norm</code></td> <td> <p>Character scalar. Either “row” or “col”. If set to “row” the rows of the Laplacian matrix sum up to zero and the rows of the stochastic matrix sum up to one; otherwise it is the columns.</p> </td></tr> <tr valign="top"><td><code>direction</code></td> <td> <p>Character scalar. When set to “right”, resp. “left”, the parameters <code>ev</code> and <code>evec</code> refer to right, resp. left eigenvectors. When passed “default” it is the SCG described in the reference below that is applied (common usage). This argument is currently not implemented, and right eigenvectors are always used.</p> </td></tr> <tr valign="top"><td><code>evec</code></td> <td> <p>A numeric matrix of (eigen)vectors to be preserved by the coarse graining (the vectors are to be stored column-wise in <code>evec</code>). If supplied, the eigenvectors should correspond to the indexes in <code>ev</code> as no cross-check will be done.</p> </td></tr> <tr valign="top"><td><code>p</code></td> <td> <p>A probability vector of length <code>nrow(X)</code> (or <code>vcount(X)</code>). <code>p</code> is the stationary probability distribution of a Markov chain when <code>mtype</code> = “stochastic”. This parameter is ignored in all other cases.</p> </td></tr> <tr valign="top"><td><code>use.arpack</code></td> <td> <p>Logical scalar. When set to <code>TRUE</code> uses the function <code><a href="arpack.html">arpack</a></code> to compute eigenpairs. This parameter should be set to <code>TRUE</code> if one deals with large (over a few thousands) AND sparse graphs or matrices. This argument is not implemented currently and LAPACK is used for solving the eigenproblems.</p> </td></tr> <tr valign="top"><td><code>maxiter</code></td> <td> <p>A positive integer giving the maximum number of iterations for the k-means algorithm when <code>algo</code> = “interv_km”. This parameter is ignored in all other cases.</p> </td></tr> <tr valign="top"><td><code>sparse</code></td> <td> <p>Logical scalar. Whether to return sparse matrices in the result, if matrices are requested.</p> </td></tr> <tr valign="top"><td><code>output</code></td> <td> <p>Character scalar. Set this parameter to “default” to retrieve a coarse-grained object of the same class as <code>X</code>.</p> </td></tr> <tr valign="top"><td><code>semproj</code></td> <td> <p>Logical scalar. Set this parameter to <code>TRUE</code> to retrieve the semi-projectors of the SCG.</p> </td></tr> <tr valign="top"><td><code>epairs</code></td> <td> <p>Logical scalar. Set this to <code>TRUE</code> to collect the eigenpairs computed by <code>scg</code>.</p> </td></tr> <tr valign="top"><td><code>stat.prob</code></td> <td> <p>Logical scalar. This is to collect the stationary probability <code>p</code> when dealing with stochastic matrices.</p> </td></tr> </table> <h3>Details</h3> <p>Please see <a href="scg-method.html">scg-method</a> for an introduction. </p> <p>In the following <i>V</i> is the matrix of eigenvectors for which the SCG is solved. <i>V</i> is calculated from <code>X</code>, if it is not given in the <code>evec</code> argument. </p> <p>The algorithm “optimum” solves exactly the SCG problem for each eigenvector in <code>V</code>. The running time of this algorithm is <i>O(max(nt) m^2)</i> for the symmetric and laplacian matrix problems (i.e. when <code>mtype</code> is “symmetric” or “laplacian”. It is <i>O(m^3)</i> for the stochastic problem. Here <i>m</i> is the number of rows in <code>V</code>. In all three cases, the memory usage is <i>O(m^2)</i>. </p> <p>The algorithms “interv” and “interv_km” solve approximately the SCG problem by performing a (for now) constant binning of the components of the eigenvectors, that is <code>nt[i]</code> constant-size bins are used to partition <code>V[,i]</code>. When <code>algo</code> = “interv_km”, the (Lloyd) k-means algorithm is run on each partition obtained by “interv” to improve accuracy. </p> <p>Once a minimizing partition (either exact or approximate) has been found for each eigenvector, the final grouping is worked out as follows: two vertices are grouped together in the final partition if they are grouped together in each minimizing partition. In general the size of the final partition is not known in advance when <code>ncol(V)</code>>1. </p> <p>Finally, the algorithm “exact_scg” groups the vertices with equal components in each eigenvector. The last three algorithms essentially have linear running time and memory load. </p> <h3>Value</h3> <table summary="R valueblock"> <tr valign="top"><td><code>Xt</code></td> <td> <p>The coarse-grained graph, or matrix, possibly a sparse matrix.</p> </td></tr> <tr valign="top"><td><code>groups</code></td> <td> <p>A vector of <code>nrow(X)</code> or <code>vcount(X)</code> integers giving the group label of each object (vertex) in the partition.</p> </td></tr> <tr valign="top"><td><code>L</code></td> <td> <p>The semi-projector <i>L</i> if <code>semproj = TRUE</code>.</p> </td></tr> <tr valign="top"><td><code>R</code></td> <td> <p>The semi-projector <i>R</i> if <code>semproj = TRUE</code>.</p> </td></tr> <tr valign="top"><td><code>values</code></td> <td> <p>The computed eigenvalues if <code>epairs = TRUE</code>.</p> </td></tr> <tr valign="top"><td><code>vectors</code></td> <td> <p>The computed or supplied eigenvectors if <code>epairs = TRUE</code>.</p> </td></tr> <tr valign="top"><td><code>p</code></td> <td> <p>The stationary probability vector if <code>mtype = stochastic</code> and <code>stat.prob = TRUE</code>. For other matrix types this is missing.</p> </td></tr> </table> <h3>Author(s)</h3> <p>David Morton de Lachapelle, <a href="http://people.epfl.ch/david.morton">http://people.epfl.ch/david.morton</a>. </p> <h3>References</h3> <p>D. Morton de Lachapelle, D. Gfeller, and P. De Los Rios, Shrinking Matrices while Preserving their Eigenpairs with Application to the Spectral Coarse Graining of Graphs. Submitted to <em>SIAM Journal on Matrix Analysis and Applications</em>, 2008. <a href="http://people.epfl.ch/david.morton">http://people.epfl.ch/david.morton</a> </p> <h3>See Also</h3> <p><a href="scg-method.html">scg-method</a> for an introduction. <code><a href="scg_eps.html">scg_eps</a></code>, <code><a href="scg_group.html">scg_group</a></code> and <code><a href="scg_semi_proj.html">scg_semi_proj</a></code>. </p> <h3>Examples</h3> <pre> ## We are not running these examples any more, because they ## take a long time (~20 seconds) to run and this is against the CRAN ## repository policy. Copy and paste them by hand to your R prompt if ## you want to run them. ## Not run: # SCG of a toy network g <- make_full_graph(5) %du% make_full_graph(5) %du% make_full_graph(5) g <- add_edges(g, c(1,6, 1,11, 6, 11)) cg <- scg(g, 1, 3, algo="exact_scg") #plot the result layout <- layout_with_kk(g) nt <- vcount(cg$Xt) col <- rainbow(nt) vsize <- table(cg$groups) ewidth <- round(E(cg$Xt)$weight,2) op <- par(mfrow=c(1,2)) plot(g, vertex.color = col[cg$groups], vertex.size = 20, vertex.label = NA, layout = layout) plot(cg$Xt, edge.width = ewidth, edge.label = ewidth, vertex.color = col, vertex.size = 20*vsize/max(vsize), vertex.label=NA, layout = layout_with_kk) par(op) ## SCG of real-world network library(igraphdata) data(immuno) summary(immuno) n <- vcount(immuno) interv <- c(100,100,50,25,12,6,3,2,2) cg <- scg(immuno, ev= n-(1:9), nt=interv, mtype="laplacian", algo="interv", epairs=TRUE) ## are the eigenvalues well-preserved? gt <- cg$Xt nt <- vcount(gt) Lt <- laplacian_matrix(gt) evalt <- eigen(Lt, only.values=TRUE)$values[nt-(1:9)] res <- cbind(interv, cg$values, evalt) res <- round(res,5) colnames(res) <- c("interv","lambda_i","lambda_tilde_i") rownames(res) <- c("N-1","N-2","N-3","N-4","N-5","N-6","N-7","N-8","N-9") print(res) ## use SCG to get the communities com <- scg(laplacian_matrix(immuno), ev=n-c(1,2), nt=2)$groups col <- rainbow(max(com)) layout <- layout_nicely(immuno) plot(immuno, layout=layout, vertex.size=3, vertex.color=col[com], vertex.label=NA) ## display the coarse-grained graph gt <- simplify(as.undirected(gt)) layout.cg <- layout_with_kk(gt) com.cg <- scg(laplacian_matrix(gt), nt-c(1,2), 2)$groups vsize <- sqrt(as.vector(table(cg$groups))) op <- par(mfrow=c(1,2)) plot(immuno, layout=layout, vertex.size=3, vertex.color=col[com], vertex.label=NA) plot(gt, layout=layout.cg, vertex.size=15*vsize/max(vsize), vertex.color=col[com.cg],vertex.label=NA) par(op) ## End(Not run) </pre> <hr /><div style="text-align: center;">[Package <em>igraph</em> version 1.3.5 <a href="00Index.html">Index</a>]</div> </body></html>