0

I want (bit curious) to know is there any other algorithm possible for preferential attachment network. I want R code. I write something and that is work for me

My Code

t1 <- 50
int.adj.mat <- matrix(c(0,1,1,0), nrow = 2) 
p <- c(0.5,0.5)
for (i in 2:t1) {
p <- rowSums(int.adj.mat)/sum(int.adj.mat)
d <- rbinom(i, 1, p)
int.adj.mat <- rbind(cbind(int.adj.mat, d), c(d,0))
}
PA <- matrix(0, nrow = NROW(int.adj.mat), ncol = NCOL(int.adj.mat))
for (i in 1:nrow(int.adj.mat)) {
PA[,i] <- int.adj.mat[,i]
}

library(igraph) #For plotting
network <- graph_from_adjacency_matrix(PA, mode = "undirected")
plot(network, vertex.size = 3, vertex.label = NA)

Output

enter image description here

This code is actually increases the order of adjacency matrix when a new node is arrived in the pre-existing network. There are several article available see (pa1 and pa2) where author describe several algorithms. But it is hard to implement in R. Any improvised version of algorithm written in R is appreciated.

This question is completely for self-study and knowledge purpose.

2
  • This question is not phrased very clearly, but it seems that you are asking two things: (1) efficient algorithms for sampling from the preferential attachment model (2) implementations of these in R. If you are looking to study graph algorithms, I strongly suggest you drop R. It is not a language suitable for algorithm development. It lacks many data structures that would be useful in that context and it makes it difficult to implement new non-trivial data structures. Commented Sep 3, 2022 at 8:47
  • The key to an efficient implementation is generating random variates from a dynamically updated discrete distribution (probability of attachment is proportional to degrees, but degrees change as the graph grows). You can take a look at igraph's psumtree data structure, implemented in C, but also well commented and easy to follow. Commented Sep 3, 2022 at 8:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.