Hi Thomas, 1) instead of length(degree(g)), just use vcount(g)
2) neighbors(g, node1) can be queried outside the interval while() loop and then stored in a temporary variable because it won't change during the lifetime of the inner loop 3) if you are sampling from the range 1:n, use sample.int() instead of sample() 4) instead of rbinom(1, 1, p), use runif(1)<p -- it is probably faster I think this should make things faster -- let me know if it is still too slow. -- T. On 24 Oct 2013, at 15:10, Thomas <[email protected]> wrote: > I'm creating a sample of nodes according to the random walk procedure > described in Section 3.3.3 of: > > http://www.stat.cmu.edu/~fienberg/Stat36-835/Leskovec-sampling-kdd06.pdf > > The following R code samples no less than 300 nodes, although it might sample > the same node twice but it runs really slowly. Does anyone know why it might > be going so slow? Is there any better way to do this? > > Thank you, > > Thomas > > #Random Walk Sample of nodes from network g > #Read graph g in as UNDIRECTED > > A <- sample(1:length(degree(g)), 1) > oput <- c() > oput <- c(oput, A) > flag <- FALSE > count <- 1 > > while(count <= 300) > { > node1 <- A > while(flag==FALSE) > { > node2 <- sample(neighbors(g,node1),1) > oput <- c(oput, node2) > count <- count + 1 > node1 <- node2 > if(rbinom(1,1,0.15)==1){flag=TRUE} > }#end of while flag loop > }#end of while count loop > This message and any attachment are intended solely for the addressee and may > contain confidential information. If you have received this message in error, > please send it back to me, and immediately delete it. Please do not use, > copy or disclose the information contained in this message or in any > attachment. Any views or opinions expressed by the author of this email do > not necessarily reflect the views of the University of Nottingham. > > This message has been checked for viruses but the contents of an attachment > may still contain software viruses which could damage your computer system, > you are advised to perform your own checks. Email communications with the > University of Nottingham may be monitored as permitted by UK legislation. > > > > > > _______________________________________________ > igraph-help mailing list > [email protected] > https://lists.nongnu.org/mailman/listinfo/igraph-help _______________________________________________ igraph-help mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/igraph-help
