igraph-help
[Top][All Lists]

## Re: [igraph] Recommend Package for Bonacich Power(Got the program to wo

 From: Surendar Swaminathan Subject: Re: [igraph] Recommend Package for Bonacich Power(Got the program to work please check) Date: Tue, 28 Jul 2009 12:47:03 -0700

Hello Alex,

How are you?. Thank you very much for the information.I got the result for the bonacich power. I used Scale= FALSE in

eigen<-evcent(g,scale=FALSE,weights=NULL,options=igraph.arpack.default) and found out the largest value and took  the inverse of the same and substituted the value for exponent in bonpow.sparse function.

I am posting the graph object along with this mail.Can you check them and let me know whether I have done any mistakes in them.

What I am using is undirected Garph and using R version 2.9.0 and Igraph version 0.5.2-2

Thank youv ery much for helping again

Help on this would be great.

I am using igraph package R version 2.9.0

R version 2.9.0 (2009-04-17)
i386-pc-mingw32
locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
other attached packages:
[1] igraph_0.5.2-2

Code on evcent

eigen<-evcent (g, scale = FALSE, weights = NULL, options = igraph.arpack.default)
evcent(g)\$value=106.43

for bonacich power sparse matrix

bonpow.sparse <- function(graph, nodes=V(graph), loops=FALSE,
exponent=0.00939514083316109, rescale=TRUE, tol=1e-07) {
## remove loops if requested

vg <- vcount(graph)
## sparse identity matrix
id <- Diagonal(vg)
## solve it
ev <- solve(id - exponent * d, degree(graph, mode="all"), tol=tol)
if (rescale) {
ev <- ev/sum(ev)
} else {
ev <- ev * sqrt(vcount(graph)/sum((ev)^2))
}
ev[as.numeric(nodes) + 1]
}
bonpower=bonpow.sparse(g)
bonacich<-data.frame(PERSON=V(g)\$name,bonpow=bonpower)
write.csv(bonacich,"  output.csv")

Please click on the above link and the graph objects get downloaded and you can start using them you can see the objects I created using ls().

Once again Thank you very much

Surendar

On Tue, Jul 21, 2009 at 11:41 AM, Surendar Swaminathan wrote:
Thank you very much Alex for the insight. I will try this and also please keep tab on this thread.

Thank you Alex once again

Surendar

On Tue, Jul 21, 2009 at 11:14 AM, Alex D'Amour wrote:
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
> 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()
>    }
>    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]
>
>
>
>
> _______________________________________________
> igraph-help mailing list
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>
>

_______________________________________________
igraph-help mailing list