dprewire {wdnet}R Documentation

Degree preserving rewiring.

Description

Rewire a given network to have predetermined assortativity coefficient(s) while preserving node degree.

Usage

dprewire(
  netwk,
  edgelist,
  directed,
  adj,
  target.assortcoef = list(outout = NULL, outin = NULL, inout = NULL, inin = NULL),
  control = list(iteration = 200, nattempts = NULL, history = FALSE, cvxr_control =
    cvxr_control(), eta.obj = function(x) 0),
  eta
)

Arguments

netwk

A wdnet object representing an unweighted network. If NULL, the function will construct a network using either edgelist, or adj.

edgelist

A two column matrix, each row represents an edge of the network.

directed

Logical, whether the network is directed or not. It will be ignored if netwk is provided.

adj

An adjacency matrix of an unweighted network.

target.assortcoef

For directed networks, it is a list represents the predetermined value or range of assortativity coefficients. For undirected networks, it is a constant between -1 to 1. It will be ignored if eta is provided.

control

A list of parameters for controlling the rewiring process and the process for solving eta.

  • 'iteration' An integer, represents the number of rewiring iterations. Each iteration consists of nattempts rewiring attempts. The assortativity coefficient(s) of the network will be recorded after each iteration.

  • 'nattempts' An integer representing the number of rewiring attempts for each iteration. Default value equals the number of rows of edgelist.

  • 'history' Logical, whether the rewiring attempts should be recorded and returned.

  • 'eta.obj' A convex function of eta to be minimized when solving for eta with given target.assortcoef. Defaults to 0. It will be ignored if eta is provided.

  • 'cvxr_control' A list of parameters passed to CVXR::solve() for solving eta with given target.assortcoef. It will be ignored if eta is provided.

eta

A matrix represents the target network structure. If specified, target.assortcoef will be ignored. For directed networks, the element at row "i-j" and column "k-l" represents the proportion of directed edges linking a source node with out-degree i and in-degree j to a target node with out-degree k and in-degree l. For undirected networks, eta is symmetric, the summation of the elements at row "i", column "j" and row "j", column "i" represents the proportion of edges linking to a node with degree i and a node with degree j.

Details

The algorithm first solves for an appropriate eta using target.assortcoef, eta.obj, and cvxr_control, then proceeds to the rewiring process and rewire the network towards the solved eta. If eta is given, the algorithm will skip the first step. This function only works for unweighted networks.

Each rewiring attempt samples two rows from edgelist, for instance Edge 1:(v_1, v_2) and Edge 2:(v_3, v_4). For directed networks, if the rewiring attempt is accepted, the sampled edges are rewired as (v_1, v_4), (v_3, v_2); for undirected networks, the algorithm try to rewire the sampled edges as {v_1, v_4}, {v_3, v_2} (type 1) or {v_1, v_3}, {v_2, v_4} (type 2), each with probability 1/2.

Value

Rewired network; assortativity coefficient(s) after each iteration; rewiring history (including the index of sampled edges and rewiring result) and solver results.

Examples


set.seed(123)
netwk1 <- rpanet(1e4, control = rpa_control_scenario(
  alpha = 0.4, beta = 0.3, gamma = 0.3
))
## rewire a directed network
target.assortcoef <- list("outout" = -0.2, "outin" = 0.2)
ret1 <- dprewire(
  netwk = netwk1,
  target.assortcoef = target.assortcoef,
  control = list(iteration = 200)
)
plot(ret1$assortcoef$Iteration, ret1$assortcoef$"outout")
plot(ret1$assortcoef$Iteration, ret1$assortcoef$"outin")

## rewire an undirected network
netwk2 <- rpanet(1e4,
  control = rpa_control_scenario(
    alpha = 0.3, beta = 0.1, gamma = 0.3, xi = 0.3
  ),
  initial.network = list(
    directed = FALSE)
)
ret2 <- dprewire(
  netwk = netwk2,
  target.assortcoef = 0.3,
  control = list(
    iteration = 300, eta.obj = CVXR::norm2,
    history = TRUE
  )
)
plot(ret2$assortcoef$Iteration, ret2$assortcoef$Value)



[Package wdnet version 1.2.3 Index]