numgraph.distributions

Static distributions

numgraph.distributions.erdos_renyi_coo(num_nodes, prob, directed=False, weighted=False, rng=None)[source]

Returns a random graph, also known as an Erdos-Renyi graph or a binomial graph. The model chooses each of the possible edges with a defined probability.

Parameters
  • num_nodes (int) – The number of nodes

  • prob (float) – Probability of an edge

  • directed (bool, optional) – If set to True, will return a directed graph, by default False

  • weighted (bool, optional) – If set to True, will return a dense representation of the weighted graph, by default False

  • rng (Generator, optional) – Numpy random number generator, by default None

Returns

  • NDArray – The random graph in COO representation (num_edges x 2).

  • Optional[NDArray] – Weights of the random graph.

numgraph.distributions.erdos_renyi_full(num_nodes, prob, directed=False, weighted=False, rng=None)[source]

Returns a random graph, also known as an Erdos-Renyi graph or a binomial graph. The model chooses each of the possible edges with a defined probability.

Parameters
  • num_nodes (int) – The number of nodes

  • prob (float) – Probability of an edge

  • directed (bool, optional) – If set to True, will return a directed graph, by default False

  • weighted (bool, optional) – If set to True, will return a dense representation of the weighted graph, by default False

  • rng (Generator, optional) – Numpy random number generator, by default None

Returns

NDArray – The random graph in matrix representation (num_nodes x num_nodes).

numgraph.distributions.barabasi_albert_coo(num_nodes, num_edges, weighted=False, rng=None)[source]

Returns a graph sampled from the Barabasi-Albert (BA) model. The graph is built incrementally by adding num_edges arcs from a new node to already existing ones with preferential attachment towards nodes with high degree.

Parameters
  • num_nodes (int) – The number of nodes

  • num_edges (int) – The number of edges

  • weighted (bool, optional) – If set to True, will return a dense representation of the weighted graph, by default False

  • rng (Optional[Generator], optional) – Numpy random number generator, by default None

Returns

  • NDArray – The Barabasi-Albert graph in COO representation (num_edges x 2)

  • Optional[NDArray] – Weights of the random graph.

numgraph.distributions.barabasi_albert_full(num_nodes, num_edges, weighted=False, rng=None)[source]

Returns a graph sampled from the Barabasi-Albert (BA) model. The graph is built incrementally by adding num_edges arcs from a new node to already existing ones with preferential attachment towards nodes with high degree.

Parameters
  • num_nodes (int) – The number of nodes

  • num_edges (int) – The number of edges

  • weighted (bool, optional) – If set to True, will return a dense representation of the weighted graph, by default False

  • rng (Optional[Generator], optional) – Numpy random number generator, by default None

Returns

NDArray – The Barabasi-Albert graph in matrix representation (num_nodes x num_nodes)

numgraph.distributions.stochastic_block_model_coo(block_sizes, probs, generator, directed=False, weighted=False, rng=None)[source]

Returns a stochastic block model graph. This model partitions the nodes into blocks of defined sizes, and places edges between pairs of nodes depending on a probability matrix. Such a matrix specifies edge probabilities between and inside blocks.

Parameters
  • block_sizes (List[int]) – Sizes of blocks

  • probs (List[List[float]]) – The squared probability matrix (num_blocks x num_blocks). The element i,j represents the edge probability between blocks i and j. The element i,i define the edge probability inside block i.

  • generator (Callable) – A callable that generates communities with size depending on block_sizes

  • directed (bool, optional) – If set to True, will return a directed graph, by default False

  • weighted (bool, optional) – If set to True, will return a dense representation of the weighted graph, by default False

  • rng (Generator, optional) – Numpy random number generator, by default None

Returns

  • NDArray – The stochastic block model graph in COO representation (num_edges x 2).

  • Optional[NDArray] – Weights of the random graph.

Note

The generator takes as input the block size, the probability, and the rng

numgraph.distributions.stochastic_block_model_full(block_sizes, probs, generator, directed=False, weighted=False, rng=None)[source]

Returns a stochastic block model graph. This model partitions the nodes into blocks of defined sizes, and places edges between pairs of nodes depending on a probability matrix. Such a matrix specifies edge probabilities between and inside blocks.

Parameters
  • block_sizes (List[int]) – Sizes of blocks

  • probs (List[List[float]]) – The squared probability matrix (num_blocks x num_blocks). The element i,j represents the edge probability between blocks i and j. The element i,i define the edge probability inside block i.

  • generator (Callable) – A callable that generates communities with size depending on block_sizes

  • directed (bool, optional) – If set to True, will return a directed graph, by default False

  • weighted (bool, optional) – If set to True, will return a dense representation of the weighted graph, by default False

  • rng (Generator, optional) – Numpy random number generator, by default None

Returns

NDArray – The stochastic block model graph in matrix representation (num_nodes x num_nodes).

Note

The generator takes as input the block size, the probability, and the rng

numgraph.distributions.clique_coo(num_nodes, weighted=False, rng=None)[source]

Returns a complete graph, a.k.a. a clique.

Parameters
  • num_nodes (int) – The number of nodes

  • weighted (bool, optional) – If set to True, will return a dense representation of the weighted graph, by default False

  • rng (Optional[Generator], optional) – Numpy random number generator, by default None

Returns

  • NDArray – The clique in COO representation (num_edges x 2)

  • Optional[NDArray] – Weights of the random graph.

numgraph.distributions.clique_full(num_nodes, weighted=False, rng=None)[source]

Returns a complete graph, a.k.a. a clique.

Parameters
  • num_nodes (int) – The number of nodes

  • weighted (bool, optional) – If set to True, will return a dense representation of the weighted graph, by default False

  • rng (Optional[Generator], optional) – Numpy random number generator, by default None

Returns

NDArray – The clique in matrix representation (num_nodes x num_nodes)

numgraph.distributions.grid_coo(height, width, directed=False, weighted=False, rng=None)[source]

Returns a full undirected two-dimensional rectangular grid lattice graph.

1 - 2 - 3
| X | X |
4 - 5 - 6
Parameters
  • height (int) – Number of vertices in the vertical axis

  • width (int) – Number of vertices in the horizontal axis

  • directed (bool, optional) – If set to True, will return a directed graph, by default False

  • weighted (bool, optional) – If set to True, will return a dense representation of the weighted graph, by default False

  • rng (Optional[Generator], optional) – Numpy random number generator, by default None

Returns

  • NDArray – The full undirected two-dimensional rectangular grid lattice graph in COO representation (num_edges x 2)

  • Optional[NDArray] – Weights of the random graph.

numgraph.distributions.grid_full(height, width, directed=False, weighted=False, rng=None)[source]

Returns a full undirected two-dimensional rectangular grid lattice graph.

1 - 2 - 3
| X | X |
4 - 5 - 6
Parameters
  • height (int) – Number of vertices in the vertical axis

  • width (int) – Number of vertices in the horizontal axis

  • directed (bool, optional) – If set to True, will return a directed graph, by default False

  • weighted (bool, optional) – If set to True, will return a dense representation of the weighted graph, by default False

  • rng (Optional[Generator], optional) – Numpy random number generator, by default None

Returns

NDArray – The full undirected two-dimensional rectangular grid lattice graph in matrix representation (num_nodes x num_nodes)

numgraph.distributions.simple_grid_coo(height, width, directed=False, weighted=False, rng=None)[source]

Returns an undirected two-dimensional rectangular grid lattice graph.

1 -- 2 -- 3
|    |    |
4 -- 5 -- 6
Parameters
  • height (int) – Number of vertices in the vertical axis

  • width (int) – Number of vertices in the horizontal axis

  • directed (bool, optional) – If set to True, will return a directed graph, by default False

  • weighted (bool, optional) – If set to True, will return a dense representation of the weighted graph, by default False

  • rng (Optional[Generator], optional) – Numpy random number generator, by default None

Returns

  • NDArray – The undirected two-dimensional rectangular grid lattice graph in COO representation (num_edges x 2)

  • Optional[NDArray] – Weights of the random graph.

numgraph.distributions.simple_grid_full(height, width, directed=False, weighted=False, rng=None)[source]

Returns an undirected two-dimensional rectangular grid lattice graph.

1 -- 2 -- 3
|    |    |
4 -- 5 -- 6
Parameters
  • height (int) – Number of vertices in the vertical axis

  • width (int) – Number of vertices in the horizontal axis

  • directed (bool, optional) – If set to True, will return a directed graph, by default False

  • weighted (bool, optional) – If set to True, will return a dense representation of the weighted graph, by default False

  • rng (Optional[Generator], optional) – Numpy random number generator, by default None

Returns

NDArray – The undirected two-dimensional rectangular grid lattice graph in matrix representation (num_nodes x num_nodes)

numgraph.distributions.random_tree_coo(num_nodes, directed=True, weighted=False, rng=None)[source]

Returns a random tree computed using a random Prufer sequence.

Parameters
  • num_nodes (int) – The number of nodes in the tree

  • directed (bool, optional) – If set to True, will return a directed graph, by default True

  • weighted (bool, optional) – If set to True, will return a dense representation of the weighted graph, by default False

  • rng (Optional[Generator], optional) – Numpy random number generator, by default None

Returns

  • NDArray – The random tree in COO representation (num_edges x 2)

  • Optional[NDArray] – Weights of the random graph.

numgraph.distributions.random_tree_full(num_nodes, directed=True, weighted=False, rng=None)[source]

Returns a random tree computed using a random Prufer sequence.

Parameters
  • num_nodes (int) – The number of nodes in the tree

  • directed (bool, optional) – If set to True, will return a directed graph, by default True

  • weighted (bool, optional) – If set to True, will return a dense representation of the weighted graph, by default False

  • rng (Optional[Generator], optional) – Numpy random number generator, by default None

Returns

NDArray – The random tree in matrix representation (num_edges x 2)

numgraph.distributions.star_coo(num_nodes, directed=False, weighted=False, rng=None)[source]

Returns a star graph.

Parameters
  • num_nodes (int) – The number of nodes

  • directed (bool, optional) – If set to True, will return a directed graph, by default False

  • weighted (bool, optional) – If set to True, will return a dense representation of the weighted graph, by default False

  • rng (Optional[Generator], optional) – Numpy random number generator, by default None

Returns

  • NDArray – The star graph in COO representation (num_edges x 2)

  • Optional[NDArray] – Weights of the random graph.

numgraph.distributions.star_full(num_nodes, directed=False, weighted=False, rng=None)[source]

Returns a star graph.

Parameters
  • num_nodes (int) – The number of nodes

  • directed (bool, optional) – If set to True, will return a directed graph, by default False

  • weighted (bool, optional) – If set to True, will return a dense representation of the weighted graph, by default False

  • rng (Optional[Generator], optional) – Numpy random number generator, by default None

Returns

NDArray – The star graph in matrix representaion (num_nodes x num_nodes)