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 |
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 |
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
|
control |
A list of parameters for controlling the rewiring process and
the process for solving
|
eta |
A matrix represents the target network structure. If specified,
|
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)