closed-loop-default-detection 0.1.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/PKG-INFO +129 -21
  2. closed_loop_default_detection-0.3.0/README.md +292 -0
  3. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/pyproject.toml +3 -3
  4. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/src/cldd/__init__.py +15 -3
  5. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/src/cldd/config.py +14 -2
  6. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/src/cldd/correctors.py +68 -8
  7. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/src/cldd/diagnostics.py +1 -1
  8. closed_loop_default_detection-0.3.0/src/cldd/emp.py +388 -0
  9. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/src/cldd/eval_default.py +93 -12
  10. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/src/cldd/feedback.py +71 -14
  11. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/src/cldd/loop.py +11 -4
  12. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/src/cldd/model_pd.py +1 -2
  13. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/src/cldd/synthetic.py +5 -6
  14. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/src/closed_loop_default_detection.egg-info/PKG-INFO +129 -21
  15. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/src/closed_loop_default_detection.egg-info/SOURCES.txt +5 -0
  16. closed_loop_default_detection-0.3.0/tests/test_book_profit.py +329 -0
  17. closed_loop_default_detection-0.3.0/tests/test_emp.py +430 -0
  18. closed_loop_default_detection-0.3.0/tests/test_eval_default.py +208 -0
  19. closed_loop_default_detection-0.3.0/tests/test_exploration.py +201 -0
  20. closed_loop_default_detection-0.3.0/tests/test_feedback_flags.py +307 -0
  21. closed_loop_default_detection-0.3.0/tests/test_sweep_stats.py +501 -0
  22. closed_loop_default_detection-0.1.0/README.md +0 -184
  23. closed_loop_default_detection-0.1.0/tests/test_eval_default.py +0 -89
  24. closed_loop_default_detection-0.1.0/tests/test_exploration.py +0 -90
  25. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/LICENSE +0 -0
  26. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/setup.cfg +0 -0
  27. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/src/cldd/counterfactual.py +0 -0
  28. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/src/cldd/fidelity.py +0 -0
  29. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/src/cldd/py.typed +0 -0
  30. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/src/cldd/reject_inference.py +0 -0
  31. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/src/cldd/scm.py +0 -0
  32. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/src/closed_loop_default_detection.egg-info/dependency_links.txt +0 -0
  33. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/src/closed_loop_default_detection.egg-info/requires.txt +0 -0
  34. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/src/closed_loop_default_detection.egg-info/top_level.txt +0 -0
  35. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/tests/test_correctors.py +0 -0
  36. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/tests/test_counterfactual.py +0 -0
  37. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/tests/test_diagnostics.py +0 -0
  38. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/tests/test_feedback.py +0 -0
  39. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/tests/test_fidelity.py +0 -0
  40. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/tests/test_fidelity_report.py +0 -0
  41. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/tests/test_loop.py +0 -0
  42. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/tests/test_loop_scm.py +0 -0
  43. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/tests/test_model_pd.py +0 -0
  44. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/tests/test_reject_inference.py +0 -0
  45. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/tests/test_scm_gating.py +0 -0
  46. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/tests/test_sklearn_compat.py +0 -0
  47. {closed_loop_default_detection-0.1.0 → closed_loop_default_detection-0.3.0}/tests/test_synthetic.py +0 -0
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: closed-loop-default-detection
3
- Version: 0.1.0
4
- Summary: CLUE-style closed loop that measures selective-labels default detection on synthetic SMB lending cohorts and finds the PD model's operating frontier.
5
- Author-email: Hossain Pazooki <hossain@pazooki.com>
3
+ Version: 0.3.0
4
+ Summary: Closed loop that measures selective-labels default detection on synthetic SMB lending cohorts and finds the PD model's operating frontier.
5
+ Author: Hossain Pazooki
6
6
  License-Expression: MIT
7
7
  Project-URL: Homepage, https://github.com/hossainpazooki/closed-loop-default-detection
8
8
  Project-URL: Repository, https://github.com/hossainpazooki/closed-loop-default-detection
@@ -55,7 +55,7 @@ hides labels the way real approval policies do, and grades every correction agai
55
55
 
56
56
  The loop escalates selection severity until correction fails and reports the **operating
57
57
  frontier** — the last severity at which declined-cohort calibration still holds (target
58
- ECE ≤ 0.10). From the committed runs (`artifacts/clue_frontier*.csv`, seed 42):
58
+ ECE ≤ 0.10). From the committed runs (`artifacts/loop_frontier*.csv`, seed 42):
59
59
 
60
60
  | Selection severity | 0.0 | 0.2 | 0.4 | 0.6 |
61
61
  |---|---|---|---|---|
@@ -63,17 +63,119 @@ ECE ≤ 0.10). From the committed runs (`artifacts/clue_frontier*.csv`, seed 42)
63
63
  | **IPW-corrected** (flat world) | 0.020 | 0.038 | **0.086 ✓** | **0.154 ✗** |
64
64
  | **IPW-corrected** (SCM world) | 0.036 | 0.038 | **0.097 ✓** | **0.244 ✗** |
65
65
 
66
- Both worlds land the frontier at **severity 0.4**, and the counterfactual deliverable breaks at
67
- the same boundary: across 25 seeds, g-computation cuts strong-propagation counterfactual MAE
68
- from 0.099 to 0.086 (−13.5%, positive on 24/25 seeds, Wilcoxon p = 1.5e-7) *inside* the
69
- frontier — and collapses to a negligible +0.0017 at full severity, where **no deployable
70
- advantage is claimed**. One cause explains both: selection through an **unobserved
71
- confounder**, which backdoor adjustment and IPW cannot fix. That single measured limit — not
72
- an unverifiable score — is the deliverable.
66
+ On **this seed** both worlds land the frontier at severity 0.4, and the counterfactual
67
+ deliverable breaks at the same boundary: across 25 seeds, g-computation cuts
68
+ strong-propagation counterfactual MAE from 0.099 to 0.086 (−13.5%, positive on 24/25 seeds,
69
+ Wilcoxon p = 1.5e-7) *inside* the frontier — and collapses to a negligible +0.0017 at full
70
+ severity, where **no deployable advantage is claimed**. One cause explains both: selection
71
+ through an **unobserved confounder**, which backdoor adjustment and IPW cannot fix. That
72
+ single measured limit — not an unverifiable score — is the deliverable.
73
+
74
+ ### The frontier is a distribution, not a point (v2)
75
+
76
+ A frontier quoted from one seed is a figure published without an error bar. `v0.2.0` runs the
77
+ loop across the full 25-seed set (`artifacts/frontier_sweep.csv`) — and **seed 42 turns out to
78
+ sit at the optimistic end**:
79
+
80
+ | World | min | median | max | seeds at 0.4 | seeds at 0.2 |
81
+ |---|---|---|---|---|---|
82
+ | flat | 0.2 | **0.4** | 0.4 | 15/25 | 10/25 |
83
+ | SCM | 0.2 | **0.2** | 0.4 | 11/25 | 14/25 |
84
+
85
+ In the SCM world the *majority of seeds fail one step earlier than the headline*: the median
86
+ frontier is **0.2**, and seed 42's 0.4 is a minority outcome (11/25). The honest statement is
87
+ that the operating frontier is **0.2–0.4 depending on the draw**, not a clean 0.4 — the
88
+ single-seed table above is a valid instance of it, not its center. Nothing about the
89
+ mechanism changes (the unobserved confounder still explains the failure); what changes is how
90
+ precisely the boundary can be quoted.
91
+
92
+ *Caveat on the sweep:* loop seed `s` consumes generator seeds `s..s+7`, and the 25-seed set has
93
+ gaps smaller than 8, so some runs share feature draws. No two runs duplicate a cohort, but the
94
+ 25 rows are not fully independent — the set is kept for comparability with the counterfactual
95
+ sweep that uses it.
73
96
 
74
97
  Reproduce the headline from committed evidence: `python scripts/paired_significance.py`.
75
98
  The full independent assessment (methodology, all numbers, what didn't hold) is the
76
- accompanying article, [`FABLE.md`](FABLE.md).
99
+ accompanying article, [`docs/assessment.md`](docs/assessment.md) — a **dated snapshot**, written
100
+ against the single-seed frontier and not retro-fitted with the distribution above.
101
+
102
+ ## Pricing the frontier (v2)
103
+
104
+ Calibration says *whether* the model is wrong on the declines; it does not say **what being
105
+ wrong costs**. v2 adds an expected-maximum-profit (EMP) reporting axis — computed from the
106
+ same in-process scores the loop already measures, and **never** a loop-control input (ECE
107
+ still decides pass/fail and the frontier). Two variants run side by side:
108
+
109
+ | Variant | Parameters | What it answers |
110
+ |---|---|---|
111
+ | `empc` — literature EMPC | Verbraken et al. (2014) prior: `p0=0.55, p1=0.10, ROI=0.2644` | benchmark-comparable: what the standard measure says |
112
+ | `emp_h` — harness-derived | this harness's own economics + **planted** default timing | what the loan structure actually pays |
113
+
114
+ **The two disagree — and the disagreement is the finding.** In the SCM world they move in
115
+ opposite directions as selection severity rises (from `artifacts/loop_frontier_scm.csv`,
116
+ declined subpopulation, seed 42):
117
+
118
+ | Selection severity | 0.0 | 0.2 | 0.4 | 0.6 |
119
+ |---|---|---|---|---|
120
+ | Literature `empc` (naive) | 0.0217 | 0.0331 | 0.0416 | **0.0420 ↑** |
121
+ | Harness `emp_h` (naive) | 0.0387 | 0.0297 | 0.0139 | **0.0024 ↓** |
122
+
123
+ The convenience prior **misprices this loan structure**: it assumes `ROI = 0.2644` where a
124
+ 60-day daily-ACH loan actually returns `0.0875` (3% origination fee + 5.75% term interest) —
125
+ a **3.0× overstatement** — and puts **55% of defaults at full recovery where the harness plants
126
+ 1.2%** (prior mean λ = 0.275 vs harness 0.419). Priced honestly, the profit on the declined
127
+ pool collapses to near-zero at the frontier; priced by the literature prior, it appears to
128
+ *grow*. Same model, same scores, opposite conclusion.
129
+
130
+ **Reading caveats — the boundary of what this measures:**
131
+
132
+ - **Raw EMP moves with world hardness.** A riskier declined pool changes EMP even for a
133
+ perfect model, so a cross-severity EMP delta is *not* pure model signal. Read the two
134
+ variants against each other at fixed severity, not the trend in isolation.
135
+ - **`emp_h` rests on unfitted timing.** `days_to_default` is planted but independent of
136
+ features and risk given default — spec-shaped, never validated against real recovery data.
137
+ So `emp_h` is a **verified experiment, not a verified result**: the arithmetic is exact, the
138
+ timing distribution is an assumption.
139
+ - **Post-term defaults are imputed.** ~22.5% of planted defaults land at day 90, past the
140
+ 60-day term, and the generator does not model their payment history; they are priced at the
141
+ cohort's mean in-term loss fraction (a stated convention, not measured truth).
142
+ - **`emp_h` is SCM-only.** The flat generator plants no timing, so its `emp_h` columns are
143
+ empty by design; only `empc` is reported there.
144
+
145
+ Exploration now carries a price tag too. From `artifacts/exploration_frontier.csv` (SCM,
146
+ seed 42, 10% budget, severity 0.6): the lever buys **157 labels for $439,578** — about
147
+ **$2,800 per label**, of which 56 are realized defaults. That is the cost of *identification*,
148
+ in dollars a lender can see, on the only lever that buys it rather than reweighting what is
149
+ already identified.
150
+
151
+ ## Pricing the feedback loop (v3)
152
+
153
+ `v0.3.0` prices the **dynamic** regime, where the model's own approvals create its next
154
+ training set: three arms (treatment = retrain each generation; **frozen** = generation-0
155
+ model deployed forever; **prior** = prior-policy funding), 25 spaced seeds × 3 severities ×
156
+ 2 exploration rates × 12 generations = **450 runs**
157
+ (`artifacts/feedback_profit_sweep.csv`), with three pre-registered hypotheses tested as
158
+ within-seed paired contrasts on realized funded-book P&L at severity 0.4, Holm-corrected.
159
+ Every number below recomputes via `python scripts/feedback_sweep_stats.py`. All of it
160
+ consumes **planted, risk-unlinked default timing** — a verified *experiment*, not a
161
+ verified *result*.
162
+
163
+ | Hypothesis (severity 0.4, gens 1–11) | Median paired deficit | Sign | Verdict |
164
+ |---|---|---|---|
165
+ | H1 feedback accumulation costs money (treatment − frozen, ε=0) | **−0.0028** | 24/25 | **confirmed** (p_holm 2.3e-06, clears the 0.0018 noise floor) |
166
+ | H2 the policy switch costs money (frozen − prior, ε=0) | +0.0119 | 0/25 | **not confirmed — measured opposite in direction** |
167
+ | H3 exploration buys profit back (treatment ε=.05 − ε=0) | −0.0024 | 0/25 | **not confirmed** |
168
+
169
+ The decomposition v3 exists for came back one-for-three: letting the loop close on its own
170
+ labels measurably costs the book (H1), but at these severities the *switch* to model-based
171
+ funding is profitable relative to the prior policy (H2's predicted sign was wrong — reported
172
+ as measured, not softened), and 5% exploration does not pay for itself in-window (H3; the
173
+ policy-book-only secondary H3a is negative too). The **H4 integrity control** — frozen-arm
174
+ paired difference must equal the explored slice's own P&L *exactly* — holds at ≤1e-10 across
175
+ all 900 checked rows, and the answer to the v2-banked question is re-verified at 25 seeds:
176
+ the declined-ECE alarm fires at generation 1–2 in every ε=0 run (severity 0.4: 25/25 at
177
+ generation 1). Full mechanics in [`docs/how-it-works.md`](docs/how-it-works.md); gates in
178
+ [`docs/validation.md`](docs/validation.md).
77
179
 
78
180
  ## Install
79
181
 
@@ -139,6 +241,7 @@ Everything is importable from top-level `cldd` (full reference: the [Sphinx docs
139
241
  | `SyntheticBorrowerGenerator`, `StructuralBorrowerGenerator` | the flat and fitted-SCM synthetic worlds |
140
242
  | `run_counterfactual_eval`, `GComputationEstimator` | counterfactual validator (g-computation vs naive conditioning) |
141
243
  | `FeedbackLoop` | model-in-the-loop selective-labels simulation |
244
+ | `empc_literature`, `emp_harness` | the two EMP variants — price the frontier in profit (reporting only, never loop control) |
142
245
  | `positivity_diagnostics` | observable regime/drift alarm — needs **no** declined-row labels |
143
246
  | `CalibratedPDClassifier` | the calibrated PD detector as a scikit-learn estimator |
144
247
  | `cldd.fidelity.run_fidelity_gate` | SCM-vs-real **marginal**-fidelity gate (univariate marginals only) |
@@ -163,7 +266,8 @@ scores = cross_val_score(CalibratedPDClassifier(random_state=42), X, y, scoring=
163
266
  Each driver runs without install (adds `src/` to the path) and writes to `artifacts/`:
164
267
 
165
268
  ```bash
166
- python scripts/run_clue.py # the closed loop → frontier table + plot (--generator scm for the SCM world)
269
+ python scripts/run_loop.py # the closed loop → frontier table + plot (--generator scm for the SCM world)
270
+ python scripts/run_frontier_sweep.py --quick # frontier distribution across the 25-seed set (drop --quick for all)
167
271
  python scripts/run_seed_sweep.py --quick # counterfactual certification (drop --quick for all seeds)
168
272
  python scripts/run_reject_inference.py # reject-inference levers vs the frontier
169
273
  python scripts/run_exploration_sweep.py # frontier vs exploration budget
@@ -173,7 +277,7 @@ python scripts/paired_significance.py # recompute the headline stat from
173
277
 
174
278
  ## Validation
175
279
 
176
- `pytest` — 123 tests, all synthetic, no real data needed. CI runs a pinned-repro job (exact
280
+ `pytest` — 149 tests, all synthetic, no real data needed. CI runs a pinned-repro job (exact
177
281
  pins), a cross-version/OS compat matrix, and a strict docs build. Six float-sensitive tests
178
282
  reproduce only under the pins in `requirements-dev.txt`; the optional marginal-fidelity gate
179
283
  compares the SCM against a **private** real dataset via `CLDD_DATA_DIR` and is the only thing
@@ -189,17 +293,21 @@ that needs it. Details, reproducibility, and troubleshooting:
189
293
  | [docs/configuration.md](docs/configuration.md) | every knob (`config.py`) and the one env var |
190
294
  | [docs/validation.md](docs/validation.md) | tests, gates, reproducibility, troubleshooting |
191
295
  | [docs/reject_inference.md](docs/reject_inference.md) | the four RI methods and their honest (modest) results |
192
- | [`FABLE.md`](FABLE.md) | **the accompanying article** — independent results & methodology assessment |
296
+ | [`docs/assessment.md`](docs/assessment.md) | **the accompanying article** — independent results & methodology assessment (dated snapshot) |
193
297
 
194
298
  Build locally: `pip install -e ".[docs]" && sphinx-build -b html -W docs docs/_build/html`.
195
299
 
196
300
  ## Status
197
301
 
198
- `0.1.0` **alpha** on [PyPI](https://pypi.org/project/closed-loop-default-detection/),
199
- changelog in [CHANGELOG.md](CHANGELOG.md). Shipped: the loop, both worlds, all levers, the
200
- fidelity gate, the sklearn estimator, CI on three gates. CLDD began as a validation harness
201
- for the Intuit TechWeek SMB Underwriting Challenge; it is not a submission and does not
202
- alter challenge files.
302
+ `0.2.0` **alpha** on [PyPI](https://pypi.org/project/closed-loop-default-detection/),
303
+ changelog in [CHANGELOG.md](CHANGELOG.md).
304
+
305
+ Shipped in 0.1.0: the loop, both synthetic worlds, all correction levers, the fidelity gate,
306
+ the sklearn estimator, CI on three gates. Added in 0.2.0: `cldd.emp` (both EMP variants),
307
+ priced exploration, the EMP-optimal cutoff, and the 25-seed frontier sweep.
308
+
309
+ CLDD began as a validation harness for the Intuit TechWeek SMB Underwriting Challenge; it is
310
+ not a submission and does not alter challenge files.
203
311
 
204
312
  ## Citation
205
313
 
@@ -211,7 +319,7 @@ Metadata in [`CITATION.cff`](CITATION.cff) (GitHub's "Cite this repository" read
211
319
  title = {{closed-loop-default-detection}: measuring selective-labels default
212
320
  detection and the PD model's operating frontier},
213
321
  year = {2026},
214
- version = {0.1.0},
322
+ version = {0.2.0},
215
323
  license = {MIT},
216
324
  url = {https://github.com/hossainpazooki/closed-loop-default-detection}
217
325
  }
@@ -0,0 +1,292 @@
1
+ # CLDD — closed-loop default detection
2
+
3
+ [![CI](https://github.com/hossainpazooki/closed-loop-default-detection/actions/workflows/ci.yml/badge.svg)](https://github.com/hossainpazooki/closed-loop-default-detection/actions/workflows/ci.yml)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
5
+ [![Docs: Sphinx](https://img.shields.io/badge/docs-sphinx-blue.svg)](docs/)
6
+ [![Python ≥3.10](https://img.shields.io/badge/python-%E2%89%A53.10-blue.svg)](pyproject.toml)
7
+
8
+ **Stress-test a probability-of-default (PD) model under *selective labels* — and get the
9
+ severity at which it breaks.** Real lending data only labels the loans a prior underwriter
10
+ approved, so you cannot measure calibration on the applicants you *declined* — exactly where a
11
+ new model must still be right. CLDD builds synthetic lending worlds with planted ground truth,
12
+ hides labels the way real approval policies do, and grades every correction against that truth.
13
+
14
+ - **Deterministic** — byte-identical per seed, scikit-learn-only, no services or GPUs.
15
+ - **Pluggable** — correction levers (IPW, retrain, exploration, reject inference) are classes;
16
+ add yours by subclassing `Corrector`.
17
+ - **Honest by construction** — every number below recomputes from committed CSVs; limits are
18
+ reported, not smoothed over.
19
+
20
+ ## The result it produces
21
+
22
+ The loop escalates selection severity until correction fails and reports the **operating
23
+ frontier** — the last severity at which declined-cohort calibration still holds (target
24
+ ECE ≤ 0.10). From the committed runs (`artifacts/loop_frontier*.csv`, seed 42):
25
+
26
+ | Selection severity | 0.0 | 0.2 | 0.4 | 0.6 |
27
+ |---|---|---|---|---|
28
+ | Naive declined ECE (flat world) | 0.021 | 0.045 | 0.108 | 0.161 |
29
+ | **IPW-corrected** (flat world) | 0.020 | 0.038 | **0.086 ✓** | **0.154 ✗** |
30
+ | **IPW-corrected** (SCM world) | 0.036 | 0.038 | **0.097 ✓** | **0.244 ✗** |
31
+
32
+ On **this seed** both worlds land the frontier at severity 0.4, and the counterfactual
33
+ deliverable breaks at the same boundary: across 25 seeds, g-computation cuts
34
+ strong-propagation counterfactual MAE from 0.099 to 0.086 (−13.5%, positive on 24/25 seeds,
35
+ Wilcoxon p = 1.5e-7) *inside* the frontier — and collapses to a negligible +0.0017 at full
36
+ severity, where **no deployable advantage is claimed**. One cause explains both: selection
37
+ through an **unobserved confounder**, which backdoor adjustment and IPW cannot fix. That
38
+ single measured limit — not an unverifiable score — is the deliverable.
39
+
40
+ ### The frontier is a distribution, not a point (v2)
41
+
42
+ A frontier quoted from one seed is a figure published without an error bar. `v0.2.0` runs the
43
+ loop across the full 25-seed set (`artifacts/frontier_sweep.csv`) — and **seed 42 turns out to
44
+ sit at the optimistic end**:
45
+
46
+ | World | min | median | max | seeds at 0.4 | seeds at 0.2 |
47
+ |---|---|---|---|---|---|
48
+ | flat | 0.2 | **0.4** | 0.4 | 15/25 | 10/25 |
49
+ | SCM | 0.2 | **0.2** | 0.4 | 11/25 | 14/25 |
50
+
51
+ In the SCM world the *majority of seeds fail one step earlier than the headline*: the median
52
+ frontier is **0.2**, and seed 42's 0.4 is a minority outcome (11/25). The honest statement is
53
+ that the operating frontier is **0.2–0.4 depending on the draw**, not a clean 0.4 — the
54
+ single-seed table above is a valid instance of it, not its center. Nothing about the
55
+ mechanism changes (the unobserved confounder still explains the failure); what changes is how
56
+ precisely the boundary can be quoted.
57
+
58
+ *Caveat on the sweep:* loop seed `s` consumes generator seeds `s..s+7`, and the 25-seed set has
59
+ gaps smaller than 8, so some runs share feature draws. No two runs duplicate a cohort, but the
60
+ 25 rows are not fully independent — the set is kept for comparability with the counterfactual
61
+ sweep that uses it.
62
+
63
+ Reproduce the headline from committed evidence: `python scripts/paired_significance.py`.
64
+ The full independent assessment (methodology, all numbers, what didn't hold) is the
65
+ accompanying article, [`docs/assessment.md`](docs/assessment.md) — a **dated snapshot**, written
66
+ against the single-seed frontier and not retro-fitted with the distribution above.
67
+
68
+ ## Pricing the frontier (v2)
69
+
70
+ Calibration says *whether* the model is wrong on the declines; it does not say **what being
71
+ wrong costs**. v2 adds an expected-maximum-profit (EMP) reporting axis — computed from the
72
+ same in-process scores the loop already measures, and **never** a loop-control input (ECE
73
+ still decides pass/fail and the frontier). Two variants run side by side:
74
+
75
+ | Variant | Parameters | What it answers |
76
+ |---|---|---|
77
+ | `empc` — literature EMPC | Verbraken et al. (2014) prior: `p0=0.55, p1=0.10, ROI=0.2644` | benchmark-comparable: what the standard measure says |
78
+ | `emp_h` — harness-derived | this harness's own economics + **planted** default timing | what the loan structure actually pays |
79
+
80
+ **The two disagree — and the disagreement is the finding.** In the SCM world they move in
81
+ opposite directions as selection severity rises (from `artifacts/loop_frontier_scm.csv`,
82
+ declined subpopulation, seed 42):
83
+
84
+ | Selection severity | 0.0 | 0.2 | 0.4 | 0.6 |
85
+ |---|---|---|---|---|
86
+ | Literature `empc` (naive) | 0.0217 | 0.0331 | 0.0416 | **0.0420 ↑** |
87
+ | Harness `emp_h` (naive) | 0.0387 | 0.0297 | 0.0139 | **0.0024 ↓** |
88
+
89
+ The convenience prior **misprices this loan structure**: it assumes `ROI = 0.2644` where a
90
+ 60-day daily-ACH loan actually returns `0.0875` (3% origination fee + 5.75% term interest) —
91
+ a **3.0× overstatement** — and puts **55% of defaults at full recovery where the harness plants
92
+ 1.2%** (prior mean λ = 0.275 vs harness 0.419). Priced honestly, the profit on the declined
93
+ pool collapses to near-zero at the frontier; priced by the literature prior, it appears to
94
+ *grow*. Same model, same scores, opposite conclusion.
95
+
96
+ **Reading caveats — the boundary of what this measures:**
97
+
98
+ - **Raw EMP moves with world hardness.** A riskier declined pool changes EMP even for a
99
+ perfect model, so a cross-severity EMP delta is *not* pure model signal. Read the two
100
+ variants against each other at fixed severity, not the trend in isolation.
101
+ - **`emp_h` rests on unfitted timing.** `days_to_default` is planted but independent of
102
+ features and risk given default — spec-shaped, never validated against real recovery data.
103
+ So `emp_h` is a **verified experiment, not a verified result**: the arithmetic is exact, the
104
+ timing distribution is an assumption.
105
+ - **Post-term defaults are imputed.** ~22.5% of planted defaults land at day 90, past the
106
+ 60-day term, and the generator does not model their payment history; they are priced at the
107
+ cohort's mean in-term loss fraction (a stated convention, not measured truth).
108
+ - **`emp_h` is SCM-only.** The flat generator plants no timing, so its `emp_h` columns are
109
+ empty by design; only `empc` is reported there.
110
+
111
+ Exploration now carries a price tag too. From `artifacts/exploration_frontier.csv` (SCM,
112
+ seed 42, 10% budget, severity 0.6): the lever buys **157 labels for $439,578** — about
113
+ **$2,800 per label**, of which 56 are realized defaults. That is the cost of *identification*,
114
+ in dollars a lender can see, on the only lever that buys it rather than reweighting what is
115
+ already identified.
116
+
117
+ ## Pricing the feedback loop (v3)
118
+
119
+ `v0.3.0` prices the **dynamic** regime, where the model's own approvals create its next
120
+ training set: three arms (treatment = retrain each generation; **frozen** = generation-0
121
+ model deployed forever; **prior** = prior-policy funding), 25 spaced seeds × 3 severities ×
122
+ 2 exploration rates × 12 generations = **450 runs**
123
+ (`artifacts/feedback_profit_sweep.csv`), with three pre-registered hypotheses tested as
124
+ within-seed paired contrasts on realized funded-book P&L at severity 0.4, Holm-corrected.
125
+ Every number below recomputes via `python scripts/feedback_sweep_stats.py`. All of it
126
+ consumes **planted, risk-unlinked default timing** — a verified *experiment*, not a
127
+ verified *result*.
128
+
129
+ | Hypothesis (severity 0.4, gens 1–11) | Median paired deficit | Sign | Verdict |
130
+ |---|---|---|---|
131
+ | H1 feedback accumulation costs money (treatment − frozen, ε=0) | **−0.0028** | 24/25 | **confirmed** (p_holm 2.3e-06, clears the 0.0018 noise floor) |
132
+ | H2 the policy switch costs money (frozen − prior, ε=0) | +0.0119 | 0/25 | **not confirmed — measured opposite in direction** |
133
+ | H3 exploration buys profit back (treatment ε=.05 − ε=0) | −0.0024 | 0/25 | **not confirmed** |
134
+
135
+ The decomposition v3 exists for came back one-for-three: letting the loop close on its own
136
+ labels measurably costs the book (H1), but at these severities the *switch* to model-based
137
+ funding is profitable relative to the prior policy (H2's predicted sign was wrong — reported
138
+ as measured, not softened), and 5% exploration does not pay for itself in-window (H3; the
139
+ policy-book-only secondary H3a is negative too). The **H4 integrity control** — frozen-arm
140
+ paired difference must equal the explored slice's own P&L *exactly* — holds at ≤1e-10 across
141
+ all 900 checked rows, and the answer to the v2-banked question is re-verified at 25 seeds:
142
+ the declined-ECE alarm fires at generation 1–2 in every ε=0 run (severity 0.4: 25/25 at
143
+ generation 1). Full mechanics in [`docs/how-it-works.md`](docs/how-it-works.md); gates in
144
+ [`docs/validation.md`](docs/validation.md).
145
+
146
+ ## Install
147
+
148
+ ```bash
149
+ pip install closed-loop-default-detection
150
+ ```
151
+
152
+ The import name is **`cldd`**. For development (tests, docs, the committed evidence),
153
+ install from source:
154
+
155
+ ```bash
156
+ git clone https://github.com/hossainpazooki/closed-loop-default-detection.git
157
+ cd closed-loop-default-detection
158
+ pip install -e ".[dev]"
159
+ ```
160
+
161
+ Python ≥ 3.10; dependencies are ranges (`numpy>=2.0`, `pandas>=2.2`, `scikit-learn>=1.6`,
162
+ `scipy>=1.11`, `matplotlib>=3.8`) so `cldd` sits alongside your stack. Exact pins for
163
+ float-exact reproduction: [`requirements-dev.txt`](requirements-dev.txt)
164
+ ([details](docs/validation.md)).
165
+
166
+ ## 60-second tour
167
+
168
+ ```python
169
+ from cldd import SelectiveLabelsLoop
170
+
171
+ result = SelectiveLabelsLoop(improve_mode="both").run() # "reweight" | "retrain" | "both"
172
+ print("Operating frontier:", result.frontier_severity)
173
+ for r in result.rounds:
174
+ print(r.selection_severity, r.naive.declined_ece, r.passed)
175
+ ```
176
+
177
+ ```mermaid
178
+ flowchart TD
179
+ A["<b>1. Generate</b><br/>synthetic cohort at a given selection severity<br/>plant true default, then hide it via the approval policy"]
180
+ B["<b>2. Measure</b><br/>train the PD model on approved rows only,<br/>score it against planted truth on the declined subpopulation"]
181
+ C["<b>3. Improve</b><br/>apply a correction lever:<br/>IPW reweight &middot; disjoint retrain &middot; exploration"]
182
+ D{"Corrected declined-cohort<br/>ECE &le; target?"}
183
+ E["<b>Operating frontier</b><br/>report the highest severity<br/>that still passes"]
184
+
185
+ A --> B --> C --> D
186
+ D -->|"yes &mdash; raise the severity"| A
187
+ D -->|"no &mdash; stop"| E
188
+ ```
189
+
190
+ A runnable end-to-end demo (classic + custom-lever paths) is
191
+ [`examples/quickstart.py`](examples/quickstart.py). Full mechanics, diagnostics, and the
192
+ feedback simulation: [docs/how-it-works.md](docs/how-it-works.md).
193
+
194
+ > **Scope.** CLDD is a synthetic **validation harness**, not a production pipeline: retraining
195
+ > and feedback are seeded simulations inside the harness; it never acts on live data or real
196
+ > lending decisions.
197
+
198
+ ## What's in the box
199
+
200
+ Everything is importable from top-level `cldd` (full reference: the [Sphinx docs](docs/)):
201
+
202
+ | Import | What it is |
203
+ |---|---|
204
+ | `SelectiveLabelsLoop` | the closed loop; `.run()` → `LoopResult` (frontier + per-round metrics) |
205
+ | `Corrector` + `NaiveCorrector`, `IPWReweightCorrector`, `DisjointRetrainCorrector`, `ExplorationCorrector` | the lever ABC and the four built-ins |
206
+ | `ReclassificationCorrector`, `AugmentationCorrector`, `FuzzyAugmentationCorrector`, `ParcellingCorrector` | four classic reject-inference methods, graded against planted truth ([honest results](docs/reject_inference.md)) |
207
+ | `SyntheticBorrowerGenerator`, `StructuralBorrowerGenerator` | the flat and fitted-SCM synthetic worlds |
208
+ | `run_counterfactual_eval`, `GComputationEstimator` | counterfactual validator (g-computation vs naive conditioning) |
209
+ | `FeedbackLoop` | model-in-the-loop selective-labels simulation |
210
+ | `empc_literature`, `emp_harness` | the two EMP variants — price the frontier in profit (reporting only, never loop control) |
211
+ | `positivity_diagnostics` | observable regime/drift alarm — needs **no** declined-row labels |
212
+ | `CalibratedPDClassifier` | the calibrated PD detector as a scikit-learn estimator |
213
+ | `cldd.fidelity.run_fidelity_gate` | SCM-vs-real **marginal**-fidelity gate (univariate marginals only) |
214
+
215
+ **Add a lever** by subclassing `Corrector` (`name`, `control_priority`, `apply`) and passing
216
+ `correctors=[NaiveCorrector(), MyCorrector()]` — the legacy `improve_mode` API is unchanged
217
+ and byte-identical. Contract details: [CONTRIBUTING.md](CONTRIBUTING.md).
218
+
219
+ **Use the detector from sklearn tooling** — `CalibratedPDClassifier` is a thin, tested wrapper
220
+ (binary-only; NaN features OK; the full `check_estimator` battery passes with zero failed
221
+ checks on scikit-learn 1.7.2–1.9.0; probabilities byte-identical to the research API):
222
+
223
+ ```python
224
+ from sklearn.model_selection import cross_val_score
225
+ from cldd import CalibratedPDClassifier
226
+
227
+ scores = cross_val_score(CalibratedPDClassifier(random_state=42), X, y, scoring="neg_brier_score")
228
+ ```
229
+
230
+ ## Command-line drivers
231
+
232
+ Each driver runs without install (adds `src/` to the path) and writes to `artifacts/`:
233
+
234
+ ```bash
235
+ python scripts/run_loop.py # the closed loop → frontier table + plot (--generator scm for the SCM world)
236
+ python scripts/run_frontier_sweep.py --quick # frontier distribution across the 25-seed set (drop --quick for all)
237
+ python scripts/run_seed_sweep.py --quick # counterfactual certification (drop --quick for all seeds)
238
+ python scripts/run_reject_inference.py # reject-inference levers vs the frontier
239
+ python scripts/run_exploration_sweep.py # frontier vs exploration budget
240
+ python scripts/run_feedback.py # model-in-the-loop feedback simulation
241
+ python scripts/paired_significance.py # recompute the headline stat from committed CSVs
242
+ ```
243
+
244
+ ## Validation
245
+
246
+ `pytest` — 149 tests, all synthetic, no real data needed. CI runs a pinned-repro job (exact
247
+ pins), a cross-version/OS compat matrix, and a strict docs build. Six float-sensitive tests
248
+ reproduce only under the pins in `requirements-dev.txt`; the optional marginal-fidelity gate
249
+ compares the SCM against a **private** real dataset via `CLDD_DATA_DIR` and is the only thing
250
+ that needs it. Details, reproducibility, and troubleshooting:
251
+ [docs/validation.md](docs/validation.md).
252
+
253
+ ## Documentation
254
+
255
+ | Where | What |
256
+ |---|---|
257
+ | [docs/quickstart.md](docs/quickstart.md) | run the loop, the counterfactual eval, the fidelity report |
258
+ | [docs/how-it-works.md](docs/how-it-works.md) | loop mechanics, diagnostics, feedback simulation, repo map |
259
+ | [docs/configuration.md](docs/configuration.md) | every knob (`config.py`) and the one env var |
260
+ | [docs/validation.md](docs/validation.md) | tests, gates, reproducibility, troubleshooting |
261
+ | [docs/reject_inference.md](docs/reject_inference.md) | the four RI methods and their honest (modest) results |
262
+ | [`docs/assessment.md`](docs/assessment.md) | **the accompanying article** — independent results & methodology assessment (dated snapshot) |
263
+
264
+ Build locally: `pip install -e ".[docs]" && sphinx-build -b html -W docs docs/_build/html`.
265
+
266
+ ## Status
267
+
268
+ `0.2.0` **alpha** on [PyPI](https://pypi.org/project/closed-loop-default-detection/),
269
+ changelog in [CHANGELOG.md](CHANGELOG.md).
270
+
271
+ Shipped in 0.1.0: the loop, both synthetic worlds, all correction levers, the fidelity gate,
272
+ the sklearn estimator, CI on three gates. Added in 0.2.0: `cldd.emp` (both EMP variants),
273
+ priced exploration, the EMP-optimal cutoff, and the 25-seed frontier sweep.
274
+
275
+ CLDD began as a validation harness for the Intuit TechWeek SMB Underwriting Challenge; it is
276
+ not a submission and does not alter challenge files.
277
+
278
+ ## Citation
279
+
280
+ Metadata in [`CITATION.cff`](CITATION.cff) (GitHub's "Cite this repository" reads it):
281
+
282
+ ```bibtex
283
+ @software{pazooki_cldd_2026,
284
+ author = {Pazooki, Hossain},
285
+ title = {{closed-loop-default-detection}: measuring selective-labels default
286
+ detection and the PD model's operating frontier},
287
+ year = {2026},
288
+ version = {0.2.0},
289
+ license = {MIT},
290
+ url = {https://github.com/hossainpazooki/closed-loop-default-detection}
291
+ }
292
+ ```
@@ -4,13 +4,13 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "closed-loop-default-detection"
7
- version = "0.1.0"
8
- description = "CLUE-style closed loop that measures selective-labels default detection on synthetic SMB lending cohorts and finds the PD model's operating frontier."
7
+ version = "0.3.0"
8
+ description = "Closed loop that measures selective-labels default detection on synthetic SMB lending cohorts and finds the PD model's operating frontier."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
11
11
  license = "MIT"
12
12
  license-files = ["LICENSE"]
13
- authors = [{ name = "Hossain Pazooki", email = "hossain@pazooki.com" }]
13
+ authors = [{ name = "Hossain Pazooki" }]
14
14
  keywords = [
15
15
  "selective-labels",
16
16
  "probability-of-default",
@@ -1,7 +1,7 @@
1
- """Closed-loop default-rate detection — a CLUE-style harness for selective labels.
1
+ """Closed-loop default-rate detection — a selective-labels validation harness.
2
2
 
3
3
  generate (``synthetic``) -> measure (``eval_default``) -> improve/frontier
4
- (``loop``). See README.md for the CLUE mapping and how to run.
4
+ (``loop``). See README.md for how to run.
5
5
  """
6
6
 
7
7
  from __future__ import annotations
@@ -11,7 +11,7 @@ from importlib.metadata import PackageNotFoundError, version as _pkg_version
11
11
  try: # pyproject `version` is the single source of truth (read from installed metadata)
12
12
  __version__ = _pkg_version("closed-loop-default-detection")
13
13
  except PackageNotFoundError: # running from a source tree with no install
14
- __version__ = "0.1.0"
14
+ __version__ = "0.2.0"
15
15
 
16
16
  from .correctors import (
17
17
  CorrectionOutcome,
@@ -36,6 +36,13 @@ from .reject_inference import (
36
36
  ReclassificationCorrector,
37
37
  RejectInferenceCorrector,
38
38
  )
39
+ from .emp import (
40
+ EMPCParams,
41
+ EMPResult,
42
+ LoanEconomics,
43
+ emp_harness,
44
+ empc_literature,
45
+ )
39
46
  from .eval_default import PdDetectionResult, fit_observed_model, score_pd_detection
40
47
  from .model_pd import CalibratedPDClassifier, CalibratedPDModel
41
48
  from .feedback import FeedbackLoop, FeedbackResult, GenerationResult
@@ -87,6 +94,11 @@ __all__ = [
87
94
  "PdDetectionResult",
88
95
  "fit_observed_model",
89
96
  "score_pd_detection",
97
+ "EMPCParams",
98
+ "EMPResult",
99
+ "LoanEconomics",
100
+ "empc_literature",
101
+ "emp_harness",
90
102
  "CalibratedPDModel",
91
103
  "CalibratedPDClassifier",
92
104
  "CounterfactualResult",
@@ -24,8 +24,7 @@ RANDOM_SEED = 42
24
24
 
25
25
  # Disjoint train-cohort offset for the retrain lever. Large enough that train
26
26
  # seeds (RANDOM_SEED + TRAIN_SEED_OFFSET + iteration) never collide with measure
27
- # seeds (RANDOM_SEED + iteration). This is the no-leakage discipline ported from
28
- # upstream-label-correction/clue/loop.py.
27
+ # seeds (RANDOM_SEED + iteration).
29
28
  TRAIN_SEED_OFFSET = 1000
30
29
 
31
30
  # --------------------------------------------------------------------------- #
@@ -59,6 +58,19 @@ TARGET_DECLINED_ECE = 0.10
59
58
 
60
59
  DEFAULT_N_APPLICANTS = 4000
61
60
 
61
+ # --------------------------------------------------------------------------- #
62
+ # EMP reporting layer (cldd.emp) — v2 measurement axis, never loop control
63
+ # --------------------------------------------------------------------------- #
64
+ # Literature EMPC prior. Verified against the primary source before entry
65
+ # (2026-07-13 spike): Verbraken, Bravo, Weber & Baesens (2014), EJOR
66
+ # 238(2):505-513 — h(lambda) = p0*delta(0) + p1*delta(1) + (1-p0-p1)*U(0,1),
67
+ # constant ROI, computed over the ROC convex hull (paper Eqs. 13/15). The
68
+ # defaults are the benchmark-standard CRAN EMP::empCreditScoring values, so
69
+ # empc columns are comparable to the published literature.
70
+ EMPC_P0 = 0.55 # P(lambda = 0): full recovery
71
+ EMPC_P1 = 0.10 # P(lambda = 1): total loss
72
+ EMPC_ROI = 0.2644 # per-loan return on investment, fraction of principal
73
+
62
74
  # --------------------------------------------------------------------------- #
63
75
  # Observable positivity-diagnostic thresholds (cldd.diagnostics)
64
76
  # --------------------------------------------------------------------------- #