andrey.data.sample_mixed#
- andrey.data.sample_mixed(*, graph='erdos_renyi', d, n, seed, density=2.0, categorical_share=0.5, categories=(2, 3), concentration=1.0, shuffle=True)[source]#
Sample a conditional linear Gaussian network of categorical and continuous variables.
- 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.categorical_share (
float) – The share of the variables that are categorical, from0to1: the firstround(categorical_share * d)in causal order.categories (
tuple[int,int]) – The least and the most categories a categorical variable has; each one’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, as forsample_discrete().shuffle (
bool) – Shuffle the columns with a permutation from the seed’s own column stream, and relabel the true graph, the categorical columns, and the parameters to match, as forsample_scm().provenance["column_order"][j]is the index columnjhas withshuffle=False.
- Returns:
data, shape(n, d), holds the category codes0..k-1of the categorical variables and the values of the continuous ones;graphis the true DAG.provenance["config"]["categorical"]lists the categorical columns andprovenance["config"]["categories"]their numbers of categories, in the same order.params.weightsholds each edge’s weight into a continuous variable: the coefficient of a continuous parent, or the largest shift of a categorical one; an edge into a categorical variable hasnan, its table being its parameters.params.noise_scalesis1for a continuous variable andnanfor a categorical one.- Return type:
CausalDataset- Raises:
ValueError – If
categorical_shareis not in[0, 1],categoriesis not a pair with2 <= least <= most,concentrationis not positive, orgraphnames no graph.
Notes
A continuous variable
xwith continuous parentspand categorical parentscisx = sum_p w_p * p + sum_c s_c[category of c] + e, withestandard Gaussian. Each|w_p|is uniform on[0.5, 2]with a random sign. The shiftss_cof a parent withkcategories arekevenly spaced values from-mtom, in a random order, withmuniform on[0.5, 2], so every category movesxby a different amount.Examples
>>> from andrey.data import sample_mixed >>> ds = sample_mixed(d=6, n=200, seed=0) >>> ds.data.shape, ds.graph.kind, ds.provenance["config"]["categorical"] ((200, 6), 'dag', [1, 2, 5])