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:
seedint

The seed of the split’s folds and learners, as result.repeats records it.

schemestr

The scheme of the fit, one of SCHEMES: "fold_evaluated" under cv_evaluation=True, "stacked" under cv_evaluation=False, and "in_sample" under cross_fit=False, whose one pseudo-fold holds every row.

estimatefloat

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_weights gives. In sample it is the targeted plug-in of the full-sample rule on every row.

fold_sizestuple of int

The validation rows of each outer fold.

fold_massestuple of float

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_estimatestuple of float

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_sharestuple of tuple of float

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_quantilestuple of tuple of float

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_quantilestuple of tuple of float

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)\) for loss="blip", \(\hat P_v(\tilde D > 0 \mid w) - 1/2\) for loss="weighted_classification", and the EP curve \(\hat\theta_v(v)\) of the declared modifiers for loss="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 through fit_fold_rule() with its inner_seeds entry returns them in FoldRule.ep.

inner_seedstuple of int

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_disagreementfloat

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.0 in sample, where one rule serves every row, and nan for a frozen rule, which holds no fold rule.

Attributes:
n_foldsint

Return the number of outer folds of the split.

fold_weightstuple of float

Return 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/V for 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/n without 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.

LearnedRuleSplit.seed: int#
LearnedRuleSplit.scheme: str#
LearnedRuleSplit.estimate: float#
LearnedRuleSplit.fold_sizes: tuple[int, ...]#
LearnedRuleSplit.fold_masses: tuple[float, ...]#
LearnedRuleSplit.fold_estimates: tuple[float, ...]#
LearnedRuleSplit.arm_shares: tuple[tuple[float, ...], ...]#
LearnedRuleSplit.gap_quantiles: tuple[tuple[float, ...], ...]#
LearnedRuleSplit.score_quantiles: tuple[tuple[float, ...], ...]#
LearnedRuleSplit.inner_seeds: tuple[int, ...]#
LearnedRuleSplit.rule_disagreement: float#