![]() |
STAG C++
2.0.0
Spectral Toolkit of Algorithms for Graphs
|
Methods for generating graphs from random graph models.
Functions | |
Graph | stag::sbm (StagInt n, StagInt k, StagReal p, StagReal q, bool exact) |
Graph | stag::sbm (StagInt n, StagInt k, StagReal p, StagReal q) |
Graph | stag::general_sbm (std::vector< StagInt > &cluster_sizes, DenseMat &probabilities, bool exact) |
Graph | stag::general_sbm (std::vector< StagInt > &cluster_sizes, DenseMat &probabilities) |
void | stag::general_sbm_edgelist (std::string &filename, std::vector< StagInt > &cluster_sizes, DenseMat &probabilities, bool exact) |
void | stag::general_sbm_edgelist (std::string &filename, std::vector< StagInt > &cluster_sizes, DenseMat &probabilities) |
Graph | stag::erdos_renyi (StagInt n, StagReal p, bool exact) |
Graph | stag::erdos_renyi (StagInt n, StagReal p) |
std::vector< StagInt > | stag::sbm_gt_labels (StagInt n, StagInt k) |
std::vector< StagInt > | stag::general_sbm_gt_labels (std::vector< StagInt > &cluster_sizes) |
Generate a graph from the symmetric stochastic block model.
Generates a graph with \(n\) vertices, divided into \(k\) evenly-sized clusters. For each pair of vertices \(u\) and \(v\), the probability of including the edge \(\{u, v\}\) in the graph is
For large enough values of \(n\), this method samples from an approximate stochastic block model by default which significantly speeds up the execution time. To sample exactly from the stochastic block model, pass the optional 'exact' parameter to the method.
The approximate sampling method has running time \(O(k^2 + \mathrm{nnz})\) where \(\mathrm{nnz}\) is the number of non-zeros in the generated graph's adjacency matrix, and the exact method has running time \(O(n^2)\).
n | the number of vertices in the graph |
k | the number of clusters; vertices are split evenly between clusters |
p | the probability of including each edge inside a cluster |
q | the probability of including each edge between two clusters |
exact | (optional) whether to use the exact probability distribution. Default: false. |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Graph stag::general_sbm | ( | std::vector< StagInt > & | cluster_sizes, |
DenseMat & | probabilities, | ||
bool | exact | ||
) |
Generate a graph from the general stochastic block model.
The cluster_sizes
vector specifies the number of vertices in each generated cluster. Let \(k\) be the length of the cluster_sizes vector.
Then, probabilities
should be a \(k \times k\) matrix which specifies the edge probability between every pair of vertices. That is, for each pair of vertices \(u\) and \(v\), the probability of including the edge \(\{u, v\}\) in the graph is \(P(u, v)\), where \(P\) is the probabilities
matrix.
The approximate sampling method has running time \(O(k^2 + \mathrm{nnz})\) where \(\mathrm{nnz}\) is the number of non-zeros in the generated graph's adjacency matrix, and the exact method has running time \(O(n^2)\).
cluster_sizes | a vector of length \(k\) with the number of vertices in each cluster. |
probabilities | a \(k \times k\) matrix with the inter-cluster probabilities. |
exact | (optional) whether to use the exact probability distribution. Default: false. |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void stag::general_sbm_edgelist | ( | std::string & | filename, |
std::vector< StagInt > & | cluster_sizes, | ||
DenseMat & | probabilities, | ||
bool | exact | ||
) |
Generate a graph from the general stochastic block model and save the resulting graph as an edgelist file.
This method uses only constant memory since the graph can be streamed to disk while it is being generated.
filename | the edgelist file to save the graph to |
cluster_sizes | a vector of length \(k\) with the number of vertices in each cluster. |
probabilities | a \(k \times k\) matrix with the inter-cluster probabilities. |
exact | (optional) whether to use the exact probability distribution. Default: false. |
void stag::general_sbm_edgelist | ( | std::string & | filename, |
std::vector< StagInt > & | cluster_sizes, | ||
DenseMat & | probabilities | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Generate a graph from the Erdos-Renyi model.
Generates a graph with \(n\) vertices. For each pair of vertices \(u\) and \(v\), the edge \(\{u, v\}\) is included in the graph with probability \(p\).
For large values of n, this method will use an approximate version of the random model with running time \(O(\mathrm{nnz})\) where \(\mathrm{nnz}\) is the number of edges in the generated graph.
If the 'exact' parameter is true, then the true Erdos-Renyi distribution will be used, with running time \(O(n^2)\).
n | the number of vertices in the graph |
p | the probability of including each edge |
exact | (optional) whether to sample from the exact model. Default: false. |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Construct a vector with the ground truth labels for a graph drawn from the symmetric stochastic block model.
n | the number of vertices in the graph |
k | the number of clusters |
Construct a vector with the ground truth labels for a graph drawn from the general stochastic block model.
cluster_sizes | a vector of length \(k\) with the number of vertices in each cluster. |