Generate a random DAG

dag_random_tree(
  n_children = 2,
  p_stop = 0,
  max = 2^10 - 1,
  verbose = simona_opt$verbose
)

dag_add_random_children(
  dag,
  p_add = 0.1,
  new_children = c(1, 4),
  add_random_children_fun = NULL,
  verbose = simona_opt$verbose
)

dag_random(
  n_children = 2,
  p_stop = 0,
  max = 2^10 - 1,
  p_add = 0.1,
  new_children = c(1, 4),
  verbose = simona_opt$verbose
)

Arguments

n_children

Number of children of a term. The value can also be a vector of length two representing the range of the number of child terms.

p_stop

The probability of a term to stop growing.

max

Maximal number of terms.

verbose

Whether to print messages.

dag

An ontology_DAG object.

p_add

The probability to add children on each term.

new_children

The number or range of numbers of new children if a term is selected to add more children.

add_random_children_fun

A function to randomly add children from the DAG.

Value

An ontology_DAG object.

Details

dag_random_tree() generates a random DAG tree from the root term. In a certain step of the growing, let's denote the set of all leaf terms as L, then in the next round of growing, floor(length(L)*p_stop) leaf terms stop growing, and for the remaining leaf terms that continue to grow, each term will add child terms with number in uniformly sampled within [ n_children[1], n_children[2] ]. The growing stops when the total number of terms in the DAG exceeds max.

dag_add_random_children() adds more links in a DAG. Each term is associated with a probability p_add to add new links where the term, if it is selected, is as a parent term, linking to other terms in the DAG. The number of new child terms is controlled by new_children which can be a single number of a range. By default, new child terms of a term t are randomly selected from other terms that are lower than the term t (check the function simona:::add_random_children). The way how to randomly select new child terms for t can be controlled by a self-defined function for the add_random_children_fun argument.

dag_random(): it simply wraps dag_random_tree() and dag_add_random_children().

Examples

tree = dag_random_tree()
dag = dag_random()