certlim 0.1.1__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.
@@ -0,0 +1,72 @@
1
+ # Changelog
2
+
3
+ ## 0.1.1
4
+
5
+ An adversarial audit of 0.1.0 found nine defects. The numerical core survived it
6
+ — 3,000 randomised instances with no violation of the certification bound, an
7
+ independent non-linear search agreeing with the hull program on every case, and
8
+ side errors respected to 1e-15 — but the interface around it did not. All nine
9
+ are fixed and each is now a test that fails if it returns.
10
+
11
+ ### Fixed, in order of how badly they could mislead
12
+
13
+ - **A search that ran out of budget was reported as a permanent obstruction.**
14
+ `n_star()` swallowed the state-space error and returned `None`, whose meaning
15
+ is "abandon this channel". `diagnose()` now returns a distinct `'undetermined'`
16
+ region that says in words that this is not a permanent obstruction, and
17
+ `n_star()` raises rather than guessing.
18
+ - **The default state ceiling was an order of magnitude above what is solvable.**
19
+ Lowered from 250,000 to 20,000, chosen from measured solve time rather than
20
+ memory: the exact program takes minutes at 20,000 states and its runtime is not
21
+ predictable from the size. The message now says so.
22
+ - **A chance tie between two units read as a structural obstruction.** Two units
23
+ with identical histograms are an exact collision by definition, and on a small
24
+ alphabet with few draws that happens by accident. `Diagnosis` now reports which
25
+ models collide and whether their raw counts were identical, and says plainly
26
+ that this may be a finite-sample coincidence.
27
+ - `Experiment` is immutable and its law arrays are read-only, so the memoised
28
+ results can no longer go stale behind a caller's edit.
29
+ - `Experiment` equality and hashing no longer raise on the numpy comparison.
30
+ - An unsorted `n_grid` no longer makes `is_monotone()` report a false failure.
31
+ - One zero tolerance (`ZERO_TOL`) replaces two that disagreed.
32
+ - `units_for` no longer advertises `alpha` and `beta` parameters it ignored.
33
+ - NaN, infinity, `n < 1` and fractional counts are rejected instead of silently
34
+ producing a plausible-looking answer.
35
+
36
+ ### Faster
37
+
38
+ `delta()` is solved through the dual separation game, 10x to 450x quicker than
39
+ the primal hull program on large state spaces (40 s to 0.22 s at 20,000 states).
40
+ Because the dual loses accuracy as the space grows, and a value near zero is
41
+ exactly where the gate verdict turns, any result below 1e-5 is re-solved with
42
+ the exact program. `delta(n, exact=True)` forces it everywhere.
43
+
44
+ A vectorised rewrite of the constraint assembly was tried first and gave no
45
+ speedup at all; the cost is in the solve, not the setup.
46
+
47
+ ### Added
48
+
49
+ - `certlim.report` — a self-contained single-file HTML certification report
50
+ combining the diagnosis, the frontier with an inline chart, the calibration and
51
+ the decision table, plus the standing scope caveats. No external stylesheet,
52
+ script, font or image, and byte-deterministic unless a timestamp is supplied.
53
+ Reachable as `certification_report()` / `write_report()` and `certlim report`.
54
+ - `Experiment.fingerprint()`, a stable digest of the registered laws for audit
55
+ trails.
56
+ - `Experiment.collision_pairs()` and `delta(exact=...)`.
57
+ - The CLI ignores non-numeric metadata columns instead of failing on them, and
58
+ `--block-col` is available on every subcommand.
59
+
60
+ ## 0.1.0
61
+
62
+ First release.
63
+
64
+ - `Experiment`: registered safe/unsafe classes over one evidence alphabet, with
65
+ `delta`, `decisiveness`, `bound`, `margin`, `gate`, `n_star`, `diagnose`.
66
+ - `frontier`: the frontier over a grid, with `bound_holds`, `is_monotone` and
67
+ `units_for`.
68
+ - `build_rule`: the deployable randomised Certify / Alert / Reject rule.
69
+ - `NestedQuantizer`, `coarsen_counts`, `check_data_processing`.
70
+ - `permutation_test`, `bootstrap_delta`: whole-unit calibration.
71
+ - `transport_margin`, `class_drift`; `screen`, `Plan`.
72
+ - `certlim` CLI with `diagnose`, `frontier`, `calibrate`, `rule`.
certlim-0.1.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 The certlim authors
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.
@@ -0,0 +1,2 @@
1
+ include README.md LICENSE CHANGELOG.md
2
+ recursive-include tests *.py
certlim-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,301 @@
1
+ Metadata-Version: 2.4
2
+ Name: certlim
3
+ Version: 0.1.1
4
+ Summary: Finite-evidence certification limits: what any Certify/Reject rule can achieve from the evidence you have.
5
+ License-Expression: MIT
6
+ Keywords: certification,safety,partial identification,hypothesis testing,selective prediction,reliability,acceptance sampling,industrial informatics
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Intended Audience :: Science/Research
9
+ Classifier: Intended Audience :: Manufacturing
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
17
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: numpy>=1.24
23
+ Requires-Dist: scipy>=1.10
24
+ Provides-Extra: test
25
+ Requires-Dist: pytest>=7.0; extra == "test"
26
+ Dynamic: license-file
27
+
28
+ # certlim
29
+
30
+ **What any Certify / Reject rule can achieve from the evidence you actually have.**
31
+
32
+ `certlim` answers a question that accuracy metrics cannot: given two registered
33
+ classes of systems — those that are safe under a proposed change and those that
34
+ are unsafe — and the measurement you can afford to take, *how often can any
35
+ procedure return a reliable verdict while controlling both kinds of error?*
36
+
37
+ And when the answer is "not often enough", it tells you which of the two
38
+ remedies applies:
39
+
40
+ - **buy more of the same evidence** — the obstruction is temporary and closes at
41
+ a computable block length; or
42
+ - **change the measurement** — the obstruction is permanent, and no amount of
43
+ the same channel, nor any re-encoding of it, will ever help.
44
+
45
+ Distinguishing those two cases is the point. They look identical to a
46
+ single-sample detector and they cost very different amounts of money.
47
+
48
+ ```bash
49
+ pip install certlim
50
+ ```
51
+
52
+ ---
53
+
54
+ ## Sixty seconds
55
+
56
+ ```python
57
+ import certlim as cl
58
+
59
+ # Two safe populations and one unsafe one, over a two-symbol evidence alphabet.
60
+ exp = cl.Experiment(safe=[[0.25, 0.75], [0.75, 0.25]],
61
+ unsafe=[[0.50, 0.50]])
62
+
63
+ d = exp.diagnose()
64
+ print(d.region) # 'delayed'
65
+ print(d.n_star) # 2
66
+ print(d.explain())
67
+ ```
68
+
69
+ > Delayed separation: the one-unit hulls intersect but no exact pair collides,
70
+ > so repetition alone opens the gate at n = 2. Buying more of the same evidence
71
+ > is the correct move here.
72
+
73
+ Note what just happened. Every safe/unsafe **pair** in this example is well
74
+ separated — the minimum pairwise total variation is `0.25` — yet one unit of
75
+ evidence certifies nothing at all:
76
+
77
+ ```python
78
+ exp.pairwise_min_tv() # 0.25 "looks separable"
79
+ exp.delta(1) # 0.0 actually is not
80
+ exp.decisiveness(1) # 0.10 = alpha + beta, i.e. no better than a coin
81
+ exp.delta(2) # 0.125 two units break the tie
82
+ ```
83
+
84
+ A criterion built on pairwise distances would have declared success here. The
85
+ composite geometry is what governs, and it is what `certlim` computes.
86
+
87
+ ---
88
+
89
+ ## The frontier
90
+
91
+ ```python
92
+ f = cl.frontier(exp, n_grid=[1, 2, 3, 5, 10], alpha=0.05, beta=0.05)
93
+ print(f)
94
+ ```
95
+
96
+ ```
97
+ n states Delta D bound slack gate
98
+ 1 2 0.000000 0.100000 0.100000 0.000000 1
99
+ 2 3 0.125000 0.112500 0.225000 0.112500 0
100
+ 3 4 0.187500 0.116667 0.287500 0.170833 0
101
+ 5 6 0.273438 0.138889 0.373438 0.234549 0
102
+ 10 11 0.409561 0.196970 0.509561 0.312591 0
103
+ ```
104
+
105
+ `Delta` is the composite separation, `D` the best worst-case decisiveness any
106
+ valid rule attains, `bound` the ceiling `min(1, alpha + beta + Delta)`, and
107
+ `gate` flags block lengths where the two hulls still meet.
108
+
109
+ `f.units_for(0.9)` returns the smallest gridded block reaching 90 % decisiveness,
110
+ or `None` if the grid does not get there.
111
+
112
+ ---
113
+
114
+ ## The deployable rule
115
+
116
+ ```python
117
+ rule = cl.build_rule(exp, n=3, alpha=0.05, beta=0.05)
118
+ rule.decisiveness # what it actually attains
119
+ rule.alert_rate_floor() # the fraction of blocks that must come back Alert
120
+
121
+ decision = rule.decide([2, 1], rng=np.random.default_rng(7))
122
+ decision.outcome # 'certify' | 'alert' | 'reject'
123
+
124
+ rule.error_profile(exp) # realised worst-case side errors, self-check
125
+ ```
126
+
127
+ The optimal rule is genuinely randomised, so pass a seeded generator whenever the
128
+ verdict has to be reproducible — in a certification workflow it usually does.
129
+
130
+ When the hulls still intersect, the optimum is a rule that **ignores the data**
131
+ and answers at the allowed error rates. `certlim` says so plainly rather than
132
+ dressing it up. That is the signal to change the measurement.
133
+
134
+ ---
135
+
136
+ ## From raw measurements
137
+
138
+ Start from per-unit symbol counts, one row per physical unit:
139
+
140
+ ```python
141
+ exp = cl.Experiment.from_counts(safe_counts, unsafe_counts, smoothing=0.5)
142
+ ```
143
+
144
+ Building the evidence menu is where most mistakes happen, so the quantiser
145
+ enforces the one property that makes menus comparable:
146
+
147
+ ```python
148
+ q = cl.NestedQuantizer.from_quantiles(features, bins=2, drop_order=(2, 1))
149
+ q.chain() # [8, 4, 2] — strictly nested, by construction
150
+ counts = q.counts(features, level=0)
151
+ ```
152
+
153
+ Quantising each menu independently produces partitions that are **not** nested,
154
+ and the resulting comparison can show a coarse menu beating its own refinement.
155
+ That is a pipeline artefact. `cl.check_data_processing(fine, coarse)` will tell
156
+ you when you have hit it.
157
+
158
+ ---
159
+
160
+ ## Finite-sample calibration
161
+
162
+ A plug-in `Delta` from observed counts is an estimate:
163
+
164
+ ```python
165
+ cl.permutation_test(unit_counts, labels, blocks=chemistry, n_permutations=999)
166
+ cl.bootstrap_delta(unit_counts, labels, n_resamples=2000)
167
+ ```
168
+
169
+ Both resample **whole physical units**. Resampling rows, cycles or time points
170
+ instead will understate the interval and inflate significance by orders of
171
+ magnitude, because repeated measurements of one unit are not independent
172
+ evidence about the population of units.
173
+
174
+ Neither is a lower confidence bound on the population separation. A significant
175
+ permutation p-value rejects label exchangeability; it does not certify anything
176
+ with coverage. `certlim` keeps that distinction in the result objects.
177
+
178
+ ---
179
+
180
+ ## Deployment and procurement
181
+
182
+ ```python
183
+ report = cl.transport_margin(source_exp, deployment_exp)
184
+ report.certified # separation survives the registered shift?
185
+ ```
186
+
187
+ The margin is `Delta_source - drift_safe - drift_unsafe`, measured as class
188
+ geometry rather than point-prediction error. A non-positive margin means the
189
+ source evidence does not certify transport — not that the deployment domain
190
+ collides.
191
+
192
+ ```python
193
+ cl.screen([
194
+ cl.Plan("passive", n=1, decisiveness=0.63, cost={"seconds": 780, "c_rate": 0.0}),
195
+ cl.Plan("active", n=1, decisiveness=0.53, cost={"seconds": 940, "c_rate": 0.5}),
196
+ cl.Plan("nameplate", n=6, decisiveness=0.10, cost={"seconds": 0, "c_rate": 0.0}),
197
+ ], target=0.4)
198
+ ```
199
+
200
+ Costs stay a vector and are never collapsed into one currency. A plan is dropped
201
+ only when another is no worse on every recorded axis. Plans measured on
202
+ different ledgers raise rather than being ranked — an unmeasured cost is not a
203
+ free cost.
204
+
205
+ ---
206
+
207
+ ## The report
208
+
209
+ One command turns the whole analysis into a filing-ready page:
210
+
211
+ ```bash
212
+ certlim report units.csv -o certification.html --subject "Lot 2026-08"
213
+ ```
214
+
215
+ ```python
216
+ cl.write_report("certification.html", exp,
217
+ unit_counts=counts, labels=labels, blocks=site,
218
+ subject="Lot 2026-08",
219
+ notes=("Grades come from the bench protocol, not from this channel.",))
220
+ ```
221
+
222
+ The page carries the structural verdict and the action it implies, the frontier
223
+ as a table and an inline chart, the finite-sample calibration, the decision table
224
+ and the standing scope caveats. It is a single file with no external stylesheet,
225
+ script, font or image, so it survives being archived or opened offline, and it is
226
+ byte-deterministic unless you pass a `timestamp` — two runs of the same analysis
227
+ produce the same file, and a diff means something actually changed.
228
+
229
+ ## Command line
230
+
231
+ ```bash
232
+ certlim diagnose units.csv # permanent, delayed, or open?
233
+ certlim frontier units.csv --n 1 2 3 5 10 --target 0.9
234
+ certlim calibrate units.csv --block-col chemistry
235
+ certlim rule units.csv --n 3 --json rule.json
236
+ certlim report units.csv -o certification.html
237
+ ```
238
+
239
+ Input is either a CSV of per-unit counts with a `grade` column holding `safe` /
240
+ `unsafe`, or a JSON file of probability laws:
241
+
242
+ ```json
243
+ {"safe": [[0.25, 0.75], [0.75, 0.25]], "unsafe": [[0.5, 0.5]]}
244
+ ```
245
+
246
+ Add `--json out.json` to any subcommand for a machine-readable report.
247
+
248
+ ---
249
+
250
+ ## What certlim does not do
251
+
252
+ It computes population geometry exactly. It does **not** know whether:
253
+
254
+ - your two classes were registered before you looked at the data;
255
+ - your grades were identified by a reference experiment rather than by the
256
+ channel you are evaluating — grading units with the channel under test makes
257
+ every number here meaningless;
258
+ - your sampling unit is the physical unit it should be;
259
+ - your evidence is conditionally i.i.d. within a block;
260
+ - your registered models are cohorts rather than individual units. If each model
261
+ is one physical unit, two units can produce identical histograms by chance,
262
+ which is an exact collision by definition. `certlim` flags that case rather
263
+ than letting it read as a structural obstruction, but it cannot decide for you
264
+ how the classes should have been registered.
265
+
266
+ Those are design decisions and the package will not make them for you. Every
267
+ result is relative to the registered classes: enlarging them can only shrink the
268
+ separation, never grow it.
269
+
270
+ ---
271
+
272
+ ## Method notes
273
+
274
+ Block laws are enumerated over count vectors, the sufficient statistic for i.i.d.
275
+ draws from a finite alphabet, so the problem is `C(n+K-1, K-1)` rather than
276
+ `K**n`. The composite distance and the optimal decision rule are solved as two
277
+ **independent** linear programs, so their agreement with the certification bound
278
+ is a real check rather than a same-code identity. There is no sampling, no
279
+ fitting and no tuning parameter anywhere in the core.
280
+
281
+ `delta()` is solved through the dual separation game, which is 10x to 450x
282
+ faster than the primal hull program on large state spaces. The dual loses
283
+ accuracy as the space grows, and a value near zero is exactly where the gate
284
+ verdict turns, so anything below `1e-5` is re-solved with the exact program;
285
+ `delta(n, exact=True)` forces it everywhere.
286
+
287
+ Exact enumeration has a ceiling (`max_states`, default 20 000). It is a **time**
288
+ budget, not a memory one — measured cost is about 3 s at 6 000 states, 40-100 s
289
+ at 20 000, and hours beyond, with run-to-run variation of a factor of two at the
290
+ same size. Exceeding it raises with the offending `(K, n)` and what to do about
291
+ it, rather than silently approximating or starting a job that never finishes.
292
+
293
+ For a finite registered class with `r` distinct one-unit laws and no exact
294
+ collision, the gate must be open by `r - 1`; `Experiment.stopping_bound()`
295
+ returns it, and `n_star()` searches exhaustively up to it. The bound is tight for
296
+ small classes and loose for large ones, and it bounds the *structural* search
297
+ only — never the number of physical units needed for a confidence statement.
298
+
299
+ ## Licence
300
+
301
+ MIT.
@@ -0,0 +1,274 @@
1
+ # certlim
2
+
3
+ **What any Certify / Reject rule can achieve from the evidence you actually have.**
4
+
5
+ `certlim` answers a question that accuracy metrics cannot: given two registered
6
+ classes of systems — those that are safe under a proposed change and those that
7
+ are unsafe — and the measurement you can afford to take, *how often can any
8
+ procedure return a reliable verdict while controlling both kinds of error?*
9
+
10
+ And when the answer is "not often enough", it tells you which of the two
11
+ remedies applies:
12
+
13
+ - **buy more of the same evidence** — the obstruction is temporary and closes at
14
+ a computable block length; or
15
+ - **change the measurement** — the obstruction is permanent, and no amount of
16
+ the same channel, nor any re-encoding of it, will ever help.
17
+
18
+ Distinguishing those two cases is the point. They look identical to a
19
+ single-sample detector and they cost very different amounts of money.
20
+
21
+ ```bash
22
+ pip install certlim
23
+ ```
24
+
25
+ ---
26
+
27
+ ## Sixty seconds
28
+
29
+ ```python
30
+ import certlim as cl
31
+
32
+ # Two safe populations and one unsafe one, over a two-symbol evidence alphabet.
33
+ exp = cl.Experiment(safe=[[0.25, 0.75], [0.75, 0.25]],
34
+ unsafe=[[0.50, 0.50]])
35
+
36
+ d = exp.diagnose()
37
+ print(d.region) # 'delayed'
38
+ print(d.n_star) # 2
39
+ print(d.explain())
40
+ ```
41
+
42
+ > Delayed separation: the one-unit hulls intersect but no exact pair collides,
43
+ > so repetition alone opens the gate at n = 2. Buying more of the same evidence
44
+ > is the correct move here.
45
+
46
+ Note what just happened. Every safe/unsafe **pair** in this example is well
47
+ separated — the minimum pairwise total variation is `0.25` — yet one unit of
48
+ evidence certifies nothing at all:
49
+
50
+ ```python
51
+ exp.pairwise_min_tv() # 0.25 "looks separable"
52
+ exp.delta(1) # 0.0 actually is not
53
+ exp.decisiveness(1) # 0.10 = alpha + beta, i.e. no better than a coin
54
+ exp.delta(2) # 0.125 two units break the tie
55
+ ```
56
+
57
+ A criterion built on pairwise distances would have declared success here. The
58
+ composite geometry is what governs, and it is what `certlim` computes.
59
+
60
+ ---
61
+
62
+ ## The frontier
63
+
64
+ ```python
65
+ f = cl.frontier(exp, n_grid=[1, 2, 3, 5, 10], alpha=0.05, beta=0.05)
66
+ print(f)
67
+ ```
68
+
69
+ ```
70
+ n states Delta D bound slack gate
71
+ 1 2 0.000000 0.100000 0.100000 0.000000 1
72
+ 2 3 0.125000 0.112500 0.225000 0.112500 0
73
+ 3 4 0.187500 0.116667 0.287500 0.170833 0
74
+ 5 6 0.273438 0.138889 0.373438 0.234549 0
75
+ 10 11 0.409561 0.196970 0.509561 0.312591 0
76
+ ```
77
+
78
+ `Delta` is the composite separation, `D` the best worst-case decisiveness any
79
+ valid rule attains, `bound` the ceiling `min(1, alpha + beta + Delta)`, and
80
+ `gate` flags block lengths where the two hulls still meet.
81
+
82
+ `f.units_for(0.9)` returns the smallest gridded block reaching 90 % decisiveness,
83
+ or `None` if the grid does not get there.
84
+
85
+ ---
86
+
87
+ ## The deployable rule
88
+
89
+ ```python
90
+ rule = cl.build_rule(exp, n=3, alpha=0.05, beta=0.05)
91
+ rule.decisiveness # what it actually attains
92
+ rule.alert_rate_floor() # the fraction of blocks that must come back Alert
93
+
94
+ decision = rule.decide([2, 1], rng=np.random.default_rng(7))
95
+ decision.outcome # 'certify' | 'alert' | 'reject'
96
+
97
+ rule.error_profile(exp) # realised worst-case side errors, self-check
98
+ ```
99
+
100
+ The optimal rule is genuinely randomised, so pass a seeded generator whenever the
101
+ verdict has to be reproducible — in a certification workflow it usually does.
102
+
103
+ When the hulls still intersect, the optimum is a rule that **ignores the data**
104
+ and answers at the allowed error rates. `certlim` says so plainly rather than
105
+ dressing it up. That is the signal to change the measurement.
106
+
107
+ ---
108
+
109
+ ## From raw measurements
110
+
111
+ Start from per-unit symbol counts, one row per physical unit:
112
+
113
+ ```python
114
+ exp = cl.Experiment.from_counts(safe_counts, unsafe_counts, smoothing=0.5)
115
+ ```
116
+
117
+ Building the evidence menu is where most mistakes happen, so the quantiser
118
+ enforces the one property that makes menus comparable:
119
+
120
+ ```python
121
+ q = cl.NestedQuantizer.from_quantiles(features, bins=2, drop_order=(2, 1))
122
+ q.chain() # [8, 4, 2] — strictly nested, by construction
123
+ counts = q.counts(features, level=0)
124
+ ```
125
+
126
+ Quantising each menu independently produces partitions that are **not** nested,
127
+ and the resulting comparison can show a coarse menu beating its own refinement.
128
+ That is a pipeline artefact. `cl.check_data_processing(fine, coarse)` will tell
129
+ you when you have hit it.
130
+
131
+ ---
132
+
133
+ ## Finite-sample calibration
134
+
135
+ A plug-in `Delta` from observed counts is an estimate:
136
+
137
+ ```python
138
+ cl.permutation_test(unit_counts, labels, blocks=chemistry, n_permutations=999)
139
+ cl.bootstrap_delta(unit_counts, labels, n_resamples=2000)
140
+ ```
141
+
142
+ Both resample **whole physical units**. Resampling rows, cycles or time points
143
+ instead will understate the interval and inflate significance by orders of
144
+ magnitude, because repeated measurements of one unit are not independent
145
+ evidence about the population of units.
146
+
147
+ Neither is a lower confidence bound on the population separation. A significant
148
+ permutation p-value rejects label exchangeability; it does not certify anything
149
+ with coverage. `certlim` keeps that distinction in the result objects.
150
+
151
+ ---
152
+
153
+ ## Deployment and procurement
154
+
155
+ ```python
156
+ report = cl.transport_margin(source_exp, deployment_exp)
157
+ report.certified # separation survives the registered shift?
158
+ ```
159
+
160
+ The margin is `Delta_source - drift_safe - drift_unsafe`, measured as class
161
+ geometry rather than point-prediction error. A non-positive margin means the
162
+ source evidence does not certify transport — not that the deployment domain
163
+ collides.
164
+
165
+ ```python
166
+ cl.screen([
167
+ cl.Plan("passive", n=1, decisiveness=0.63, cost={"seconds": 780, "c_rate": 0.0}),
168
+ cl.Plan("active", n=1, decisiveness=0.53, cost={"seconds": 940, "c_rate": 0.5}),
169
+ cl.Plan("nameplate", n=6, decisiveness=0.10, cost={"seconds": 0, "c_rate": 0.0}),
170
+ ], target=0.4)
171
+ ```
172
+
173
+ Costs stay a vector and are never collapsed into one currency. A plan is dropped
174
+ only when another is no worse on every recorded axis. Plans measured on
175
+ different ledgers raise rather than being ranked — an unmeasured cost is not a
176
+ free cost.
177
+
178
+ ---
179
+
180
+ ## The report
181
+
182
+ One command turns the whole analysis into a filing-ready page:
183
+
184
+ ```bash
185
+ certlim report units.csv -o certification.html --subject "Lot 2026-08"
186
+ ```
187
+
188
+ ```python
189
+ cl.write_report("certification.html", exp,
190
+ unit_counts=counts, labels=labels, blocks=site,
191
+ subject="Lot 2026-08",
192
+ notes=("Grades come from the bench protocol, not from this channel.",))
193
+ ```
194
+
195
+ The page carries the structural verdict and the action it implies, the frontier
196
+ as a table and an inline chart, the finite-sample calibration, the decision table
197
+ and the standing scope caveats. It is a single file with no external stylesheet,
198
+ script, font or image, so it survives being archived or opened offline, and it is
199
+ byte-deterministic unless you pass a `timestamp` — two runs of the same analysis
200
+ produce the same file, and a diff means something actually changed.
201
+
202
+ ## Command line
203
+
204
+ ```bash
205
+ certlim diagnose units.csv # permanent, delayed, or open?
206
+ certlim frontier units.csv --n 1 2 3 5 10 --target 0.9
207
+ certlim calibrate units.csv --block-col chemistry
208
+ certlim rule units.csv --n 3 --json rule.json
209
+ certlim report units.csv -o certification.html
210
+ ```
211
+
212
+ Input is either a CSV of per-unit counts with a `grade` column holding `safe` /
213
+ `unsafe`, or a JSON file of probability laws:
214
+
215
+ ```json
216
+ {"safe": [[0.25, 0.75], [0.75, 0.25]], "unsafe": [[0.5, 0.5]]}
217
+ ```
218
+
219
+ Add `--json out.json` to any subcommand for a machine-readable report.
220
+
221
+ ---
222
+
223
+ ## What certlim does not do
224
+
225
+ It computes population geometry exactly. It does **not** know whether:
226
+
227
+ - your two classes were registered before you looked at the data;
228
+ - your grades were identified by a reference experiment rather than by the
229
+ channel you are evaluating — grading units with the channel under test makes
230
+ every number here meaningless;
231
+ - your sampling unit is the physical unit it should be;
232
+ - your evidence is conditionally i.i.d. within a block;
233
+ - your registered models are cohorts rather than individual units. If each model
234
+ is one physical unit, two units can produce identical histograms by chance,
235
+ which is an exact collision by definition. `certlim` flags that case rather
236
+ than letting it read as a structural obstruction, but it cannot decide for you
237
+ how the classes should have been registered.
238
+
239
+ Those are design decisions and the package will not make them for you. Every
240
+ result is relative to the registered classes: enlarging them can only shrink the
241
+ separation, never grow it.
242
+
243
+ ---
244
+
245
+ ## Method notes
246
+
247
+ Block laws are enumerated over count vectors, the sufficient statistic for i.i.d.
248
+ draws from a finite alphabet, so the problem is `C(n+K-1, K-1)` rather than
249
+ `K**n`. The composite distance and the optimal decision rule are solved as two
250
+ **independent** linear programs, so their agreement with the certification bound
251
+ is a real check rather than a same-code identity. There is no sampling, no
252
+ fitting and no tuning parameter anywhere in the core.
253
+
254
+ `delta()` is solved through the dual separation game, which is 10x to 450x
255
+ faster than the primal hull program on large state spaces. The dual loses
256
+ accuracy as the space grows, and a value near zero is exactly where the gate
257
+ verdict turns, so anything below `1e-5` is re-solved with the exact program;
258
+ `delta(n, exact=True)` forces it everywhere.
259
+
260
+ Exact enumeration has a ceiling (`max_states`, default 20 000). It is a **time**
261
+ budget, not a memory one — measured cost is about 3 s at 6 000 states, 40-100 s
262
+ at 20 000, and hours beyond, with run-to-run variation of a factor of two at the
263
+ same size. Exceeding it raises with the offending `(K, n)` and what to do about
264
+ it, rather than silently approximating or starting a job that never finishes.
265
+
266
+ For a finite registered class with `r` distinct one-unit laws and no exact
267
+ collision, the gate must be open by `r - 1`; `Experiment.stopping_bound()`
268
+ returns it, and `n_star()` searches exhaustively up to it. The bound is tight for
269
+ small classes and loose for large ones, and it bounds the *structural* search
270
+ only — never the number of physical units needed for a confidence statement.
271
+
272
+ ## Licence
273
+
274
+ MIT.