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 forsample_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.0draws 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 forsample_scm().provenance["column_order"][j]is the index columnjhas withshuffle=False.
- Returns:
dataholds the category codes, shape(n, d);graphis the true DAG;provenance["config"]["categories"]lists each column’s number of categories.params.weightsandparams.noise_scalesare empty: the tables are the parameters.- Return type:
CausalDataset- Raises:
ValueError – If
categoriesis not a pair with2 <= least <= most,concentrationis not positive, orgraphnames 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')