Network sampling¶
Functions for random sampling of weighted directed networks are in motifcluster.sampling.
-
demonstration_graph
()¶ Generate a small graph for demonstrations.
Generate the sparse and dense adjacency matrices of a small weighted directed graph, for demonstrating methods and running tests.
Returns: - adj_mat_dense (matrix) – the adjacency matrix in dense form.
- adj_mat_sparse (sparse matrix) – the adjacency matrix in sparse form.
-
sample_bsbm
(source_block_sizes, dest_block_sizes, bipartite_connection_matrix, bipartite_weight_matrix=None, sample_weight_type='unweighted')¶ Sample a bipartite stochastic block model (BSBM).
Sample the (weighted) adjacency matrix of a (weighted) bipartite stochastic block model (BSBM) with specified parameters.
Parameters: - source_block_sizes (list of int) – A list containing the size of each block of source vertices.
- dest_block_sizes (list of int) – A list containing the size of each block of destination vertices.
- bipartite_connection_matrix (matrix) – A matrix containing the source block to destination block connection probabilities.
- bipartite_weight_matrix (matrix) – A matrix containing the source block to destination block weight parameters. Unused for sample_weight_type = “constant”. Defaults to None.
- sample_weight_type (str) – The type of weighting scheme. One of “unweighted”, “constant” or “poisson”.
Returns: adj_mat – A randomly sampled (weighted) adjacency matrix of a BSBM.
Return type: sparse matrix
Examples
>>> source_block_sizes = [10, 10] >>> dest_block_sizes = [10, 10, 10] >>> bipartite_connection_matrix = np.array([0.8, 0.5, 0.1, 0.1, 0.5, 0.8]).reshape((2, 3)) >>> bipartite_weight_matrix = np.array([20, 10, 2, 2, 10, 20]).reshape((2, 3)) >>> sample_bsbm(block_sizes, bipartite_connection_matrix, ... bipartite_weight_matrix, "poisson")
-
sample_dsbm
(block_sizes, connection_matrix, weight_matrix=None, sample_weight_type='unweighted')¶ Sample a directed stochastic block model (DSBM).
Sample the (weighted) adjacency matrix of a (weighted) directed stochastic block model (DSBM) with specified parameters.
Parameters: - block_sizes (list of int) – A list containing the size of each block of vertices.
- connection_matrix (matrix) – A matrix containing the block-to-block connection probabilities.
- sample_weight_type (str) – The type of weighting scheme. One of “unweighted”, “constant” or “poisson”.
- weight_matrix (matrix) – A matrix containing the block-to-block weight parameters. Unused for sample_weight_type = “constant”. Defaults to None.
Returns: adj_mat – A randomly sampled (weighted) adjacency matrix of a DSBM.
Return type: sparse matrix
Examples
>>> block_sizes = [10, 10] >>> connection_matrix = np.array([0.8, 0.1, 0.1, 0.8]).reshape((2, 2)) >>> weight_matrix = np.array([10, 3, 3, 10]).reshape((2, 2)) >>> sample_dsbm(block_sizes, connection_matrix, weight_matrix, "poisson")