Re: [R] Matrix package,solve() errors and crashes Please help

2009-05-18 Thread Surendar Swaminathan
Hello Martin,

  Thank you very much for the reply. Thanks for solving the problem earlier
I was not aware of it.I did not receive any message and that is what made me
to post it again. Thank you once again.

I will let the person know about the solve(a,Matrix(b))

I still have this doubt.I still get the error message

*Error in solve(a, Matrix(b)) :
  cs_lu(A) failed: near-singular A (or out of memory)*
**

Am I doing any mistake.

I made changes to your program and tried still I got the above error. So, I
planned to stick to the program that you sent and still I get the same
error.

simplify()ing graph.. [Ok]
d <- get.adjacency(., sparse)  .. [Ok]
d <- as(d, "symmetricMatrix")  .. [Ok]
M <- (id - exponent * d)   .. [Ok]
b <- degree(graph,.)   .. [Ok]
solve(M, b).. Error in solve(a, Matrix(b)) :
  cs_lu(A) failed: near-singular A (or out of memory)
Is there anything I am missing from your program or something I should do
before running your program

Please help

Thanks in Advance

Nathan
On Sat, May 16, 2009 at 7:31 AM, Martin Maechler  wrote:

> > "SS" == Surendar Swaminathan 
> > on Fri, 15 May 2009 15:55:23 -0700 writes:
>
>>> Hello All,
>>>
>SS> Please help me with this problem.I have been having this problem for
> over a
>SS> month now and I could not find any information.I later realised that
> error
>SS> is with MATRIX package.
>
> [...]
>
>
>SS> This is my graph object.
>SS> The file 'Bonacich Power.RData' (1.5 MB) is available for download
> at
>SS> <
>SS>
> http://dropbox.unl.edu/uploads/20090522/7a0d0313f21fd6a8/Bonacich%20Power.RData
>
> [...]
>
> and you have asked almost the idetnical question 4 weeks ago,
> and got a first answer, but then not a *real* answer.
> I'm sorry for that, since I had started answering you,
> and even more as I *did* solve the problem back then.. (April 22).
>
> more below ...
>
>SS> computer Configuration
>
>SS> *WIndows XP service Pack 3 .0 GB RAM*
>
>SS> I am using SPARSE matrix to solve the problem
>SS> This is the code I use to obtain bonpower using Sparse Matrix &
>SS> alternatively the code is in the following website
>
>SS> http://igraph.wikidot.com/r-recipes#toc6
>
> I'm really appaled that "R-recipes" on such a website give
> such an unprofessional advice
>
>
> {the following is so grabled because of your (implicit)
>  insistence on using HTML-ified e-mail .. }
>
>SS> *bonpow.sparse <- function(graph, nodes=V(graph), loops=FALSE,
>SS> exponent=1, rescale=TRUE, tol=1e-07) {*
>SS> *  ## remove loops if requested
>SS> *
>SS> *  ## sparse adjacency matrix
>SS> d <- get.adjacency(graph, sparse=TRUE)*
>SS> *  ## sparse identity matrix
>SS> id <- spMatrix(vcount(graph), vcount(graph),
>SS> i=1:vcount(graph), j=1:vcount(graph),
>SS> x=rep(1, vcount(graph)))
>SS> id <- as(id, "dgCMatrix")*
>SS> *  ## solve it
>   SS> ev <- solve(id - exponent * d, tol=tol) %*% degree(graph,
> mode="all")*
>SS> *  if (rescale) {
>SS> ev <- ev/sum(ev)
>SS> } else {
>SS> ev <- ev * sqrt(vcount(graph)/sum((ev)^2))
>SS> }*
>SS> *  ev[as.numeric(nodes) + 1]
>SS> }*
>SS> **
>SS> I realised that the error is in Matrix Package
>SS> *Error: cannot allocate vector of size 3.3 Gb
>SS> In addition: Warning messages:
>SS> 1: In solve(id - exponent * d, tol = tol) :
>SS> Reached total allocation of 1535Mb: see help(memory.size)
>SS> 2: In solve(id - exponent * d, tol = tol) :
>SS> Reached total allocation of 1535Mb: see help(memory.size)
>SS> 3: In solve(id - exponent * d, tol = tol) :
>SS> Reached total allocation of 1535Mb: see help(memory.size)
>SS> 4: In solve(id - exponent * d, tol = tol) :
>SS> Reached total allocation of 1535Mb: see help(memory.size)*
>SS> **
>SS> sessionInfo()
>SS> R version 2.9.0 (2009-04-17)
>
> [ . ] {irrelevant here}
>
>
>SS> Please help Matrix Experts
>
> Well, I've marked the one line above
>
>  ev <- solve(id - exponent * d, tol=tol) %*% degree(graph, mode="all")*
>
> 
> which really contains stupid advice.
> Yes, this is strongly put, but I think people who tell you to
> solve
>
>A x = b  (A [n x n] matrix)
>
> in R by  x <- solve(A) %*% b
> should not give advice on programming at all.
> 
>
> One of the proper advices would use
> x <- solve(A, b)
>
> and indeed that's even more crucial in the case where  A  is
> sparse matrix:  solve(A) is never sparse for sparse A (*),
> but   solve(A, b)  can happen with a fast (and memory-efficient)
> algorithm, and that's what happens also when you use the Matrix package.
> I append a version of your function that is also slightly
> improved in other places.
>
> (*) and that's why your memory blows up when A is large and sparse !
>
>SS> Thanks in advance
>SS> Nathan
>
>SS> [[alternative HTML version deleted]]
>
> (stil

Re: [R] Matrix package,solve() errors and crashes Please help

2009-05-16 Thread Martin Maechler
> "SS" == Surendar Swaminathan 
> on Fri, 15 May 2009 15:55:23 -0700 writes:

>> Hello All,
>> 
SS> Please help me with this problem.I have been having this problem for 
over a
SS> month now and I could not find any information.I later realised that 
error
SS> is with MATRIX package.

[...]


SS> This is my graph object.
SS> The file 'Bonacich Power.RData' (1.5 MB) is available for download at
SS> <
SS> 
http://dropbox.unl.edu/uploads/20090522/7a0d0313f21fd6a8/Bonacich%20Power.RData

[...]

and you have asked almost the idetnical question 4 weeks ago,
and got a first answer, but then not a *real* answer.
I'm sorry for that, since I had started answering you, 
and even more as I *did* solve the problem back then.. (April 22).

more below ...

SS> computer Configuration

SS> *WIndows XP service Pack 3 .0 GB RAM*

SS> I am using SPARSE matrix to solve the problem
SS> This is the code I use to obtain bonpower using Sparse Matrix &
SS> alternatively the code is in the following website

SS> http://igraph.wikidot.com/r-recipes#toc6

I'm really appaled that "R-recipes" on such a website give 
such an unprofessional advice


{the following is so grabled because of your (implicit)
 insistence on using HTML-ified e-mail .. }

SS> *bonpow.sparse <- function(graph, nodes=V(graph), loops=FALSE,
SS> exponent=1, rescale=TRUE, tol=1e-07) {*
SS> *  ## remove loops if requested
SS> *
SS> *  ## sparse adjacency matrix
SS> d <- get.adjacency(graph, sparse=TRUE)*
SS> *  ## sparse identity matrix
SS> id <- spMatrix(vcount(graph), vcount(graph),
SS> i=1:vcount(graph), j=1:vcount(graph),
SS> x=rep(1, vcount(graph)))
SS> id <- as(id, "dgCMatrix")*
SS> *  ## solve it
  SS> ev <- solve(id - exponent * d, tol=tol) %*% degree(graph, mode="all")*
SS> *  if (rescale) {
SS> ev <- ev/sum(ev)
SS> } else {
SS> ev <- ev * sqrt(vcount(graph)/sum((ev)^2))
SS> }*
SS> *  ev[as.numeric(nodes) + 1]
SS> }*
SS> **
SS> I realised that the error is in Matrix Package
SS> *Error: cannot allocate vector of size 3.3 Gb
SS> In addition: Warning messages:
SS> 1: In solve(id - exponent * d, tol = tol) :
SS> Reached total allocation of 1535Mb: see help(memory.size)
SS> 2: In solve(id - exponent * d, tol = tol) :
SS> Reached total allocation of 1535Mb: see help(memory.size)
SS> 3: In solve(id - exponent * d, tol = tol) :
SS> Reached total allocation of 1535Mb: see help(memory.size)
SS> 4: In solve(id - exponent * d, tol = tol) :
SS> Reached total allocation of 1535Mb: see help(memory.size)*
SS> **
SS> sessionInfo()
SS> R version 2.9.0 (2009-04-17)

 [ . ] {irrelevant here}


SS> Please help Matrix Experts

Well, I've marked the one line above

 ev <- solve(id - exponent * d, tol=tol) %*% degree(graph, mode="all")*

 
which really contains stupid advice.
Yes, this is strongly put, but I think people who tell you to
solve

A x = b  (A [n x n] matrix)

in R by  x <- solve(A) %*% b
should not give advice on programming at all.


One of the proper advices would use
 x <- solve(A, b)

and indeed that's even more crucial in the case where  A  is
sparse matrix:  solve(A) is never sparse for sparse A (*),
but   solve(A, b)  can happen with a fast (and memory-efficient)
algorithm, and that's what happens also when you use the Matrix package.
I append a version of your function that is also slightly
improved in other places.

(*) and that's why your memory blows up when A is large and sparse !

SS> Thanks in advance
SS> Nathan

SS> [[alternative HTML version deleted]]

(still   It would *really* help if you used a more sensible e-mail
 configuration  }

Regards,
Martin Maechler

---

Here's the corrected bonpow.sparse() function , actually with
extra code for diagnostic output, etc.
You should probably simplify it again :

## I got help from IGRAPH community to use sparse Matrix
##
## http://igraph.wikidot.com/r-recipes#toc6
##
### "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): ", clas

Re: [R] Matrix package,solve() errors and crashes Please help

2009-05-15 Thread Surendar Swaminathan
>
> Hello All,
>
Please help me with this problem.I have been having this problem for over a
month now and I could not find any information.I later realised that error
is with MATRIX package.

I am working on graph object using IGRAPH version 0.5.2-2 package &  wanted
to do Bonacich Power.

What I have is undirected GRAPH.

This is my graph object.
  The file 'Bonacich Power.RData' (1.5 MB) is available for download at
<
http://dropbox.unl.edu/uploads/20090522/7a0d0313f21fd6a8/Bonacich%20Power.RData
>

Graph size

*Vertices: 20924
Edges: 146938
Directed: FALSE
No graph attributes.
Vertex attributes: name.
No edge attributes.
*

computer Configuration

*WIndows XP service Pack 3 .0 GB RAM*

I am using SPARSE matrix to solve the problem
This is the code I use to obtain bonpower using Sparse Matrix &
alternatively the code is in the following website

http://igraph.wikidot.com/r-recipes#toc6

*bonpow.sparse <- function(graph, nodes=V(graph), loops=FALSE,
  exponent=1, rescale=TRUE, tol=1e-07) {*
*  ## remove loops if requested
  *
*  ## sparse adjacency matrix
  d <- get.adjacency(graph, sparse=TRUE)*
*  ## sparse identity matrix
  id <- spMatrix(vcount(graph), vcount(graph),
 i=1:vcount(graph), j=1:vcount(graph),
 x=rep(1, vcount(graph)))
  id <- as(id, "dgCMatrix")*
*  ## solve it
  ev <- solve(id - exponent * d, tol=tol) %*% degree(graph, mode="all")*
*  if (rescale) {
ev <- ev/sum(ev)
  } else {
ev <- ev * sqrt(vcount(graph)/sum((ev)^2))
  }*
*  ev[as.numeric(nodes) + 1]
}*
**
I realised that the error is in Matrix Package
 *Error: cannot allocate vector of size 3.3 Gb
In addition: Warning messages:
1: In solve(id - exponent * d, tol = tol) :
  Reached total allocation of 1535Mb: see help(memory.size)
2: In solve(id - exponent * d, tol = tol) :
  Reached total allocation of 1535Mb: see help(memory.size)
3: In solve(id - exponent * d, tol = tol) :
  Reached total allocation of 1535Mb: see help(memory.size)
4: In solve(id - exponent * d, tol = tol) :
  Reached total allocation of 1535Mb: see help(memory.size)*
**
sessionInfo()
 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] Matrix_0.999375-24 lattice_0.17-22igraph_0.5.2-2
loaded via a namespace (and not attached):
[1] grid_2.9.0

Please help Matrix Experts

Thanks in advance

Nathan

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Matrix package,solve() errors and crashes

2009-04-22 Thread Surendar Swaminathan
Hello Martin,

 Thanks for looking in to the problem. My mistake, I pasted the code for
sparse matrix for the graph that was created by

test.g <- simplify(ba.game(1000,m=2))

What I was intending to show was I have a graph object "g" created by
IGRPAH. Please find the link that has the graph object.

http://dropbox.unl.edu/uploads/20090424/cfe4fcb854bb17f2/Graph.RData

Substituting this graph object to the argument in the sparse Matrix gives
the error.

Also I have pasted the link for the sparse Matrix code & the thread I had
posted to IGraph community about the error.

Code (http://igraph.wikidot.com/r-recipes#toc6)

Thread
http://www.google.com/search?q=bonpowe+crashes&sourceid=ie7&rls=com.microsoft:en-US&ie=utf8&oe=utf8&rlz=1I7DKUS_en

I substituted my Graph Object in the code.It says error.

Hope I have explained properly.

Thanks in advance Martin

Nathan







On Tue, Apr 21, 2009 at 6:13 AM, Martin Maechler  wrote:

> > "SS" == Surendar Swaminathan 
> > on Mon, 20 Apr 2009 12:10:47 -0700 writes:
>
>SS> Hello All, I am working on graph object using IGRAPH
>SS> package wanted to do Bonacich Power.  This is my graph
>SS> object.
>
>SS> The file 'Graph.RData' (4.2 MB) is available for
>SS> download at
>SS>
> http://dropbox.unl.edu/uploads/20090424/cfe4fcb854bb17f2/Graph.RData
>
>SS> Graph size
>
>SS> Vertices: 20984 Edges: 326033 Directed: FALSE No graph
>SS> attributes.  Vertex attributes: name.  No edge
>SS> attributes.
>
>SS> When I use bonacich power it goes out of memory
>
>SS> Error in get.adjacency.dense(graph, type = type, attr =
>SS> attr, names = names, : At vector.pmt:409 : cannot
>SS> reserve space for vector, Out of memory
>
> how much memory (RAM) has your computer?
>
> I have tried in a few ways to reproduce your problem,
> but have not got any errors, neither when using the 'test.g'
> example you use below, nor by using
>bonpow.sparse(g)
> where 'g' comes from your  'Graph.RData' file (you mention above).
>
> But you have not provided (in your e-mail) a fully reproducible
> example, so I am not sure how exactly you got the memory problem
> (or even worse the "crash"es).
>
> Regards,
> Martin Maechler, ETH Zurich
> (co-maintainer of 'Matrix').
>
>SS> I got help from IGRAPH community to use sparse Matrix
>
>SS> http://igraph.wikidot.com/r-recipes#toc6
>
>SS> bonpow.sparse <- function(graph, nodes=V(graph),
>SS> loops=FALSE, exponent=1, rescale=FALSE, tol=1e-07) {
>
>SS>   ## remove loops if requested if (!loops) { graph <-
>SS> simplify(graph, remove.multiple=FALSE,
>SS> remove.loops=TRUE) }
>
>SS>   ## sparse adjacency matrix d <- get.adjacency(graph,
>SS> sparse=TRUE)
>
>SS>   ## sparse identity matrix id <-
>SS> spMatrix(vcount(graph), vcount(graph),
>SS> i=1:vcount(graph), j=1:vcount(graph), x=rep(1,
>SS> vcount(graph))) id <- as(id, "dgCMatrix")
>
>SS>   ## solve it ev <- solve(id - exponent * d, tol=tol)
>SS> %*% degree(graph, mode="out")
>
>SS>   if (rescale) { ev <- ev/sum(ev) } else { ev <- ev *
>SS> sqrt(vcount(graph)/sum((ev)^2)) }
>
>SS>   ev[as.numeric(nodes) + 1] }
>
>SS> ## test graph test.g <- simplify(ba.game(1000,m=2))
>
>SS> ## test run system.time(bp1 <- bonpow(test.g))
>SS> system.time(bp2 <- bonpow.sparse(test.g))
>
>SS> ## check that they are the same max(abs(bp1-bp2)) I get
>SS> following error and sometime it crashes.
>
>SS> In solve(id - exponent * d, tol = tol) : Reached total
>SS> allocation of 1535Mb: see help(memory.size).I increased
>SS> the memory size and still it is not helpful
>
>SS> Help on this would be great.
>
>SS> These are steps I followed
>
>SS> 1. Created graph object using Igraph version 0.6 on R
>SS> 2.8.1 windows XP 2. Bonpow(g) 3. Bonpow.sparse function
>
>SS> sessionInfo()
>
>SS> R version 2.8.1 (2008-12-22) i386-pc-mingw32 locale:
>SS> LC_COLLATE=English_United
>SS> States.1252;LC_CTYPE=English_United
>SS> States.1252;LC_MONETARY=English_United
>SS> States.1252;LC_NUMERIC=C;LC_TIME=English_United
>SS> States.1252 attached base packages: [1] stats graphics
>SS> grDevices utils datasets methods base other attached
>SS> packages: [1] Matrix_0.999375-23 lattice_0.17-20
>SS> igraph_0.6 loaded via a namespace (and not attached):
>SS> [1] grid_2.8.1
>
>SS> Thanks in advance
>
>SS> Nathan
>
>SS> [[alternative HTML version deleted]]
>
>SS> __
>SS> R-help@r-project.org mailing list
>SS> https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
>SS> read the posting guide
>SS> 
> http://www.R-project.org/posting-guide.htmland
>  provide
>SS> commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]


Re: [R] Matrix package,solve() errors and crashes

2009-04-21 Thread Martin Maechler
> "SS" == Surendar Swaminathan 
> on Mon, 20 Apr 2009 12:10:47 -0700 writes:

SS> Hello All, I am working on graph object using IGRAPH
SS> package wanted to do Bonacich Power.  This is my graph
SS> object.

SS> The file 'Graph.RData' (4.2 MB) is available for
SS> download at
SS> http://dropbox.unl.edu/uploads/20090424/cfe4fcb854bb17f2/Graph.RData

SS> Graph size

SS> Vertices: 20984 Edges: 326033 Directed: FALSE No graph
SS> attributes.  Vertex attributes: name.  No edge
SS> attributes.

SS> When I use bonacich power it goes out of memory

SS> Error in get.adjacency.dense(graph, type = type, attr =
SS> attr, names = names, : At vector.pmt:409 : cannot
SS> reserve space for vector, Out of memory

how much memory (RAM) has your computer?

I have tried in a few ways to reproduce your problem,
but have not got any errors, neither when using the 'test.g'
example you use below, nor by using  
bonpow.sparse(g)
where 'g' comes from your  'Graph.RData' file (you mention above).

But you have not provided (in your e-mail) a fully reproducible
example, so I am not sure how exactly you got the memory problem
(or even worse the "crash"es).

Regards,
Martin Maechler, ETH Zurich
(co-maintainer of 'Matrix').

SS> I got help from IGRAPH community to use sparse Matrix

SS> http://igraph.wikidot.com/r-recipes#toc6

SS> bonpow.sparse <- function(graph, nodes=V(graph),
SS> loops=FALSE, exponent=1, rescale=FALSE, tol=1e-07) {

SS>   ## remove loops if requested if (!loops) { graph <-
SS> simplify(graph, remove.multiple=FALSE,
SS> remove.loops=TRUE) }

SS>   ## sparse adjacency matrix d <- get.adjacency(graph,
SS> sparse=TRUE)

SS>   ## sparse identity matrix id <-
SS> spMatrix(vcount(graph), vcount(graph),
SS> i=1:vcount(graph), j=1:vcount(graph), x=rep(1,
SS> vcount(graph))) id <- as(id, "dgCMatrix")

SS>   ## solve it ev <- solve(id - exponent * d, tol=tol)
SS> %*% degree(graph, mode="out")

SS>   if (rescale) { ev <- ev/sum(ev) } else { ev <- ev *
SS> sqrt(vcount(graph)/sum((ev)^2)) }

SS>   ev[as.numeric(nodes) + 1] }

SS> ## test graph test.g <- simplify(ba.game(1000,m=2))

SS> ## test run system.time(bp1 <- bonpow(test.g))
SS> system.time(bp2 <- bonpow.sparse(test.g))

SS> ## check that they are the same max(abs(bp1-bp2)) I get
SS> following error and sometime it crashes.

SS> In solve(id - exponent * d, tol = tol) : Reached total
SS> allocation of 1535Mb: see help(memory.size).I increased
SS> the memory size and still it is not helpful

SS> Help on this would be great.

SS> These are steps I followed

SS> 1. Created graph object using Igraph version 0.6 on R
SS> 2.8.1 windows XP 2. Bonpow(g) 3. Bonpow.sparse function

SS> sessionInfo()

SS> R version 2.8.1 (2008-12-22) i386-pc-mingw32 locale:
SS> LC_COLLATE=English_United
SS> States.1252;LC_CTYPE=English_United
SS> States.1252;LC_MONETARY=English_United
SS> States.1252;LC_NUMERIC=C;LC_TIME=English_United
SS> States.1252 attached base packages: [1] stats graphics
SS> grDevices utils datasets methods base other attached
SS> packages: [1] Matrix_0.999375-23 lattice_0.17-20
SS> igraph_0.6 loaded via a namespace (and not attached):
SS> [1] grid_2.8.1

SS> Thanks in advance

SS> Nathan

SS> [[alternative HTML version deleted]]

SS> __
SS> R-help@r-project.org mailing list
SS> https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
SS> read the posting guide
SS> http://www.R-project.org/posting-guide.html and provide
SS> commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Matrix package,solve() errors and crashes

2009-04-20 Thread Surendar Swaminathan
Hello All,

  I am working on graph object using IGRAPH package wanted to do Bonacich
Power.  This is my graph object.

The file 'Graph.RData' (4.2 MB) is available for download at
http://dropbox.unl.edu/uploads/20090424/cfe4fcb854bb17f2/Graph.RData

Graph size

Vertices: 20984
Edges: 326033
Directed: FALSE
No graph attributes.
Vertex attributes: name.
No edge attributes.

When I use bonacich power it goes out of memory

Error in get.adjacency.dense(graph, type = type, attr = attr, names =
names,  :
  At vector.pmt:409 : cannot reserve space for vector, Out of memory

I got help from IGRAPH community to use sparse Matrix

http://igraph.wikidot.com/r-recipes#toc6

bonpow.sparse <- function(graph, nodes=V(graph), loops=FALSE,
  exponent=1, rescale=FALSE, tol=1e-07) {

  ## remove loops if requested
  if (!loops) {
graph <- simplify(graph, remove.multiple=FALSE, remove.loops=TRUE)
  }

  ## sparse adjacency matrix
  d <- get.adjacency(graph, sparse=TRUE)

  ## sparse identity matrix
  id <- spMatrix(vcount(graph), vcount(graph),
 i=1:vcount(graph), j=1:vcount(graph),
 x=rep(1, vcount(graph)))
  id <- as(id, "dgCMatrix")

  ## solve it
  ev <- solve(id - exponent * d, tol=tol) %*% degree(graph, mode="out")

  if (rescale) {
ev <- ev/sum(ev)
  } else {
ev <- ev * sqrt(vcount(graph)/sum((ev)^2))
  }

  ev[as.numeric(nodes) + 1]
}

## test graph
test.g <- simplify(ba.game(1000,m=2))

## test run
system.time(bp1 <- bonpow(test.g))
system.time(bp2 <- bonpow.sparse(test.g))

## check that they are the same
max(abs(bp1-bp2)) I get following error and sometime it crashes.

In solve(id - exponent * d, tol = tol) :
Reached total allocation of 1535Mb: see help(memory.size).I increased the
memory size and still it is not helpful

Help on this would be great.

These are steps I followed

1. Created graph object using Igraph version 0.6 on R 2.8.1 windows XP
2. Bonpow(g)
3. Bonpow.sparse function

sessionInfo()

R version 2.8.1 (2008-12-22)
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] Matrix_0.999375-23 lattice_0.17-20igraph_0.6
loaded via a namespace (and not attached):
[1] grid_2.8.1

Thanks in advance

Nathan

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Matrix package,solve() errors and crashes"

2009-04-17 Thread Surendar Swaminathan
Hello All,

  I am working on graph object using IGRAPH package wanted to do Bonacich
Power.  This is my graph object.

The file 'Graph.RData' (4.2 MB) is available for download at
http://dropbox.unl.edu/uploads/20090424/cfe4fcb854bb17f2/Graph.RData

Graph size

Vertices: 20984
Edges: 326033
Directed: FALSE
No graph attributes.
Vertex attributes: name.
No edge attributes.

When I use bonacich power it goes out of memory

Error in get.adjacency.dense(graph, type = type, attr = attr, names =
names,  :
  At vector.pmt:409 : cannot reserve space for vector, Out of memory

I got help from IGRAPH community to use sparse Matrix

http://igraph.wikidot.com/r-recipes#toc6


bonpow.sparse <- function(graph, nodes=V(graph), loops=FALSE,
  exponent=1, rescale=FALSE, tol=1e-07) {

  ## remove loops if requested
  if (!loops) {
graph <- simplify(graph, remove.multiple=FALSE, remove.loops=TRUE)
  }

  ## sparse adjacency matrix
  d <- get.adjacency(graph, sparse=TRUE)

  ## sparse identity matrix
  id <- spMatrix(vcount(graph), vcount(graph),
 i=1:vcount(graph), j=1:vcount(graph),
 x=rep(1, vcount(graph)))
  id <- as(id, "dgCMatrix")

  ## solve it
  ev <- solve(id - exponent * d, tol=tol) %*% degree(graph, mode="out")

  if (rescale) {
ev <- ev/sum(ev)
  } else {
ev <- ev * sqrt(vcount(graph)/sum((ev)^2))
  }

  ev[as.numeric(nodes) + 1]
}

## test graph
test.g <- simplify(ba.game(1000,m=2))

## test run
system.time(bp1 <- bonpow(test.g))
system.time(bp2 <- bonpow.sparse(test.g))

## check that they are the same
max(abs(bp1-bp2))



I get following error and sometime it crashes.

In solve(id - exponent * d, tol = tol) :
Reached total allocation of 1535Mb: see help(memory.size).I increased the
memory size and still it is not helpful

Help on this would be great.

These are steps I followed

1. Created graph object using Igraph version 0.6 on R 2.8.1 windows XP
2. Bonpow(g)
3. Bonpow.sparse function

sessionInfo()

R version 2.8.1 (2008-12-22)
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] Matrix_0.999375-23 lattice_0.17-20igraph_0.6
loaded via a namespace (and not attached):
[1] grid_2.8.1

Thanks in advance

Nathan

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.