Generate scale-free graphs according to the Barabasi-Albert model
The BA-model is a very simple stochastic algorithm for building a graph.
sample_pa(n, power = 1, m = NULL, out.dist = NULL, out.seq = NULL, out.pref = FALSE, zero.appeal = 1, directed = TRUE, algorithm = c("psumtree", "psumtree-multiple", "bag"), start.graph = NULL)
- Number of vertices.
- The power of the preferential attachment, the default is one, ie. linear preferential attachment.
- Numeric constant, the number of edges to add in each time step This
argument is only used if both
out.seqare omitted or NULL.
- Numeric vector, the distribution of the number of edges to
add in each time step. This argument is only used if the
out.seqargument is omitted or NULL.
- Numeric vector giving the number of edges to add in each time step. Its first element is ignored as no edges are added in the first time step.
- Logical, if true the total degree is used for calculating the citation probability, otherwise the in-degree is used.
attractivenessof the vertices with no adjacent edges. See details below.
- Whether to create a directed graph.
- The algorithm to use for the graph generation.
psumtreeuses a partial prefix-sum tree to generate the graph, this algorithm can handle any
zero.appealvalues and never generates multiple edges.
NULLor an igraph graph. If a graph, then the supplied graph is used as a starting graph for the preferential attachment algorithm. The graph should have at least one vertex. If a graph is supplied here and the
- Passed to
This is a simple stochastic algorithm to generate a graph. It is a discrete time step model and in each time step a single vertex is added.
We start with a single vertex and no edges in the first time step. Then we
add one vertex in each time step and the new vertex initiates some edges to
old vertices. The probability that an old vertex is chosen is given by
$$P[i] \sim k_i^\alpha+a$$ where $k_i$
is the in-degree of vertex $i$ in the current time step (more precisely
the number of adjacent edges of $i$ which were not initiated by $i$
itself) and $\alpha$ and $a$ are parameters given by the
The number of edges initiated in a time step is given by the
out.seq arguments. If
out.seq is given and
not NULL then it gives the number of edges to add in a vector, the first
element is ignored, the second is the number of edges to add in the second
time step and so on. If
out.seq is not given or null and
out.dist is given and not NULL then it is used as a discrete
distribution to generate the number of edges in each time step. Its first
element is the probability that no edges will be added, the second is the
probability that one edge is added, etc. (
out.dist does not need to
sum up to one, it normalized automatically.)
out.dist should contain
non-negative numbers and at east one element should be positive.
out.dist are omitted or NULL then
will be used, it should be a positive integer constant and
will be added in each time step.
sample_pa generates a directed graph by default, set
FALSE to generate an undirected graph. Note that
even if an undirected graph is generated $k_i$ denotes the number
of adjacent edges not initiated by the vertex itself and not the total (in-
+ out-) degree of the vertex, unless the
out.pref argument is set to
- A graph object.
Barabasi, A.-L. and Albert R. 1999. Emergence of scaling in random networks Science, 286 509--512.
g <- sample_pa(10000) degree_distribution(g)