rpa_control_preference | R Documentation |
rpanet
.Set preference function(s). Defined for rpanet
.
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"
)
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 |
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 of outs
(node out-strength) and
ins
(node in-strength). For example, "pow(outs, 2) + 1"
,
"pow(outs, 2) + pow(ins, 2) + 1"
, etc. The expression will be used
to define an XPtr
via RcppXPtrUtils::cppXPtr
. The XPtr
will be passed to the network generation function. The expression must not
have variables other than outs
and ins
.
'XPtr' an
external pointer wrapped in an object of class XPtr
defined via
RcppXPtrUtils::cppXPtr
. An example for defining an XPtr
with
C++
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 supplied C++
function accepts two double
arguments and returns a double
. The first and second arguments
represent node out- and in-strength, respectively. Note that the XPtr
will
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
.
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
.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.