dirichlet_split#

fedcausal.data.dirichlet_split(ds, n_clients, alpha, seed, by=None)[source]#

Split a dataset across clients via Dirichlet-distribution draws.

With by=None the clients’ sizes follow one Dirichlet(alpha) draw (quantity skew). With by=j each level of variable j is spread by its own draw, so clients see different mixes of that variable (value skew). Every client gets at least one row: rows move from the largest client to any that would be empty.

Parameters:
dsDiscreteDataset or ContinuousDataset

The dataset to split.

n_clientsint

Number of clients. Must satisfy 1 <= n_clients <= ds.n_rows.

alphafloat

Dirichlet concentration, positive. Small values (0.1) give very uneven splits, large ones (1e6) nearly even ones.

seedint

Random seed. The same arguments always give the same split.

byint, optional

Column to skew by. Only for a DiscreteDataset. Default None, quantity skew.

Returns:
list[DiscreteDataset] or list[ContinuousDataset]

n_clients non-empty datasets that together hold every row of ds exactly once.

Raises:
ValueError

If n_clients or alpha is not positive, if n_clients exceeds ds.n_rows, or if by is out of range.

TypeError

If by is given but ds is not a DiscreteDataset.