API reference

andrey.data.sample_discrete#

andrey.data.sample_discrete(*, graph='erdos_renyi', d, n, seed, density=2.0, categories=(2, 3), concentration=1.0, shuffle=True)[source]#

Sample a discrete Bayesian network with random conditional probability tables.

Parameters:
  • graph (str) – The random graph the DAG is drawn from, as for sample_scm().

  • d (int) – Node count.

  • n (int) – Sample count.

  • seed (int) – Root seed.

  • density (float) – Mean total degree (2 * |E| / d) of the graph.

  • categories (tuple[int, int]) – The least and the most categories a node has; each node’s count is drawn uniformly between them, both included. The least is at least 2.

  • concentration (float) – Concentration of the symmetric Dirichlet each table row is drawn from. 1.0 draws rows uniformly over the probability simplex; a smaller value draws peakier rows, so the variables depend on their parents more strongly.

  • shuffle (bool) – Shuffle the columns with a permutation from the seed’s own column stream, and relabel the true graph and the categories to match, as for sample_scm(). provenance["column_order"][j] is the index column j has with shuffle=False.

Returns:

data holds the category codes, shape (n, d); graph is the true DAG; provenance["config"]["categories"] lists each column’s number of categories. params.weights and params.noise_scales are empty: the tables are the parameters.

Return type:

CausalDataset

Raises:

ValueError – If categories is not a pair with 2 <= least <= most, concentration is not positive, or graph names no graph.

Examples

>>> from andrey.data import sample_discrete
>>> ds = sample_discrete(d=5, n=200, seed=0)
>>> ds.data.shape, ds.graph.kind
((200, 5), 'dag')