Skip to content

docs(contract): enforce the corrected manuscript equations; retire the erratum - #42

Merged
nceglia merged 1 commit into
mainfrom
model/contract
Aug 3, 2026
Merged

docs(contract): enforce the corrected manuscript equations; retire the erratum#42
nceglia merged 1 commit into
mainfrom
model/contract

Conversation

@nceglia

@nceglia nceglia commented Aug 3, 2026

Copy link
Copy Markdown
Owner

The manuscript's Entropy section has been corrected — eqs 3–4 now weight by the conditional (matching the log), and eq 4's left-hand side reads H(p(φ|c)) instead of the impossible H(p(c)). Both now agree with the implementation exactly.

Verified before changing anything, on a small asymmetric 3×2 joint:

eq manuscript code
3 1.251629 / 1.061278 _clonotypic_one
4 0.721928 / 1.0 / 0.591673 _phenotypic_one
5 0.288703 _mi_from_joint

Added tests that transcribe eqs 2–6 literally from the manuscript and assert the code computes exactly that. These become the primary definitional tests; the existing identity tests stay but they pin consequences of a formula (uniform → log₂k, degenerate → 0) rather than the formula itself.

SOURCE_ERRATA removed from the manifest, __all__, both note_eq references, the module docstring, METRICS_CONTRACT.md and CLAUDE.md. A short historical note remains in the prose so a reader holding the old revision isn't confused.

test_note_literal_formula_would_break_the_decomposition is reframed rather than deleted, as test_marginal_weighting_is_not_an_entropy — marginal-weighting is the natural way to mis-transcribe these equations and it fails two ways at once: the value can exceed log₂|C| (impossible for an entropy over |C| outcomes), and it makes the MI decomposition return a negative mutual information. Worth guarding independent of any manuscript revision.

One live deviation, now explicit

Eq 6 defines NMI = I / (½(H(c)+H(φ))) — the mean denominator — while tcri defaults to "min". On the contract's test joint that's 0.239 (eq 6) vs 0.293 (default), ~23% apart. min is deliberate: the mean denominator scales with log₂(C) and so isn't comparable across groups with different clone counts.

Recorded as SANCTIONED_EXTENSIONS['normalize_mode_default'] and pinned by test_eq6_nmi_is_the_average_denominator, which asserts both that "average" reproduces eq 6 and that the default does not — so the divergence can never go silent. Anything reproducing the note's benchmark must pass normalize_mode="average".

Metrics contract 12 → 17 tests. Full suite 169 passed, 3 skipped.

…e erratum

The manuscript's Entropy section has been corrected: eqs 3-4 now weight by the
CONDITIONAL (matching the log) and eq 4's left-hand side reads H(p(phi|c)) instead
of the impossible H(p(c)). Both now agree with the implementation exactly.

Verified before changing anything (small asymmetric 3x2 joint):
  eq 3  1.251629 / 1.061278          == _clonotypic_one   MATCH
  eq 4  0.721928 / 1.0 / 0.591673    == _phenotypic_one   MATCH
  eq 5  0.288703                     == _mi_from_joint    MATCH

Added tests that transcribe eqs 2-6 LITERALLY from the manuscript and assert the
code computes exactly that. These are now the primary definitional tests; the
pre-existing identity tests (uniform -> log2 k, degenerate -> 0, zero-mass -> NaN,
support-only, the MI decomposition) stay, but they pin CONSEQUENCES of a formula
rather than the formula itself.

SOURCE_ERRATA removed from the manifest, __all__, the two note_eq references, the
module docstring, METRICS_CONTRACT.md and CLAUDE.md. A short historical note stays
in the prose so a reader who finds the old revision is not confused.

test_note_literal_formula_would_break_the_decomposition is REFRAMED rather than
deleted, as test_marginal_weighting_is_not_an_entropy: marginal-weighting is the
natural way to mis-transcribe these equations and it fails two ways at once -- the
value can exceed log2(|C|) (impossible for an entropy over |C| outcomes) and it
makes the MI decomposition return a NEGATIVE mutual information. Worth keeping as a
standing guard independent of any manuscript revision.

ONE LIVE DEVIATION, now explicit. Eq 6 defines NMI = I / ((1/2)(H(c)+H(phi))) -- the
MEAN denominator -- while tcri defaults to 'min'. On the contract's test joint that
is 0.239 (eq 6) vs 0.293 (default), ~23% apart. 'min' is deliberate: the mean
denominator scales with log2(C) and so is not comparable across groups with
different clone counts. Recorded as
SANCTIONED_EXTENSIONS['normalize_mode_default'] and pinned by
test_eq6_nmi_is_the_average_denominator, which asserts BOTH that 'average'
reproduces eq 6 AND that the default does not -- so the divergence cannot go silent.
Anything reproducing the note's benchmark must pass normalize_mode='average'.

Metrics contract 12 -> 17 tests. Full suite 169 passed, 3 skipped.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@cursor

cursor Bot commented Aug 3, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@nceglia
nceglia merged commit aef4e52 into main Aug 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant