On Tue, Jul 21, 2009 at 2:08 PM, Surendar
Swaminathan<
address@hidden> wrote:
> Hello All,
>
> There was Solve Matrix Package error when trying to do Bonaicih power for
> large graph. R version 2.8.1 Can someone recommend a package to work on
> Philip bonacich power.
>
> I posted the same long time back and was directed to the code.
>
>
http://igraph.wikidot.com/r-recipes#toc6 this is the output I had got
>
> solve() errors and crashes
>
> I posted the error on R user list and was told to use different code still I
> could not solve the problem
> ##
> ### "Enhanced" by Martin Maechler:
> bonpow.sparse <- function(graph, nodes = V(graph), loops = FALSE,
> exponent = 1, adj.type = "both",
> trace = TRUE,
> rescale=FALSE, tol=1e-07)
> {
> stopifnot(require("igraph"),
> require("Matrix"))
> if(trace) {
> c.width <- 30
> C1 <- function(s) cat(sprintf("%-*s .. ", c.width, s))
> C2 <- function() cat("[Ok]\n")
> } else { C1 <- C2 <- function(...) {} }
> ## remove loops if requested
> if (!loops) {
> C1("simplify()ing graph")
> graph <- simplify(graph, remove.multiple=FALSE, remove.loops=TRUE)
> C2()
> }
> ## sparse adjacency matrix
> C1("d <- get.adjacency(., sparse)")
> d <- get.adjacency(graph, type = adj.type, sparse=TRUE); C2()
> if(trace >= 2)
> cat("class(d): ", class(d),"\n")
> if(!is.directed(graph)) {
> ## MM: unfortunately "igraph" does not return a *symmetric*
> ## --- sparse matrix directly, saving space and time,
> ## so we at least do it now :
> C1("d <- as(d, \"symmetricMatrix\")")
> d <- as(d, "symmetricMatrix"); C2()
> }
> ## sparse identity matrix
> vg <- vcount(graph)
> if(FALSE) { ## "non-sense" :
> C1("spMatrix(.) for Diagonal(vg)")
> id <- spMatrix(vg, vg, i=1:vg, j=1:vg, x = rep(1, vg)); C2()
> C1(" --> as(., \"dgCMatrix\")")
> id <- as(id, "dgCMatrix"); C2()
> }
> else
> id <- Diagonal(vg)
> C1("M <- (id - exponent * d)")
> M <- id - exponent * d ; C2()
> C1("b <- degree(graph,.)")
> b <- degree(graph, mode="out") ; C2()
> if(trace >= 2) {
> cat(" M : class ", class(M),"; dim: ", dim(M),"\n")
> cat(" b : class ", class(b),"; length: ", length(b),"\n")
> }
> ## solve it
> ## MM: This is "the horror" -- ("it's the economy, stupid !!")
> ## particularly as solve(M) is *never* sparse !!!
> ## He should use solve(M, b) !!
> if(FALSE) {
> C1("solve(M) %*% b")
> ev <- solve(M, tol=tol) %*% b; C2()
> } else {
> C1("solve(M, b)")
> ev <- solve(M, b) ; C2()
> }
> if (rescale) {
> ev <- ev/sum(ev)
> } else {
> ev <- ev * sqrt(vg/sum((ev)^2))
> - Hide quoted text -
> }
> ev[as.numeric(nodes) + 1]
>
>
>
> Thanks in Advance.
>