peal.data.dataset_utils.process_confounder_data_controlled¶
- peal.data.dataset_utils.process_confounder_data_controlled(raw_data, config, mode, extract_instances_tensor, set_negative_to_zero=True)[source]¶
Subsample rows so that target and confounder co-occur at a fixed rate.
Rows are consumed in file order and sorted into the four (attribute, confounder) groups until every group reaches its quota, which is derived from
config.num_samplesand eitherconfig.full_confounder_config(four fractions summing to 1) orconfig.confounder_probability(the aligned groups (0,0) and (1,1) each getp/2, the misaligned ones(1-p)/2). Rows with attribute or confounder values >= 2 are skipped. Each group is then split withconfig.splitso that all partitions keep the same confounder ratio.- Parameters:
raw_data (
iterable) – Rows (csv lines or json records) passed toextract_instances_tensor.config (
DataConfig) – Providesnum_samples,splitand the confounder settings.mode (
str) –"train","val","test"; otherwise all selected keys.extract_instances_tensor (
callable) –f(idx, line) -> (key, tensor, attribute, confounder).set_negative_to_zero (
bool, optional) – Clamp negative tensor values (and the attribute/confounder ints) to 0.
- Returns:
- Raises:
AssertionError – If the quotas cannot be filled from the available rows or the totals do not add up to
config.num_samples.