igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Recommend Package for Bonacich Power


From: Alex D'Amour
Subject: Re: [igraph] Recommend Package for Bonacich Power
Date: Tue, 21 Jul 2009 14:14:00 -0400

Surendar,

What parameters are you using when running the routine? Exponent
should be no larger than 1/lambda where lambda is the largest
eigenvalue of the matrix. If you were using the defaults, it's very
likely that this is the reason the routine failed.

First, try evaluating evcent(g)$value to find the largest eigenvalue,
then make sure that exponent is no larger than its inverse.

It is unfortunate that the default value for this function is almost
guaranteed not to work. It might be better to reparametrize the
function such that exponent specifies the proportion of 1/lambda that
you would like to set the exponent to. So exponent =1 would correspond
to the real exponent being 1/lambda, exponent=05. would be
1/(2*lambda), etc.

Best,
Alex D'Amour
Harvard Institute for Quantitative Social Science

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.
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]