payoff 0.1.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.
- payoff-0.1.0/.github/dependabot.yml +10 -0
- payoff-0.1.0/.github/workflows/ci.yml +29 -0
- payoff-0.1.0/.github/workflows/release.yml +37 -0
- payoff-0.1.0/.gitignore +10 -0
- payoff-0.1.0/.python-version +1 -0
- payoff-0.1.0/CHANGELOG.md +19 -0
- payoff-0.1.0/CITATION.cff +11 -0
- payoff-0.1.0/LICENSE +21 -0
- payoff-0.1.0/PKG-INFO +234 -0
- payoff-0.1.0/README.md +207 -0
- payoff-0.1.0/RELEASING.md +37 -0
- payoff-0.1.0/SECURITY.md +24 -0
- payoff-0.1.0/examples/quickstart.py +75 -0
- payoff-0.1.0/pyproject.toml +69 -0
- payoff-0.1.0/src/payoff/__init__.py +69 -0
- payoff-0.1.0/src/payoff/discretion.py +26 -0
- payoff-0.1.0/src/payoff/measure.py +284 -0
- payoff-0.1.0/src/payoff/model.py +297 -0
- payoff-0.1.0/src/payoff/py.typed +0 -0
- payoff-0.1.0/tests/data/payoff-workbook.xlsx +0 -0
- payoff-0.1.0/tests/test_measure.py +59 -0
- payoff-0.1.0/tests/test_model.py +83 -0
- payoff-0.1.0/tests/test_repo.py +39 -0
- payoff-0.1.0/tests/test_workbook.py +173 -0
- payoff-0.1.0/uv.lock +514 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
strategy:
|
|
15
|
+
fail-fast: false
|
|
16
|
+
matrix:
|
|
17
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
20
|
+
with:
|
|
21
|
+
persist-credentials: false
|
|
22
|
+
- uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
|
23
|
+
with:
|
|
24
|
+
python-version: ${{ matrix.python-version }}
|
|
25
|
+
- run: uv sync --locked
|
|
26
|
+
- run: uv run ruff check
|
|
27
|
+
- run: uv run ruff format --check
|
|
28
|
+
- run: uv run mypy
|
|
29
|
+
- run: uv run pytest
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
# Publishes to PyPI when a version tag such as v0.1.0 is pushed. Uses PyPI
|
|
4
|
+
# trusted publishing, so no password or API token is stored anywhere.
|
|
5
|
+
# Setup steps are in RELEASING.md.
|
|
6
|
+
|
|
7
|
+
on:
|
|
8
|
+
push:
|
|
9
|
+
tags: ["v*"]
|
|
10
|
+
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
publish:
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
environment: pypi
|
|
18
|
+
permissions:
|
|
19
|
+
contents: read
|
|
20
|
+
id-token: write
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
23
|
+
with:
|
|
24
|
+
persist-credentials: false
|
|
25
|
+
- uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
|
26
|
+
with:
|
|
27
|
+
python-version: "3.12"
|
|
28
|
+
- name: Check the tag matches the version
|
|
29
|
+
env:
|
|
30
|
+
TAG: ${{ github.ref_name }}
|
|
31
|
+
run: |
|
|
32
|
+
version=$(uv run --no-project python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
|
|
33
|
+
test "$TAG" = "v$version" || { echo "Tag $TAG does not match version $version"; exit 1; }
|
|
34
|
+
- run: uv sync --locked
|
|
35
|
+
- run: uv run pytest
|
|
36
|
+
- run: uv build
|
|
37
|
+
- run: uv publish --trusted-publishing always
|
payoff-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes are listed here. The project follows
|
|
4
|
+
[Semantic Versioning](https://semver.org/).
|
|
5
|
+
|
|
6
|
+
## 0.1.0 - 2026-11-30
|
|
7
|
+
|
|
8
|
+
First release.
|
|
9
|
+
|
|
10
|
+
- `model`: expected value per item for review-everything, no-review, and
|
|
11
|
+
routed designs; best cut-off within review capacity, exact at the capacity
|
|
12
|
+
edge; break-even accuracy; value of more capacity; payback on the build
|
|
13
|
+
and net value over its years of use.
|
|
14
|
+
- `measure`: ranges, one-at-a-time sensitivity, joint simulation, value of
|
|
15
|
+
information per input; reviewer statistics (Beta update, Wilson interval,
|
|
16
|
+
seeded-error sample size, error rate implied by edits).
|
|
17
|
+
- `discretion`: proceed, wait, or stop for a project taken on for its option
|
|
18
|
+
value.
|
|
19
|
+
- Tests that reproduce the published workbook's numbers.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use this software, please cite it as below."
|
|
3
|
+
title: "payoff: decide whether an AI system is worth using"
|
|
4
|
+
authors:
|
|
5
|
+
- family-names: Daigle
|
|
6
|
+
given-names: Christopher
|
|
7
|
+
version: 0.1.0
|
|
8
|
+
date-released: 2026-11-30
|
|
9
|
+
license: MIT
|
|
10
|
+
repository-code: "https://github.com/ChristopherDaigle/payoff"
|
|
11
|
+
url: "https://quantchris.com/posts/2026-11-29-is-it-possible-and-is-it-worth-it.html"
|
payoff-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Christopher Daigle
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
payoff-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: payoff
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Decide whether an AI system is worth using, and how much of its output people should check.
|
|
5
|
+
Project-URL: Homepage, https://github.com/ChristopherDaigle/payoff
|
|
6
|
+
Project-URL: Source, https://github.com/ChristopherDaigle/payoff
|
|
7
|
+
Project-URL: Issues, https://github.com/ChristopherDaigle/payoff/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/ChristopherDaigle/payoff/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Article, https://quantchris.com/posts/2026-11-29-is-it-possible-and-is-it-worth-it.html
|
|
10
|
+
Author: Christopher Daigle
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: decision analysis,expected value,human in the loop,model evaluation,value of information
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# payoff
|
|
29
|
+
|
|
30
|
+
Decide whether an AI system is worth using, and how much of its output
|
|
31
|
+
people should check.
|
|
32
|
+
|
|
33
|
+
[](https://github.com/ChristopherDaigle/payoff/actions/workflows/ci.yml)
|
|
34
|
+
|
|
35
|
+
Most AI work is funded on a model metric (accuracy, F1, AUC) and a business
|
|
36
|
+
case that assumes the model does all the work. Neither says whether the
|
|
37
|
+
*system* is worth having: the model, the cut-off someone chose, the people who
|
|
38
|
+
check some of its output, and the capacity they have. `payoff` prices every
|
|
39
|
+
outcome of that system, finds the best share of work to send to people, and
|
|
40
|
+
shows which uncertain inputs are worth measuring before you decide.
|
|
41
|
+
|
|
42
|
+
The name is the decision-theory term. Every way a decision can turn out has a
|
|
43
|
+
payoff, and the best design is the one with the highest expected payoff once
|
|
44
|
+
the model's errors, the reviewers' time, and the build are all counted.
|
|
45
|
+
|
|
46
|
+
It is the code companion to two articles:
|
|
47
|
+
|
|
48
|
+
- [Is It Possible, and Is It Worth It?](https://quantchris.com/posts/2026-11-29-is-it-possible-and-is-it-worth-it.html)
|
|
49
|
+
covers what to do with the costs and benefits.
|
|
50
|
+
- [Where the Numbers Come From](https://quantchris.com/posts/2026-11-29-where-the-numbers-come-from.html)
|
|
51
|
+
covers how to get them.
|
|
52
|
+
|
|
53
|
+
The same calculations are in a
|
|
54
|
+
[workbook](https://quantchris.com/assets/files/payoff-workbook.xlsx) for
|
|
55
|
+
readers who prefer a spreadsheet. The tests check that this package and the
|
|
56
|
+
workbook give the same numbers.
|
|
57
|
+
|
|
58
|
+
## Install
|
|
59
|
+
|
|
60
|
+
With [uv](https://docs.astral.sh/uv/):
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
uv add payoff
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
or with pip: `pip install payoff`.
|
|
67
|
+
Python 3.10 or later. No runtime dependencies.
|
|
68
|
+
|
|
69
|
+
## Quick start
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
import payoff
|
|
73
|
+
|
|
74
|
+
# A refund team: 100,000 requests a year, dollars per request.
|
|
75
|
+
hourly = 50.0 # loaded cost per hour of a support rep
|
|
76
|
+
params = payoff.Params(
|
|
77
|
+
value=10.0, # a correct decision is worth what it costs to make today
|
|
78
|
+
error_cost=50.0, # a wrong decision that reaches a customer
|
|
79
|
+
hand_cost=payoff.cost_of_minutes(12, hourly),
|
|
80
|
+
confirm_cost=payoff.cost_of_minutes(3, hourly),
|
|
81
|
+
fix_cost=payoff.cost_of_minutes(6, hourly),
|
|
82
|
+
accuracy=0.80,
|
|
83
|
+
separation=1.5,
|
|
84
|
+
catch_rate=0.90,
|
|
85
|
+
overturn_rate=0.02,
|
|
86
|
+
capacity=0.40,
|
|
87
|
+
run_cost=0.50,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
best = payoff.best_within_capacity(params)
|
|
91
|
+
best.share_reviewed # 0.40: check 40% of requests
|
|
92
|
+
payoff.advantage(params) # 4.81: dollars saved per request versus today
|
|
93
|
+
payoff.payback_months(200_000, payoff.advantage(params) * 100_000) # 5.0
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`examples/quickstart.py` adds sensitivity, simulation, and the value of
|
|
97
|
+
measuring each input:
|
|
98
|
+
|
|
99
|
+
```text
|
|
100
|
+
$ uv run python examples/quickstart.py
|
|
101
|
+
Check 40% of items.
|
|
102
|
+
Advantage over doing it by hand: $4.81 per item,
|
|
103
|
+
$480,911 per year.
|
|
104
|
+
Pays back the build 5.0 months after launch, 9.0 after funding.
|
|
105
|
+
One more point of capacity is worth $4,375 per year.
|
|
106
|
+
|
|
107
|
+
What to measure first (advantage per year, low to high):
|
|
108
|
+
error_cost $646,782 to -$348,443 <- can change the answer
|
|
109
|
+
hand_cost $230,911 to $730,911
|
|
110
|
+
...
|
|
111
|
+
Beats the current process in 66% of 2,000 draws.
|
|
112
|
+
Knowing error_cost exactly is worth about $71,054 per year.
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## What it answers
|
|
116
|
+
|
|
117
|
+
| Question | Function |
|
|
118
|
+
|---|---|
|
|
119
|
+
| What is each design worth per item? | `expected_value_by_hand`, `expected_value_full_automation`, `expected_value_review_all`, `evaluate` |
|
|
120
|
+
| What accuracy does each design need? | `break_even_accuracy_full_automation`, `break_even_accuracy_review_all` |
|
|
121
|
+
| What share should people check, given their capacity? | `best_within_capacity`, `advantage` |
|
|
122
|
+
| What is more review capacity worth? | `capacity_value` |
|
|
123
|
+
| When does the build pay back, and what is it worth over its life? | `payback_months`, `net_value` |
|
|
124
|
+
| Which inputs could change the answer? | `Range`, `sensitivity` |
|
|
125
|
+
| How likely is the system to beat the current process? | `simulate` |
|
|
126
|
+
| Which measurement is worth paying for? | `value_of_information` |
|
|
127
|
+
| What are reviewers' catch and overturn rates? | `beta_posterior_mean`, `wilson_interval`, `seeded_errors_needed` |
|
|
128
|
+
| What error rate do the edits imply? | `implied_error_rate` |
|
|
129
|
+
| The numbers say no: proceed, wait, or stop? | `decide` |
|
|
130
|
+
|
|
131
|
+
Every public function has a docstring with its arguments and return value.
|
|
132
|
+
|
|
133
|
+
## The model
|
|
134
|
+
|
|
135
|
+
Each item gets a confidence score. Items at or above a cut-off go straight
|
|
136
|
+
through; the rest go to a person, up to the review capacity. A person
|
|
137
|
+
confirms a correct draft, fixes a wrong one they catch, misses the rest, and
|
|
138
|
+
now and then changes a correct draft into a wrong one.
|
|
139
|
+
|
|
140
|
+
| Input | Meaning |
|
|
141
|
+
|---|---|
|
|
142
|
+
| `value` | Value of one correct result |
|
|
143
|
+
| `error_cost` | Cost of an error that gets through, on top of the value lost |
|
|
144
|
+
| `hand_cost` | Cost of doing one item from scratch |
|
|
145
|
+
| `confirm_cost`, `fix_cost` | Cost of confirming a correct draft, fixing a wrong one |
|
|
146
|
+
| `accuracy` | Share of outputs that are right |
|
|
147
|
+
| `separation` | How well the score tells right from wrong, in standard deviations |
|
|
148
|
+
| `catch_rate` | Share of wrong drafts people catch |
|
|
149
|
+
| `overturn_rate` | Share of correct drafts people change to wrong |
|
|
150
|
+
| `capacity` | Share of items people can check |
|
|
151
|
+
| `run_cost` | Cost of running the system, per item |
|
|
152
|
+
|
|
153
|
+
Money inputs can be in any one unit. The articles, the workbook, and these
|
|
154
|
+
examples use dollars, with a refund team as the running example. Setting
|
|
155
|
+
`value=1` instead measures everything relative to the value of a correct
|
|
156
|
+
result, which is handy for comparing very different systems.
|
|
157
|
+
|
|
158
|
+
Assumptions, stated so you can judge whether they fit:
|
|
159
|
+
|
|
160
|
+
- Scores are normal with unit variance: mean `separation` for correct
|
|
161
|
+
outputs, mean 0 for wrong ones. Calibrate against your own score
|
|
162
|
+
distributions before relying on the routing result.
|
|
163
|
+
- One error cost per item. Systems with several kinds of error should price
|
|
164
|
+
them separately and use a weighted average, or extend the model.
|
|
165
|
+
- Reviewers' catch and overturn rates do not depend on the cut-off. In
|
|
166
|
+
practice they move when the review queue changes; the articles explain how
|
|
167
|
+
to measure them per queue.
|
|
168
|
+
|
|
169
|
+
## How it matches the workbook
|
|
170
|
+
|
|
171
|
+
`best_within_capacity` searches a grid of cut-offs and then checks the
|
|
172
|
+
cut-off that fills capacity exactly, found by bisection. The workbook does the
|
|
173
|
+
same with formulas (201 cut-offs, 60 bisection steps).
|
|
174
|
+
`tests/test_workbook.py` reads the workbook's computed values and recomputes
|
|
175
|
+
each one from its inputs.
|
|
176
|
+
|
|
177
|
+
## Project layout
|
|
178
|
+
|
|
179
|
+
```text
|
|
180
|
+
src/payoff/
|
|
181
|
+
model.py outcomes, routing, break-even, capacity value, payback
|
|
182
|
+
measure.py ranges, sensitivity, simulation, reviewer statistics
|
|
183
|
+
discretion.py proceed, wait, or stop
|
|
184
|
+
tests/
|
|
185
|
+
test_model.py properties that hold for any inputs
|
|
186
|
+
test_measure.py measurement helpers
|
|
187
|
+
test_workbook.py parity with the published workbook
|
|
188
|
+
test_repo.py every text file is plain ASCII
|
|
189
|
+
data/payoff-workbook.xlsx
|
|
190
|
+
examples/quickstart.py
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Development
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
uv sync # creates .venv from uv.lock
|
|
197
|
+
uv run pytest # tests
|
|
198
|
+
uv run ruff check # lint (Google docstring convention)
|
|
199
|
+
uv run ruff format --check # formatting
|
|
200
|
+
uv run mypy # strict type checks
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
CI runs all four on Python 3.10 to 3.13. Releases go to PyPI from a version
|
|
204
|
+
tag; see [RELEASING.md](RELEASING.md).
|
|
205
|
+
|
|
206
|
+
## Design choices
|
|
207
|
+
|
|
208
|
+
- **No runtime dependencies.** The math needs only the standard library, so
|
|
209
|
+
there is nothing to audit or pin for users.
|
|
210
|
+
- **Frozen dataclasses with validation.** Bad inputs fail when they are
|
|
211
|
+
created, with a message naming the field.
|
|
212
|
+
- **Repeatable randomness.** `simulate` takes a seed and defaults to 0.
|
|
213
|
+
- **Plain text.** A test keeps every text file ASCII, so nothing renders
|
|
214
|
+
differently from one terminal or editor to the next.
|
|
215
|
+
|
|
216
|
+
## Roadmap
|
|
217
|
+
|
|
218
|
+
The articles climb a ladder, and the package will follow it:
|
|
219
|
+
|
|
220
|
+
1. A classic model: two kinds of error, thresholds from costs, ranking under
|
|
221
|
+
fixed capacity.
|
|
222
|
+
2. Extraction: many fields per document and many documents per case, where
|
|
223
|
+
correctness compounds.
|
|
224
|
+
3. AI agents: a sequence of steps that take actions, with approval at
|
|
225
|
+
irreversible ones.
|
|
226
|
+
4. Several AI agents: handoffs, and AI agents checking each other.
|
|
227
|
+
|
|
228
|
+
## Citing
|
|
229
|
+
|
|
230
|
+
See `CITATION.cff`, or use GitHub's "Cite this repository" button.
|
|
231
|
+
|
|
232
|
+
## License
|
|
233
|
+
|
|
234
|
+
MIT. See `LICENSE`.
|
payoff-0.1.0/README.md
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# payoff
|
|
2
|
+
|
|
3
|
+
Decide whether an AI system is worth using, and how much of its output
|
|
4
|
+
people should check.
|
|
5
|
+
|
|
6
|
+
[](https://github.com/ChristopherDaigle/payoff/actions/workflows/ci.yml)
|
|
7
|
+
|
|
8
|
+
Most AI work is funded on a model metric (accuracy, F1, AUC) and a business
|
|
9
|
+
case that assumes the model does all the work. Neither says whether the
|
|
10
|
+
*system* is worth having: the model, the cut-off someone chose, the people who
|
|
11
|
+
check some of its output, and the capacity they have. `payoff` prices every
|
|
12
|
+
outcome of that system, finds the best share of work to send to people, and
|
|
13
|
+
shows which uncertain inputs are worth measuring before you decide.
|
|
14
|
+
|
|
15
|
+
The name is the decision-theory term. Every way a decision can turn out has a
|
|
16
|
+
payoff, and the best design is the one with the highest expected payoff once
|
|
17
|
+
the model's errors, the reviewers' time, and the build are all counted.
|
|
18
|
+
|
|
19
|
+
It is the code companion to two articles:
|
|
20
|
+
|
|
21
|
+
- [Is It Possible, and Is It Worth It?](https://quantchris.com/posts/2026-11-29-is-it-possible-and-is-it-worth-it.html)
|
|
22
|
+
covers what to do with the costs and benefits.
|
|
23
|
+
- [Where the Numbers Come From](https://quantchris.com/posts/2026-11-29-where-the-numbers-come-from.html)
|
|
24
|
+
covers how to get them.
|
|
25
|
+
|
|
26
|
+
The same calculations are in a
|
|
27
|
+
[workbook](https://quantchris.com/assets/files/payoff-workbook.xlsx) for
|
|
28
|
+
readers who prefer a spreadsheet. The tests check that this package and the
|
|
29
|
+
workbook give the same numbers.
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
With [uv](https://docs.astral.sh/uv/):
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
uv add payoff
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
or with pip: `pip install payoff`.
|
|
40
|
+
Python 3.10 or later. No runtime dependencies.
|
|
41
|
+
|
|
42
|
+
## Quick start
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import payoff
|
|
46
|
+
|
|
47
|
+
# A refund team: 100,000 requests a year, dollars per request.
|
|
48
|
+
hourly = 50.0 # loaded cost per hour of a support rep
|
|
49
|
+
params = payoff.Params(
|
|
50
|
+
value=10.0, # a correct decision is worth what it costs to make today
|
|
51
|
+
error_cost=50.0, # a wrong decision that reaches a customer
|
|
52
|
+
hand_cost=payoff.cost_of_minutes(12, hourly),
|
|
53
|
+
confirm_cost=payoff.cost_of_minutes(3, hourly),
|
|
54
|
+
fix_cost=payoff.cost_of_minutes(6, hourly),
|
|
55
|
+
accuracy=0.80,
|
|
56
|
+
separation=1.5,
|
|
57
|
+
catch_rate=0.90,
|
|
58
|
+
overturn_rate=0.02,
|
|
59
|
+
capacity=0.40,
|
|
60
|
+
run_cost=0.50,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
best = payoff.best_within_capacity(params)
|
|
64
|
+
best.share_reviewed # 0.40: check 40% of requests
|
|
65
|
+
payoff.advantage(params) # 4.81: dollars saved per request versus today
|
|
66
|
+
payoff.payback_months(200_000, payoff.advantage(params) * 100_000) # 5.0
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`examples/quickstart.py` adds sensitivity, simulation, and the value of
|
|
70
|
+
measuring each input:
|
|
71
|
+
|
|
72
|
+
```text
|
|
73
|
+
$ uv run python examples/quickstart.py
|
|
74
|
+
Check 40% of items.
|
|
75
|
+
Advantage over doing it by hand: $4.81 per item,
|
|
76
|
+
$480,911 per year.
|
|
77
|
+
Pays back the build 5.0 months after launch, 9.0 after funding.
|
|
78
|
+
One more point of capacity is worth $4,375 per year.
|
|
79
|
+
|
|
80
|
+
What to measure first (advantage per year, low to high):
|
|
81
|
+
error_cost $646,782 to -$348,443 <- can change the answer
|
|
82
|
+
hand_cost $230,911 to $730,911
|
|
83
|
+
...
|
|
84
|
+
Beats the current process in 66% of 2,000 draws.
|
|
85
|
+
Knowing error_cost exactly is worth about $71,054 per year.
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## What it answers
|
|
89
|
+
|
|
90
|
+
| Question | Function |
|
|
91
|
+
|---|---|
|
|
92
|
+
| What is each design worth per item? | `expected_value_by_hand`, `expected_value_full_automation`, `expected_value_review_all`, `evaluate` |
|
|
93
|
+
| What accuracy does each design need? | `break_even_accuracy_full_automation`, `break_even_accuracy_review_all` |
|
|
94
|
+
| What share should people check, given their capacity? | `best_within_capacity`, `advantage` |
|
|
95
|
+
| What is more review capacity worth? | `capacity_value` |
|
|
96
|
+
| When does the build pay back, and what is it worth over its life? | `payback_months`, `net_value` |
|
|
97
|
+
| Which inputs could change the answer? | `Range`, `sensitivity` |
|
|
98
|
+
| How likely is the system to beat the current process? | `simulate` |
|
|
99
|
+
| Which measurement is worth paying for? | `value_of_information` |
|
|
100
|
+
| What are reviewers' catch and overturn rates? | `beta_posterior_mean`, `wilson_interval`, `seeded_errors_needed` |
|
|
101
|
+
| What error rate do the edits imply? | `implied_error_rate` |
|
|
102
|
+
| The numbers say no: proceed, wait, or stop? | `decide` |
|
|
103
|
+
|
|
104
|
+
Every public function has a docstring with its arguments and return value.
|
|
105
|
+
|
|
106
|
+
## The model
|
|
107
|
+
|
|
108
|
+
Each item gets a confidence score. Items at or above a cut-off go straight
|
|
109
|
+
through; the rest go to a person, up to the review capacity. A person
|
|
110
|
+
confirms a correct draft, fixes a wrong one they catch, misses the rest, and
|
|
111
|
+
now and then changes a correct draft into a wrong one.
|
|
112
|
+
|
|
113
|
+
| Input | Meaning |
|
|
114
|
+
|---|---|
|
|
115
|
+
| `value` | Value of one correct result |
|
|
116
|
+
| `error_cost` | Cost of an error that gets through, on top of the value lost |
|
|
117
|
+
| `hand_cost` | Cost of doing one item from scratch |
|
|
118
|
+
| `confirm_cost`, `fix_cost` | Cost of confirming a correct draft, fixing a wrong one |
|
|
119
|
+
| `accuracy` | Share of outputs that are right |
|
|
120
|
+
| `separation` | How well the score tells right from wrong, in standard deviations |
|
|
121
|
+
| `catch_rate` | Share of wrong drafts people catch |
|
|
122
|
+
| `overturn_rate` | Share of correct drafts people change to wrong |
|
|
123
|
+
| `capacity` | Share of items people can check |
|
|
124
|
+
| `run_cost` | Cost of running the system, per item |
|
|
125
|
+
|
|
126
|
+
Money inputs can be in any one unit. The articles, the workbook, and these
|
|
127
|
+
examples use dollars, with a refund team as the running example. Setting
|
|
128
|
+
`value=1` instead measures everything relative to the value of a correct
|
|
129
|
+
result, which is handy for comparing very different systems.
|
|
130
|
+
|
|
131
|
+
Assumptions, stated so you can judge whether they fit:
|
|
132
|
+
|
|
133
|
+
- Scores are normal with unit variance: mean `separation` for correct
|
|
134
|
+
outputs, mean 0 for wrong ones. Calibrate against your own score
|
|
135
|
+
distributions before relying on the routing result.
|
|
136
|
+
- One error cost per item. Systems with several kinds of error should price
|
|
137
|
+
them separately and use a weighted average, or extend the model.
|
|
138
|
+
- Reviewers' catch and overturn rates do not depend on the cut-off. In
|
|
139
|
+
practice they move when the review queue changes; the articles explain how
|
|
140
|
+
to measure them per queue.
|
|
141
|
+
|
|
142
|
+
## How it matches the workbook
|
|
143
|
+
|
|
144
|
+
`best_within_capacity` searches a grid of cut-offs and then checks the
|
|
145
|
+
cut-off that fills capacity exactly, found by bisection. The workbook does the
|
|
146
|
+
same with formulas (201 cut-offs, 60 bisection steps).
|
|
147
|
+
`tests/test_workbook.py` reads the workbook's computed values and recomputes
|
|
148
|
+
each one from its inputs.
|
|
149
|
+
|
|
150
|
+
## Project layout
|
|
151
|
+
|
|
152
|
+
```text
|
|
153
|
+
src/payoff/
|
|
154
|
+
model.py outcomes, routing, break-even, capacity value, payback
|
|
155
|
+
measure.py ranges, sensitivity, simulation, reviewer statistics
|
|
156
|
+
discretion.py proceed, wait, or stop
|
|
157
|
+
tests/
|
|
158
|
+
test_model.py properties that hold for any inputs
|
|
159
|
+
test_measure.py measurement helpers
|
|
160
|
+
test_workbook.py parity with the published workbook
|
|
161
|
+
test_repo.py every text file is plain ASCII
|
|
162
|
+
data/payoff-workbook.xlsx
|
|
163
|
+
examples/quickstart.py
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Development
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
uv sync # creates .venv from uv.lock
|
|
170
|
+
uv run pytest # tests
|
|
171
|
+
uv run ruff check # lint (Google docstring convention)
|
|
172
|
+
uv run ruff format --check # formatting
|
|
173
|
+
uv run mypy # strict type checks
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
CI runs all four on Python 3.10 to 3.13. Releases go to PyPI from a version
|
|
177
|
+
tag; see [RELEASING.md](RELEASING.md).
|
|
178
|
+
|
|
179
|
+
## Design choices
|
|
180
|
+
|
|
181
|
+
- **No runtime dependencies.** The math needs only the standard library, so
|
|
182
|
+
there is nothing to audit or pin for users.
|
|
183
|
+
- **Frozen dataclasses with validation.** Bad inputs fail when they are
|
|
184
|
+
created, with a message naming the field.
|
|
185
|
+
- **Repeatable randomness.** `simulate` takes a seed and defaults to 0.
|
|
186
|
+
- **Plain text.** A test keeps every text file ASCII, so nothing renders
|
|
187
|
+
differently from one terminal or editor to the next.
|
|
188
|
+
|
|
189
|
+
## Roadmap
|
|
190
|
+
|
|
191
|
+
The articles climb a ladder, and the package will follow it:
|
|
192
|
+
|
|
193
|
+
1. A classic model: two kinds of error, thresholds from costs, ranking under
|
|
194
|
+
fixed capacity.
|
|
195
|
+
2. Extraction: many fields per document and many documents per case, where
|
|
196
|
+
correctness compounds.
|
|
197
|
+
3. AI agents: a sequence of steps that take actions, with approval at
|
|
198
|
+
irreversible ones.
|
|
199
|
+
4. Several AI agents: handoffs, and AI agents checking each other.
|
|
200
|
+
|
|
201
|
+
## Citing
|
|
202
|
+
|
|
203
|
+
See `CITATION.cff`, or use GitHub's "Cite this repository" button.
|
|
204
|
+
|
|
205
|
+
## License
|
|
206
|
+
|
|
207
|
+
MIT. See `LICENSE`.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Releasing
|
|
2
|
+
|
|
3
|
+
Releases go to [PyPI](https://pypi.org/project/payoff/) through the Release
|
|
4
|
+
workflow, using PyPI trusted publishing. No password or API token is stored
|
|
5
|
+
in the repository or on a laptop.
|
|
6
|
+
|
|
7
|
+
## One-time setup
|
|
8
|
+
|
|
9
|
+
1. On PyPI, sign in, turn on two-factor authentication, and open
|
|
10
|
+
**Your account > Publishing**. Add a pending publisher:
|
|
11
|
+
- PyPI project name: `payoff`
|
|
12
|
+
- Owner: `ChristopherDaigle`
|
|
13
|
+
- Repository name: `payoff`
|
|
14
|
+
- Workflow name: `release.yml`
|
|
15
|
+
- Environment name: `pypi`
|
|
16
|
+
2. On GitHub, open the repository's **Settings > Environments**, create an
|
|
17
|
+
environment named `pypi`, and add yourself as a required reviewer so every
|
|
18
|
+
release waits for your approval.
|
|
19
|
+
|
|
20
|
+
A pending publisher does not reserve the name. The name is claimed when the
|
|
21
|
+
first release uploads, so do step 1 and the first release in one sitting.
|
|
22
|
+
|
|
23
|
+
## Each release
|
|
24
|
+
|
|
25
|
+
1. Update `version` in `pyproject.toml`, `version` and `date-released` in
|
|
26
|
+
`CITATION.cff`, and `CHANGELOG.md`. Run `uv lock`.
|
|
27
|
+
2. Check: `uv run ruff check && uv run ruff format --check && uv run mypy &&
|
|
28
|
+
uv run pytest`.
|
|
29
|
+
3. Commit, then tag and push:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
git tag v0.1.0
|
|
33
|
+
git push origin main v0.1.0
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
4. Approve the run in the Actions tab. The workflow checks that the tag
|
|
37
|
+
matches the version, runs the tests, builds, and uploads.
|
payoff-0.1.0/SECURITY.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Security
|
|
2
|
+
|
|
3
|
+
## Supported versions
|
|
4
|
+
|
|
5
|
+
Only the latest release receives fixes.
|
|
6
|
+
|
|
7
|
+
## Reporting a vulnerability
|
|
8
|
+
|
|
9
|
+
Please report security issues privately through GitHub's private
|
|
10
|
+
vulnerability reporting on this repository (Security tab, "Report a
|
|
11
|
+
vulnerability"). Do not open a public issue. Expect an acknowledgement within
|
|
12
|
+
a week.
|
|
13
|
+
|
|
14
|
+
## Scope and design
|
|
15
|
+
|
|
16
|
+
- The package has no runtime dependencies and makes no network calls, file
|
|
17
|
+
writes, or subprocess calls. It does arithmetic on the numbers it is given.
|
|
18
|
+
- Inputs are validated when a `Params` or `Range` is created: non-numbers,
|
|
19
|
+
non-finite values, negatives, and rates outside 0 to 1 are rejected.
|
|
20
|
+
- Randomness (`simulate`) uses Python's `random` module with a fixed seed for
|
|
21
|
+
repeatable results. It is not used for anything security-related.
|
|
22
|
+
- Development dependencies are pinned in `uv.lock`. CI runs on GitHub-hosted
|
|
23
|
+
runners with actions pinned to full commit SHAs and read-only permissions.
|
|
24
|
+
- The workbook in `tests/data` contains formulas only, no macros.
|