cleverly.interventions.LearnedRuleSplit#
- class cleverly.interventions.LearnedRuleSplit(seed: int, scheme: str, estimate: float, fold_sizes: tuple[int, ...], fold_masses: tuple[float, ...], fold_estimates: tuple[float, ...], arm_shares: tuple[tuple[float, ...], ...], gap_quantiles: tuple[tuple[float, ...], ...], score_quantiles: tuple[tuple[float, ...], ...], inner_seeds: tuple[int, ...], rule_disagreement: float)[source]#
Record one split of a learned-rule fit: its rules and its fold estimates.
- Parameters:
- seed
int The seed of the split’s folds and learners, as
result.repeatsrecords it.- scheme
str The scheme of the fit, one of
SCHEMES:"fold_evaluated"undercv_evaluation=True,"stacked"undercv_evaluation=False, and"in_sample"undercross_fit=False, whose one pseudo-fold holds every row.- estimate
float The split’s estimate. Under the fold-evaluated report it is \((1/V)\sum_v \psi^*_{nv}\), and under the stacked report it is the pooled plug-in \(\sum_v (W_v/W)\psi^*_{nv}\), which
fold_weightsgives. In sample it is the targeted plug-in of the full-sample rule on every row.- fold_sizes
tupleofint The validation rows of each outer fold.
- fold_masses
tupleoffloat The observation-weight mass \(W_v\) of each fold’s validation rows, on the fit’s mean-one weight scale. Without weights it is the fold’s row count.
- fold_estimates
tupleoffloat The targeted plug-in value \(\psi^*_{nv}\) of each fold on its own validation rows. Under the fold-evaluated report each is a term of the estimate, and with baseline strata it is the share mixture of the fold’s stratum plug-ins. Under the stacked report it is descriptive: the weighted mean of \(\bar Q^*(d_i, W_i)\) over the fold’s rows at the fit’s own fluctuation. Pooled targeting does not solve each fold’s score, so a fold value is not an estimate of \(\Psi_{d_{nv}}(P_0)\) with its own interval, and only their weighted sum is reported. In sample the one value is the estimate.
- arm_shares
tupleoftupleoffloat For each fold, the share of its validation rows that its rule assigns to each arm, in arm-code order (
LearnedRuleRecord.arms). Each fold’s shares sum to 1. At two arms the second share is the share the rule treats.- gap_quantiles
tupleoftupleoffloat For each fold, quantiles of the top-two gap of the outer outcome regression, \(\max_a \bar Q_v(a, W) - \max_{a \ne d_v(W)} \bar Q_v(a, W)\), on its validation rows, at
BLIP_QUANTILE_LEVELS, on the scale the outcome regression is fitted on. At two arms it is the absolute blip \(|\bar Q_v(1, W) - \bar Q_v(0, W)|\). For the plug-in rule it is the margin of the rule’s own argmax, whose mass at 0 speaks to C3. Under a pseudo-outcome loss it describes the outer outcome regression, not the rule.- score_quantiles
tupleoftupleoffloat For a pseudo-outcome loss, for each fold, quantiles of the rule learner’s score minus its threshold on the fold’s validation rows, at
BLIP_QUANTILE_LEVELS: \(\hat b_v(w)\) forloss="blip", \(\hat P_v(\tilde D > 0 \mid w) - 1/2\) forloss="weighted_classification", and the EP curve \(\hat\theta_v(v)\) of the declared modifiers forloss="ep", on the outcome’s own scale (not the scaled blip). The rule treats where this is positive, so its mass at 0 speaks to C3. Empty for the plug-in rule and for a frozen rule. An EP fold’s chosen sieve size and its cross-validated risks are not recorded here; a refit of the fold throughfit_fold_rule()with itsinner_seedsentry returns them inFoldRule.ep.- inner_seeds
tupleofint For a pseudo-outcome loss, the seed of each fold’s inner cross-fit and rule learner (
inner_seed()), so that a refit of one fold’s rule reproduces it. Empty for the plug-in rule.- rule_disagreement
float The share of the split’s rows at which the fold rules do not all assign the same arm, read from every fold’s rule at every row (
fold_rules()). Rules that converge to one limit agree almost everywhere, so a large share speaks against condition C3 and, for the value of the optimal rule, against a non-exceptional law.0.0in sample, where one rule serves every row, andnanfor a frozen rule, which holds no fold rule.
- seed
- Attributes:
n_foldsintReturn the number of outer folds of the split.
fold_weightstupleoffloatReturn the weight of each fold in the split’s target and estimate.
Methods#
Attributes#
- LearnedRuleSplit.fold_weights#
Return the weight of each fold in the split’s target and estimate.
1/Vfor every fold under the fold-evaluated report, and the fold’s share \(W_v/W\) of the weight mass under the stacked report (n_v/nwithout weights). The one pseudo-fold of an in-sample fit has weight 1.
- LearnedRuleSplit.n_folds#
Return the number of outer folds of the split.