| rpa_control_preference {wdnet} | R Documentation |
Set preference function(s). Defined for rpanet.
Description
Set preference function(s). Defined for rpanet.
Usage
rpa_control_preference(
ftype = c("default", "customized"),
sparams = c(1, 1, 0, 0, 1),
tparams = c(0, 0, 1, 1, 1),
params = c(1, 1),
spref = "outs + 1",
tpref = "ins + 1",
pref = "s + 1"
)
Arguments
ftype |
Preference function type. Either "default" or "customized".
"customized" preference functions require "binary" or "linear" generation
methods. If using default preference functions, |
sparams |
A numerical vector of length 5 giving the parameters of the
default source preference function. Defined for directed networks.
Probability of choosing an existing node as the source node is proportional
to |
tparams |
A numerical vector of length 5 giving the parameters of the
default target preference function. Defined for directed networks.
Probability of choosing an existing node as the target node is proportional
to |
params |
A numerical vector of length 2 giving the parameters of the
default preference function. Defined for undirected networks. Probability
of choosing an existing node is proportional to |
spref |
Character expression or an object of class |
tpref |
Character expression or an object of class |
pref |
Character expression or an object of class |
Details
If choosing customized preference functions, spref,
tpref and pref will be used and the network generation method
must be "binary" or "linear". spref (tpref) defines the
source (target) preference function, it can be a character expression or an
object of class XPtr.
Character expression; it must be a one-line
C++style expression ofouts(node out-strength) andins(node in-strength). For example,"pow(outs, 2) + 1","pow(outs, 2) + pow(ins, 2) + 1", etc. The expression will be used to define anXPtrviaRcppXPtrUtils::cppXPtr. TheXPtrwill be passed to the network generation function. The expression must not have variables other thanoutsandins.'XPtr' an external pointer wrapped in an object of class
XPtrdefined viaRcppXPtrUtils::cppXPtr. An example for defining anXPtrwithC++source code is included in Examples. For more information about passing function pointers, see https://gallery.rcpp.org/articles/passing-cpp-function-pointers-rcppxptrutils/. Please note the suppliedC++function accepts twodoublearguments and returns adouble. The first and second arguments represent node out- and in-strength, respectively. Note that theXPtrwill be invalid and cannot be used to control network generation in another separate R session. Therefore, we recommend preserving the source code of your preference function for future use.
pref is defined analogously. If using character expression, it must
be a one-line C++ style expression of s (node strength). If
using XPtr, the supplied C++ function accepts only one
double argument and returns a double.
Value
A list of class rpacontrol with components ftype,
sparams, tparams, params or ftype,
spref, tpref, pref with function pointers
spref.pointer, tpref.pointer, pref.pointer.
Examples
# Set source preference as out-strength^2 + in-strength + 1,
# target preference as out-strength + in-strength^2 + 1.
# 1. use default preference functions
ctr1 <- rpa_control_preference(
ftype = "default",
sparams = c(1, 2, 1, 1, 1), tparams = c(1, 1, 1, 2, 1)
)
# 2. use character expressions
ctr2 <- rpa_control_preference(
ftype = "customized",
spref = "pow(outs, 2) + ins + 1", tpref = "outs + pow(ins, 2) + 1"
)
# 3. define XPtr's with C++ source code
spref.pointer <- RcppXPtrUtils::cppXPtr(
code =
"double spref(double outs, double ins) {return pow(outs, 2) + ins + 1;}"
)
tpref.pointer <- RcppXPtrUtils::cppXPtr(
code =
"double tpref(double outs, double ins) {return outs + pow(ins, 2) + 1;}"
)
ctr3 <- rpa_control_preference(
ftype = "customized",
spref = spref.pointer,
tpref = tpref.pointer
)
ret <- rpanet(1e5, control = ctr3)