For using the igraph C library
A hierarchical random graph is an ensemble of undirected
graphs with n
vertices. It is defined via a binary tree with n
leaf and n1
internal vertices, where the
internal vertices are labeled with probabilities.
The probability that two vertices are connected in the random graph
is given by the probability label at their closest common
ancestor.
Please read the following two articles for more about hierarchical random graphs: A. Clauset, C. Moore, and M.E.J. Newman. Hierarchical structure and the prediction of missing links in networks. Nature 453, 98  101 (2008); and A. Clauset, C. Moore, and M.E.J. Newman. Structural Inference of Hierarchies in Networks. In E. M. Airoldi et al. (Eds.): ICML 2006 Ws, Lecture Notes in Computer Science 4503, 113. SpringerVerlag, Berlin Heidelberg (2007).
igraph contains functions for fitting HRG models to a given network
(igraph_hrg_fit
), for generating networks from a given HRG
ensemble (igraph_hrg_game
, igraph_hrg_sample
), converting
an igraph graph to a HRG and back (igraph_hrg_create
, igraph_hrg_dendrogram
), for calculating a consensus tree from a
set of sampled HRGs (igraph_hrg_consensus
) and for predicting
missing edges in a network based on its HRG models (igraph_hrg_predict
).
The igraph HRG implementation is heavily based on the code published by Aaron Clauset, at his website, http://tuvalu.santafe.edu/~aaronc/hierarchy/
typedef struct igraph_hrg_t { igraph_vector_int_t left; igraph_vector_int_t right; igraph_vector_t prob; igraph_vector_int_t vertices; igraph_vector_int_t edges; } igraph_hrg_t;
A hierarchical random graph (HRG) can be given as a binary tree, where the internal vertices are labeled with real numbers.
Note that you don't necessarily have to know this internal representation for using the HRG functions, just pass the HRG objects created by one igraph function, to another igraph function.
It has the following members:
Values:

Vector that contains the left children of the internal tree vertices. The first vertex is always the root vertex, so the first element of the vector is the left child of the root vertex. Internal vertices are denoted with negative numbers, starting from 1 and going down, i.e. the root vertex is 1. Leaf vertices are denoted by nonnegative number, starting from zero and up. 

Vector that contains the right children of the
vertices, with the same encoding as the 

The connection probabilities attached to the internal vertices, the first number belongs to the root vertex (i.e. internal vertex 1), the second to internal vertex 2, etc. 

The number of edges in the subtree below the given internal vertex. 

The number of vertices in the subtree below the given internal vertex, including itself. 
igraph_error_t igraph_hrg_init(igraph_hrg_t *hrg, igraph_integer_t n);
This function must be called before passing an igraph_hrg_t
to
an igraph function.
Arguments:

Pointer to the HRG data structure to initialize. 

The number of vertices in the graph that is modeled by this HRG. It can be zero, if this is not yet known. 
Returns:
Error code. 
Time complexity: O(n), the number of vertices in the graph.
void igraph_hrg_destroy(igraph_hrg_t *hrg);
The HRG data structure can be reinitialized again with an igraph_hrg_destroy
call.
Arguments:

Pointer to the HRG data structure to deallocate. 
Time complexity: operating system dependent.
igraph_integer_t igraph_hrg_size(const igraph_hrg_t *hrg);
Arguments:

Pointer to the HRG. 
Returns:
The number of leaf nodes in the HRG. 
Time complexity: O(1).
igraph_error_t igraph_hrg_resize(igraph_hrg_t *hrg, igraph_integer_t newsize);
Arguments:

Pointer to an initialized (see 

The new size, i.e. the number of leaf nodes. 
Returns:
Error code. 
Time complexity: O(n), n is the new size.
igraph_error_t igraph_hrg_fit(const igraph_t *graph, igraph_hrg_t *hrg, igraph_bool_t start, igraph_integer_t steps);
Arguments:

The igraph graph to fit the model to. Edge directions are ignored in directed graphs. 

Pointer to an initialized HRG, the result of the fitting
is stored here. It can also be used to pass a HRG to the
function, that can be used as the starting point of the Markov
Chain Monte Carlo fitting, if the 

Logical, whether to start the fitting from the given HRG model. 

Integer, the number of MCMC steps to take in the fitting procedure. If this is zero, then the fitting stop is a convergence criteria is fulfilled. 
Returns:
Error code. 
Time complexity: TODO.
igraph_error_t igraph_hrg_consensus(const igraph_t *graph, igraph_vector_int_t *parents, igraph_vector_t *weights, igraph_hrg_t *hrg, igraph_bool_t start, igraph_integer_t num_samples);
The calculation can be started from the given HRG (hrg
), or (if
start
is false), a HRG is first fitted to the given graph.
Arguments:

The input graph. 

An initialized vector, the results are stored here. For each vertex, the id of its parent vertex is stored, or 1, if the vertex is the root vertex in the tree. The first n vertex IDs (from 0) refer to the original vertices of the graph, the other IDs refer to vertex groups. 

Numeric vector, counts the number of times a given
tree split occured in the generated network samples, for each
internal vertices. The order is the same as in 

A hierarchical random graph. It is used as a starting
point for the sampling, if the 

Logical, whether to use the supplied HRG (in 

The number of samples to generate for creating the consensus tree. 
Returns:
Error code. 
Time complexity: TODO.
igraph_error_t igraph_hrg_sample(const igraph_hrg_t *hrg, igraph_t *sample);
This function draws a single sample from a hierarchical random graph model.
Arguments:

A HRG model to sample from 

Pointer to an uninitialized graph; the sample is stored here. 
Returns:
Error code. 
Time complexity: TODO.
igraph_error_t igraph_hrg_game(igraph_t *graph, const igraph_hrg_t *hrg);
This function is a simple shortcut to igraph_hrg_sample
.
It creates a single graph from the given HRG.
Arguments:

Pointer to an uninitialized graph, the new graph is created here. 

The hierarchical random graph model to sample from. 
Returns:
Error code. 
Time complexity: TODO.
igraph_error_t igraph_from_hrg_dendrogram( igraph_t *graph, const igraph_hrg_t *hrg, igraph_vector_t *prob );
Creates the igraph graph equivalent of the dendrogram encoded in an
igraph_hrg_t
data structure. The probabilities associated to the
nodes are returned in a vector so this function works without an
attribute handler.
Arguments:

Pointer to an uninitialized graph, the result is stored here. 

The hierarchical random graph to convert. 

Pointer to an initialized vector; the probabilities
associated to the nodes of the dendrogram will be stored here. Leaf nodes
will have an associated probability of 
Returns:
Error code. 
Time complexity: O(n), the number of vertices in the graph.
igraph_error_t igraph_hrg_create(igraph_hrg_t *hrg, const igraph_t *graph, const igraph_vector_t *prob);
Arguments:

Pointer to an initialized 

The igraph graph to convert. It must be a directed binary tree, with n1 internal and n leaf vertices. The root vertex must have indegree zero. 

The vector of probabilities, this is used to label the internal nodes of the hierarchical random graph. 
Returns:
Error code. 
Time complexity: O(n), the number of vertices in the tree.
igraph_error_t igraph_hrg_predict(const igraph_t *graph, igraph_vector_int_t *edges, igraph_vector_t *prob, igraph_hrg_t *hrg, igraph_bool_t start, igraph_integer_t num_samples, igraph_integer_t num_bins);
Samples HRG models for a network, and estimated the probability that an edge was falsely observed as nonexistent in the network.
Arguments:

The input graph. 

The list of missing edges is stored here, the first two elements are the first edge, the next two the second edge, etc. 

Vector of probabilies for the existence of missing
edges, in the order corresponding to 

A HRG, it is used as a starting point if 

Logical, whether to start the MCMC from the given HRG. 

The number of samples to generate. 

Controls the resolution of the edge probabilities. Higher numbers result higher resolution. 
Returns:
Error code. 
Time complexity: TODO.
igraph_error_t igraph_hrg_dendrogram(igraph_t *graph, const igraph_hrg_t *hrg);
Creates the igraph graph equivalent of an igraph_hrg_t
data
structure.
Arguments:

Pointer to an uninitialized graph, the result is stored here. 

The hierarchical random graph to convert. 
Returns:
Error code. 
Time complexity: O(n), the number of vertices in the graph.
Deprecated since version 0.10.5. Please do not use this function in new
code; use igraph_hrg_dendrogram()
instead.
← Chapter 25. Graphlets  Chapter 27. Embedding of graphs → 