R/simple_net.R

# function to generate simulated network  
simple_net <-
  function(time_step, 
           alpha              = 1     ,
           mode_PA            = 1     , # mode 1: log-linear, mode 2: non-log linear, mode 3: custom PA function
           beta               = 2     ,
           custom_PA          = 1     , # assume: A_k = custom_PA[k + 1]; if out of range, then use the last value in the array
           mode_p             = 1     ,
           p_const            = 0.5   , # with probability p add a new node without any edge, with probability 1 - p add a new edge between two existing nodes
           p_max              = 0.5   ,
           p_min              = 0.01  
){
    # time_step: number of time-steps to grow the network
    
    num_seed <- 2
   
    if ((p_const < 0) || (time_step < 0))
      stop("The parameters must be non-negative")  
    
    
    num_of_row  <- num_seed + time_step 
    
    edge_list   <- matrix(nrow = num_of_row, ncol = 3,0)
    
    
    
    edge_list_index      <- 1
    current_time_step    <- 0                 # current time_step
    for (n in 1:num_seed) {
      edge_list[edge_list_index,] <- c(n, -1, current_time_step);
      edge_list_index             <- edge_list_index + 1
    } 
    current_time_step             <- current_time_step + 1
    #print(edge_list[1:(edge_list_index - 1),])
    
    degree                 <- rep(0,num_seed)
    names(degree)          <- as.integer(1:num_seed) 
    
    
    temp                   <- .generate_net_C(edge_list, degree, time_step, mode_PA, alpha,beta, custom_PA, mode_p, p_const, p_max, p_min)
    
    matrix_net             <- temp$edge_list
    deg_vec                <- temp$deg_vec
    return(list(net = matrix_net,deg_vec = deg_vec))
  }
thongphamthe/mcPAFit documentation built on May 20, 2019, 10:23 p.m.