#StackBounty: #r #network-programming #simulation #igraph Adding ties in a network based on node attribute (weight)

Bounty: 100

I am simulating network change over time using igraph in r and am looking for an efficient and scalable way to code this for use in business.

The main drivers of network change are:

  • New nodes
  • New ties
  • New node weights

In the first stage, in the network of 100 nodes 10% are randomly connected. The node weights are also assigned at random. The network is undirected. There are 100 stages.

In each of the following stages:

  • Ten (10) new nodes occur randomly and are added to the model. They are unconnected in this stage.
  • The node weights of these new nodes are assigned at random.
  • The new ties between two nodes in time t+1 are a probabilistic function of the network distance between these nodes in the network and the node weight at previous stage (time t). Nodes at greater network distance are less likely to connect than nodes nodes at shorter distance. The decay function is exponential.
  • Nodes with greater weight attract more ties than those with smaller weights. The relationship between node weight and increased probability of tie-formation should be super-linear.
  • In each step, 10% of the total existing ties is added as a function what the previous point.
  • The network ties and nodes from previous stages are carried over (i.e. the networks are cumulative).
  • At each stage, the node weight can change randomly up to 10% of its current weight (i.e. a weight of 1 can change to {0.9-1.1} in t+1)
  • At each stage, the network needs to be saved.

How can this be written?

Edit: these networks will be examined on a number of graph-level characteristics at a later stage

This is what I have now, but doesn’t include the node weights. How do we include this efficiently?

# number of nodes and ties to start with (i.e. 1836)
n = 100
p = 0.1

# build random network
net1 <- erdos.renyi.game(n, p, "gnp", directed = F)
write_graph(net1, paste0("D://network_sim_0.dl"), format="pajek")

for(i in seq(1,100,1)){

time <- proc.time()

net1 <- read_graph(paste0("D://network_sim_",i-1,".dl"), format="pajek")  

# how many will we build in next stage?
new_ties <- round(0.1*ecount(net1), 0)  # 10% of those in net1

# add 10 new nodes
net2 <- add_vertices(net1, 10)

# get network distance for each dyad in net1 + the new nodes
spel <- data.table::melt(shortest.paths(net2))
names(spel) <- c("node_i", "node_j", "distance")

# replace inf with max observed value + 1
spel$distance[which(!is.finite(spel$distance))] <- max(spel$distance[is.finite(spel$distance)]) +1

# assign a probability (?) with a exponential decay function. Smallest distance == greatest prob.
spel$prob <- exp(-0.5, spel$distance))   # is this what I need?
#hist(spel$prob, freq=T, xlab="Probability of tie-formation")
#hist(spel$distance, freq=T, xlab="Network Distance")

# lets sample new ties from this probability
spel$index <- seq_along(spel$prob)
to_build <- subset(spel, index %in% sample(spel$index, size = new_ties, prob=spel$prob))
net2 <- add_edges(net2, as.numeric(unlist(str_split(paste(to_build$node_i, to_build$node_j), " "))))

# save the network
write_graph(net2, paste0("D://network_sim_",i,".dl"), format="pajek")



Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.