# Identity resolution when signals disappear

A synthetic shop with a content site and an app, where the true person behind every visit is known. Identifying
signals are taken away one at a time and then together (a browser family that caps cookies and drops cross-site
links, withheld device advertising ids, declined or withdrawn consent, a platform migration that re-keys every id),
and three stitching rules are scored against the truth: deterministic, deterministic plus probabilistic matching, and
a probabilistic band. It asks how far user counts, conversion rates and channel shares drift, and which rule stays
honest about what it cannot know. The page is `index.html`.

All data is synthetic, generated on fixed seeds. No real person, customer or company data is used. Every rate is a
declared assumption, listed in `DESIGN.md`.

## What is here

| File | What it is |
|---|---|
| `index.html` | The study page, built by `idr/report.py` from `results/results.json` |
| `DESIGN.md` | The design, with every rate, the rules, the measures and the predictions, written before any result |
| `idr/generate.py` | The synthetic people, devices and visits |
| `idr/observe.py` | What the data records under each signal-loss scenario |
| `idr/stitch.py` | The stitching rules: deterministic, the match model (label-trained and unsupervised), the band draws |
| `idr/measure.py` | Measures against the truth: counts, merges and splits, conversion rate, last-touch and position credit |
| `idr/run.py`, `idr/summarize.py` | One aggregate file per scenario and seed, then the summary |
| `results/cells/` | The per-run aggregates (counts, rates and shares only) |
| `idr/sweep.py`, `results/sweep/` | Added after the results: all four losses at three decline rates and three capped phone-browser shares, 10 seeds each |
| `results/consent-audit.json` | Per seed, the share of true users who declined consent, beside the band's estimate |
| `results/results.json` | Every aggregate the page shows |
| `results/page-numbers.json`, `results/page-constants.json` | The map from each number on the page to its source |
| `tools/check_numbers.py` | Traces every number on the page to the results file or a declared constant |
| `tests/` | Unit cases on small tables written into the test code, a small seeded end-to-end run, and a replay of the results and the page |

## Reproduce it

Python 3.12, with the pinned dependencies:

```
python3.12 -m venv .venv
.venv/bin/pip install -r requirements.lock
.venv/bin/python -B -m idr.run cells       # 10 seeds x 6 scenarios -> results/cells/
.venv/bin/python -B -m idr.sweep run       # the added rate sweep -> results/sweep/
.venv/bin/python -B -m idr.sweep consent   # results/consent-audit.json
.venv/bin/python -B -m idr.run summary     # results/results.json
.venv/bin/python -B -m idr.report          # index.html and the number map
.venv/bin/python -B -m pytest tests -q -p no:cacheprovider
.venv/bin/python -I tools/check_numbers.py
```

The tests need no network.

## Design summary

- Six scenarios on the same people: baseline; cookie loss; device ids withheld; consent declined or withdrawn; a
  migration that re-keys every id; all four at once.
- Rules: deterministic (login, verified email, device advertising id); probabilistic (Fellegi-Sunter weights learnt
  from the deterministic rule's labels, link at a posterior of 0.9); band (60 draws from the same posteriors, 5th to
  95th percentile, visits without consent reported apart). An unsupervised fit of the same model and its band were
  added after a development run on a separate seed, before any reported run, and are labelled so.
- Consent is enforced in every rule: rows after a decline or withdrawal carry no identifier and are never matched.
- Per scenario, the mean of 10 runs with the lowest and highest; nothing is pooled across scenarios.
- Added after the results were read: the decline rate (4%, 8%, 16%) and the capped share of phone browsers (30%, 55%,
  80%) swept with all four losses, on the same seeds; user counts are reported both as a distinct-id count and as
  identified users only.

## Second part: one record per customer

`master-record.html` builds one master record per customer from three systems of the same synthetic shop (a CRM, a
billing system and a product database) and scores deterministic keys, probabilistic matching at five thresholds, a
steward queue and three survivorship rules against the known truth. The first part's generator output is unchanged; the new sources come from a separate random stream.

| File | What it is |
|---|---|
| `master-record.html` | The page, built by `idr/mdm_report.py` from `results/master/results.json` |
| `DESIGN-master-record.md`, `protocol-master-record.json` | The design, every rate and the predictions, written before any result, except the session fit and three added measures, which were added after a development run and committed before any reported run |
| `idr/mdm_generate.py` | The CRM, billing and product records and the orders, on the first part's people |
| `idr/mdm_match.py` | Normalisers, deterministic keys, blocking, the match model (declared fit and session fit), linking, the steward queue |
| `idr/mdm_measure.py` | Count error, merges and splits, revenue per customer, survivorship accuracy |
| `idr/mdm_run.py`, `idr/mdm_summarize.py` | One aggregate file per data setting and seed, then the summary |
| `results/master/cells/` | The per-run aggregates (9 data settings x 10 seeds) |
| `results/master/results.json` | Every aggregate the page shows |
| `results/master/page-numbers.json`, `results/master/page-constants.json` | The map from each number on the page to its source |
| `tests/test_master_units.py`, `tests/test_master_replay.py` | Unit cases on small tables, a small seeded end-to-end run, and a replay of the results and the page |

Implementation notes, two code choices not in the design text: non-match probabilities carry add-one smoothing
(`idr/mdm_match.py`, `u_probs`), so no comparison level has a zero probability; and "same address" means the whole
normalised address matches, unit and street type included, while the same postcode alone is a partial agreement. Both were set in the code before any reported run.

Reproduce it, after the setup above:

```
.venv/bin/python -B -m idr.mdm_run cells        # 9 data settings x 10 seeds -> results/master/cells/
.venv/bin/python -B -m idr.mdm_summarize        # results/master/results.json
.venv/bin/python -B -m idr.mdm_report           # master-record.html and its number map
.venv/bin/python -I tools/check_numbers.py --page master-record.html --results results/master/results.json --claims results/master/page-numbers.json
```

## Licence

The code here may be reused. The design system under `vendor/` keeps its own licence and font licences.

Some files are packed in identity-resolution-data-1.zip; unzip it here to restore the full export, which the manifest lists file by file.
