diff --git a/.github/workflows/periodic-h0-pilot.yml b/.github/workflows/periodic-h0-pilot.yml index 77fa07ab2..369774727 100644 --- a/.github/workflows/periodic-h0-pilot.yml +++ b/.github/workflows/periodic-h0-pilot.yml @@ -51,6 +51,8 @@ jobs: run: python -B -S experiments/periodic_h0/word_polynomial_certificate.py --verify experiments/periodic_h0/results/word_polynomial1 - name: Replay finite-cutoff count caps and exact expected clipping losses run: python -B -S experiments/periodic_h0/finite_count_loss_certificate.py --verify experiments/periodic_h0/results/finite_count_loss1 + - name: Replay fixed-sample confidence plans and exact finite-law controls + run: python -B -S experiments/periodic_h0/count_confidence_certificate.py --verify experiments/periodic_h0/results/count_confidence1 - name: Execute the complete fixed pilot run: | python -B experiments/periodic_h0/run_pilot.py --output "$RUNNER_TEMP/periodic-h0-replay" diff --git a/experiments/periodic_h0/CONFIRMATION_READINESS.md b/experiments/periodic_h0/CONFIRMATION_READINESS.md index 2ff0b6788..912cba8be 100644 --- a/experiments/periodic_h0/CONFIRMATION_READINESS.md +++ b/experiments/periodic_h0/CONFIRMATION_READINESS.md @@ -16,6 +16,7 @@ paired differences, finite-sample error, and the last refinement remain relevant | Exact fine-grid H0 endpoints | [Integer barcode and independent connectivity verification](EXACT_H0.md) | One C38 grid and its frozen finite polynomial only; exact endpoints and deterministic bin-count sandwich | | New sampler → exact polynomial barcode | [Explicit-word bridge](WORD_POLYNOMIAL.md) and [complete deterministic example](results/word_polynomial1/RESULTS.md) | Exact finite-polynomial bin counts at cutoff 1; no random input law or full-field diagram claim | | Finite-cutoff exceptional-count control | [Uniform 16 K² bar-count bound and exact clipping-loss budgets](FINITE_COUNT_LOSS.md) | Supplied for F64,K under the declared IID uniform-input model; no bin means, infinite-field moment or sampling confidence claim | +| Prospective sampling error | [Fixed-sample simultaneous confidence](COUNT_CONFIDENCE.md) and [exact planning costs](results/count_confidence1/RESULTS.md) | Conditional finite-cutoff theorem supplied; actual IID input law, fixed plan and all certified rows still required; no observed confidence interval | | Ideal infinite-field truncation | [Exact Gaussian shell/theta bound](GAUSSIAN_TAIL.md), including all modes beyond64 and the normalization correction | Uniform probabilistic tail supplied for the explicitly defined ideal field | | Coupling the stored coefficients to the ideal field | Explicit low-mode sup-norm/coefficient contract in the same proof | rho remains unknown; no full-field probability or count bound for the frozen polynomial | | Lifetime range | Larger bins exhibit numerical stability; shortest bins still drift | No certified finite-lifetime range for the leading law | @@ -72,6 +73,9 @@ the old seed-labelled coefficients do not acquire this coupling. A numerical remainder budget and infinite-field exceptional-count moments remain separate inputs. The [finite-cutoff count bound](results/finite_count_loss1/RESULTS.md) now supplies the missing count factor for clipping alone; contracted/expanded observable -means and their sampling-error bounds still need evaluation. +means still need evaluation. The [fixed-sample confidence theorem](COUNT_CONFIDENCE.md) +now supplies a conditional sampling-error procedure; its [planning examples](results/count_confidence1/RESULTS.md) +show the substantial cost of the worst-case count cap. No sample has been consumed +and the historical eight-field study has no new confidence claim. The finite-polynomial derivative input is now available. The source-bound manuscript and literature work can advance in parallel without waiting for that budget. diff --git a/experiments/periodic_h0/COUNT_CONFIDENCE.md b/experiments/periodic_h0/COUNT_CONFIDENCE.md new file mode 100644 index 000000000..421e790bf --- /dev/null +++ b/experiments/periodic_h0/COUNT_CONFIDENCE.md @@ -0,0 +1,281 @@ +# Fixed-sample confidence for finite-cutoff expected counts + +[Finite-cutoff expectation transfer](FINITE_COUNT_LOSS.md) · +[Explicit-word polynomial bridge](WORD_POLYNOMIAL.md) · +[Sampler and its input-law premise](GAUSSIAN_COUPLING.md) · +[Exact confidence arithmetic](count_confidence.py) + +The finite-polynomial bar cap also bounds sampling error. This note gives +simultaneous confidence intervals for unconditional expected bin counts of +the same-cutoff ideal Gaussian polynomial, provided a fixed number of word +blocks have the declared IID law and every retained row has valid count +bounds. Grid errors may vary between rows. Grid refinement and the choice +to leave a computation unresolved may depend on the sample: concentration +is applied to fixed latent polynomial counts, not to the computed grid +observables. + +This is a prospective mathematical statement. The arithmetic implementation +does not authenticate a word source, a sampling plan or a grid certificate. +No observed IID or Gaussian sample, evaluated ensemble mean, infinite-field +expected count or lifetime-law confirmation is supplied by this note. + +## 1. Fixed observables and the sampling assumptions + +Fix an integer 1<=K<=64 and write C_K=16 K^2. Use the polynomial P_J, +normalization S_alpha,64 and word order of the unchanged sampler. Let rho +and p be its same-cutoff coefficient-error and clipping-probability upper +bounds. In particular they are uniform bounds from that construction, not +estimates fitted to a sample. The target is G=F64,K, not the infinite field. + +Before inspecting the sample, fix a positive integer n, a finite family of +m>=1 bins [a_j,b_j) with 00. Overlapping bins +are allowed. The exact implementation uses rational endpoints, budgets and +radius. Assume J_1,...,J_n are independent blocks, each consisting of +(2K+1)^2 independent uniform 128-bit words. This law includes independence +both within a block and between blocks. It remains an explicit hypothesis; +neither a seed nor a list of integer words proves it. Repeated word values +are possible under this law and are not a reason to discard a draw. + +Define the following fixed functions on the entire word space: + +```text +X_j^-(J) = N_PJ([a_j+2 rho, b_j-2 rho)), +X_j^+(J) = N_PJ([a_j-2 rho, b_j+2 rho)) if a_j > 2 rho, + C_K otherwise. +mu_j^- = E X_j^-(J), mu_j^+ = E X_j^+(J), +nu_j = E N_G([a_j,b_j)). +``` + +An empty or reversed contracted interval has count zero. Only strictly +positive finite ordinary H0 lifetimes are counted; the essential class +remains separate. The measurability and deterministic cap proved in +[FINITE_COUNT_LOSS.md](FINITE_COUNT_LOSS.md) give + +```text +0 <= X_j^-(J) <= X_j^+(J) <= C_K. +max(0, mu_j^- - C_K p) <= nu_j <= min(C_K, mu_j^+ + C_K p). +``` + +Every expectation here is over its entire declared law. There is no +conditioning on clipping success, on a chosen word list or on successful +grid computation. The latent variables X_j^-(J_i) and X_j^+(J_i) are IID +across i for each fixed j. Different bins and the two signs can be dependent. + +## 2. What a retained row must establish + +For each i and j, require actual bounds + +```text +0 <= L_ij <= X_j^-(J_i) <= X_j^+(J_i) <= U_ij <= C_K. +``` + +A separately certified grid diagram Q_i with +d_B(D(P_Ji),Q_i)<=e_i supplies such bounds. Set d_i=2(e_i+rho) and use + +```text +L_ij = N_Qi([a_j+d_i,b_j-d_i)), +U_ij = min(C_K, N_Qi([a_j-d_i,b_j+d_i))) if a_j > d_i, + C_K otherwise. +``` + +The contracted grid count is zero for an empty interval. To see the lower +inequality for every word, apply the grid-to-polynomial matching argument +to the fixed polynomial interval [a_j+2 rho,b_j-2 rho). Its grid contraction +is exactly the interval defining L_ij. If that polynomial interval is empty, +so is the grid contraction. For the upper inequality, when a_j>d_i the +polynomial interval [a_j-2 rho,b_j+2 rho) starts strictly above 2 e_i, so its +expanded grid count bounds X_j^+. Both that count and C_K bound X_j^+; +their minimum therefore does too. In the remaining cases the cap suffices. +The strict test is necessary, including at equality, because a bar at the +diagonal threshold can disappear in a matching. + +These statements are deterministic and do not require the Gaussian clipping +event. They reuse the existing bin-transfer theorem and +`finite_count_loss.grid_observables`; no probability is assigned to a fixed +word fixture by this reasoning. + +If a grid calculation fails or has no valid certificate, retain the draw +with L_ij=0 and U_ij=C_K. All n draws remain in every average. The grid size, +refinement, error bound and choice to leave a computation unresolved can +depend on all the observed words or calculations, provided each final row +still satisfies the pointwise inequalities. Such choices only replace the +unknown latent sample averages by conservative bounds. They do not require +the reported grid rows to be IID. + +The fixed n, bin family and radius remain part of the sampling premise. +Choosing them after seeing the sample, stopping when an interval looks +favorable, or discarding unresolved draws is not justified by this theorem. +An unresolved row is a retained draw with missing computational evidence; +it is not evidence that an unrecorded or never-generated draw occurred. + +## 3. Simultaneous confidence theorem + +Let Lbar_j and Ubar_j be the sums of all n respective row bounds divided +by n, and put + +```text +R = min(1, 2 m exp(-2 n (r/C_K)^2)). +``` + +Under the assumptions above, with probability at least 1-R, simultaneously +for every j, + +```text +mu_j^- >= max(0, Lbar_j-r), +mu_j^+ <= min(C_K, Ubar_j+r), + +max(0, Lbar_j-r-C_K p) <= nu_j + <= min(C_K, Ubar_j+r+C_K p). +``` + +Thus the random intervals cover fixed unconditional means. They are not +probability intervals for the count of the next realized field. No +independence between bins, between the two observables, or between clipping +and counts is assumed. + +**Bounded-variable concentration.** For a variable X taking values in +[0,C_K], define h(t)=log E exp(t(X-E X)). Its distribution here has finite +support, so differentiation is legitimate for every real t. Under the +exponentially tilted probability law, its second derivative is + +```text +h''(t) = Var_t(X) + = E_t[(X-C_K/2)^2] - (E_t[X]-C_K/2)^2 + <= C_K^2/4. +``` + +Since h(0)=h'(0)=0, the integral form of Taylor's formula gives +h(t)=t^2 integral_0^1 (1-u)h''(ut)du <= t^2 C_K^2/8. For n independent +copies, multiplication of moment-generating functions and exponential +Markov therefore give, for t>0, + +```text +Pr(Xbar-E X > r) <= exp(-t n r + n t^2 C_K^2/8). +``` + +Taking t=4r/C_K^2 proves an upper bound exp(-2n r^2/C_K^2). +Using h(-t) gives the same bound for Pr(E X-Xbar>r). + +Apply the upper tail to X_j^- and the lower tail to X_j^+. A union bound +over 2m events gives R. Outside their union, + +```text +mu_j^- >= Xbar_j^- - r >= Lbar_j-r, +mu_j^+ <= Xbar_j^+ + r <= Ubar_j+r. +``` + +This step explains why adaptively refined or unresolved grid rows are +permitted: only the fixed latent polynomial variables enter concentration. +Insert these inequalities into the unchanged finite-cutoff expectation +transfer to obtain the claimed intervals for nu_j. The clipping correction +is C_K p, not n C_K p. It bounds an expectation difference; this argument +does not demand clipping success for every sampled coupling. + +This theorem bounds mu_j^- and mu_j^+. It does not assert that an adaptively +produced grid average estimates a fixed mean E L_grid or E U_grid. Such a +claim instead needs a fixed total per-word evaluation rule defining those +random variables. + +## 4. Exact arithmetic and its evidence boundary + +`count_confidence.risk_upper(K,n,m,r)` evaluates a rational upper bound for +R using `gaussian_tail.exp_neg_bounds`. If x=2n(r/C_K)^2 exceeds the inherited +evaluator's domain, the function evaluates at min(x,4096). This is safe +because exp(-x)<=exp(-min(x,4096)); it can be conservative. The returned +upper exponential endpoint is multiplied by 2m and the result capped at +one. No floating logarithm, square root or exponential is needed. A desired +failure level is established only when the resulting exact rational upper +bound is no greater than that level. + +`count_confidence.mean_interval(K,p,rows,r,n)` uses exactly n rows for one +bin. Each integer pair must satisfy 0<=L<=U<=C_K. A `None` row contributes +[0,C_K]. The function computes rational averages, adds the sampling radius +and passes the resulting mean bounds to the existing expectation-transfer +arithmetic. For a simultaneous claim, use the complete fixed bin family +and its actual cardinality m with the same n and r. Although the generic +cap arithmetic accepts positive integer cutoffs, the sampler-based theorem +in this note is restricted to 1<=K<=64 with its corresponding budgets. + +Type checks, row counts, order, sums, exponential enclosures and interval +arithmetic are executable checks. They do not establish that a supplied +pair brackets the latent polynomial counts. That requires the actual +word-to-polynomial and grid evidence, or another valid argument. Likewise, +the code does not establish independence, uniformity, prospective choice +of the sampling plan, or that p belongs to the stated sampler and cutoff. +Those are external premises, not properties inferred from plausible +numbers or a successful arithmetic replay. + +An illustrative row list must therefore remain labeled as deterministic +arithmetic input. It supplies no observed ensemble mean and is not a +collection of authenticated grid certificates. Historical PCG64 fields and +the earlier selected word fixture acquire no new law or confidence claim. + +## 5. Planning scale and exact negative controls + +For eight bins, n=40000 and r=C_K/100 give exponent exactly 8. The exact +exponential evaluator bounds the family failure probability from above by +a rational value whose upward decimal rendering is + +```text +0.005367402046440190. +``` + +This is below 0.01 under the theorem's premises. The corresponding absolute +count radii and the sample sizes for radius one at that same bound are: + +| Cutoff K | Cap C_K | Radius C_K/100 at n=40000 | n=4 C_K^2 for radius one | +|---|---:|---:|---:| +| 1 | 16 | 4/25 = 0.16 | 1,024 | +| 24 | 9,216 | 2304/25 = 92.16 | 339,738,624 | +| 32 | 16,384 | 4096/25 = 163.84 | 1,073,741,824 | + +These are prospective arithmetic examples, not consumed sample sizes or a +held-out lifetime-law design. The conservative worst-case cap makes useful +absolute precision expensive at larger cutoffs. The interval width also +includes the gap between the lower and upper grid averages and the clipping +correction; the sampling radius alone is not the total uncertainty. + +The following finite-law examples check the statistical arithmetic without +claiming to be polynomial or Gaussian data: + +- Let X be 0 or 16 with equal probability, use n=8 and r=4, and supply + exact rows [X,X]. Exhaustive rational summation gives + Pr(|Xbar-8|>4)=9/128. The correct bound is 2 exp(-1); omitting C_K^2 + would give 2 exp(-256), smaller than the actual failure probability. +- With the same law and plan, certify zero outcomes as [0,0] and retain + positive outcomes as unresolved [0,16]. The exact probability that the + upper confidence endpoint misses the mean 8 is 9/256. Dropping all the + unresolved outcomes and treating the remaining zero rows as the sample + instead misses on 255/256 of all sequences; the last sequence has no + retained row. This detects conditioning on success and a wrong denominator. +- Replace selected exact rows by [0,16], making the selection depend on + the whole sequence. Every resulting interval contains its exact-row + interval. Enumeration checks the permitted adaptive widening directly. +- For four bins and n=1, choose uniformly which one bin has count 16; + the other three have count zero. Each bin mean is 4, and the total count + is always 16. With r=10, the selected bin has lower endpoint 6, so + simultaneous failure has probability one. Omitting the family factor + would give 2 exp(-25/32), whose upward decimal bound is + 0.915666723543228522, less than one. The correct family bound is capped + at one. + +These examples supplement strict-endpoint, empty-contraction and unresolved +grid controls in the existing finite-count tests. A replay must also reject +altered n, family size, means, risk or scope even when output hashes are +rebound. Tests establish these arithmetic properties; they do not certify +the IID input premise or prove a supplied grid matching. + +## 6. Remaining obligations + +The new result supplies a sampling-error theorem for the finite-cutoff +expectation transfer. It evaluates no random sample mean. Actual inference +still requires the specified input law, the fixed sampling plan, all +retained draws and valid row evidence. A small-support arithmetic toy is +not the full uniform-word ensemble. + +The ideal infinite field has no fixed-cutoff cap C_K. Its exceptional-event +count moment, the expected-count spectral-tail step and a numerical +lifetime-law remainder remain separate. This result provides no held-out +confirmation, physical source authentication, formal proof certificate or +independent-human review. Authorship, substantive nonauthor review, formal +evidence and scientific acceptance retain their distinct meanings. diff --git a/experiments/periodic_h0/README.md b/experiments/periodic_h0/README.md index 1dfdce293..f8080bd78 100644 --- a/experiments/periodic_h0/README.md +++ b/experiments/periodic_h0/README.md @@ -51,6 +51,12 @@ infinite-field count-moment and sampling-error inputs remain open. This small experiment samples a truncated version of the periodized Gaussian field on a side-24 square torus and measures finite ordinary superlevel H₀ bars using GUDHI. It accompanies the [manuscript draft](../../docs/research-translation/20260930/MANUSCRIPT.md), [statement crosswalk](../../docs/research-translation/20260930/CROSSWALK.md) and [original protocol](../../docs/research-translation/20260930/EXPERIMENT.md). It is numerical evidence about the declared discretized ensemble, not a continuum certificate or a new mathematical acceptance. +The [fixed-sample confidence result](results/count_confidence1/RESULTS.md) now +quantifies prospective sampling error for that finite-cutoff comparison. Its +[proof](COUNT_CONFIDENCE.md) permits adaptive grid refinement while retaining +failed computations in every average. The exact planning table shows the cost +of the conservative cap; it supplies no observed ensemble confidence interval. + ## Reproduce the pilot From the repository root, with Python 3.12 and a CPU: diff --git a/experiments/periodic_h0/count_confidence.py b/experiments/periodic_h0/count_confidence.py new file mode 100644 index 000000000..d16e8cc61 --- /dev/null +++ b/experiments/periodic_h0/count_confidence.py @@ -0,0 +1,60 @@ +"""Exact arithmetic for conditional, fixed-sample mean confidence bounds. + +COUNT_CONFIDENCE.md proves the statistical statement. These functions do not +authenticate an IID source, a grid certificate, or a prospective sampling plan. +""" +from fractions import Fraction as Q +import finite_certificate as fc +import finite_count_loss as cl +from gaussian_tail import exp_neg_bounds + + +def _positive_integer(value): + fc.require(type(value) is int and value>0,'Positive integer required') + return value + + +def _radius(value): + fc.require(type(value) is Q and value>0,'Positive exact rational radius required') + return value + + +def risk_upper(cutoff, sample_count, bins, radius): + """Upper bound min(1,2*m*exp(-2*n*(r/C)^2)), C=16*K^2. + + n, bins and radius must be chosen before seeing the sample. Dependence + between bins is allowed; the n latent word blocks must be IID. Large + exponents are conservatively capped for the inherited interval evaluator. + """ + cap=cl.bar_cap(cutoff) + n=_positive_integer(sample_count);m=_positive_integer(bins);r=_radius(radius) + exponent=2*n*(r/cap)**2 + return min(Q(1),2*m*exp_neg_bounds(min(exponent,Q(4096)))[1]) + + +def mean_interval(cutoff, failure, rows, radius, sample_count): + """Conditional target-mean interval from one predeclared bin's rows. + + Each pair must actually enclose the corresponding fixed latent polynomial + observables as in the proof. Only the numeric domain is checked here. + None denotes an unresolved grid and contributes [0,C] to the original n. + The returned interval has the risk bound from risk_upper only under its + statistical premises. Neither an arithmetic row nor this output is data + authentication or a test of the IID assumption. + """ + cap=cl.bar_cap(cutoff);n=_positive_integer(sample_count);r=_radius(radius) + fc.require(type(failure) is Q and 0<=failure<=1,'Exact probability bound in [0,1] required') + fc.require(type(rows) is list and len(rows)==n,'Every planned draw must have a row') + low=high=0 + for row in rows: + if row is None: + lo,hi=0,cap + else: + fc.require(type(row) in (list,tuple) and len(row)==2,'A lower/upper count pair is required') + lo,hi=row + fc.require(type(lo) is int and type(hi) is int and 0<=lo<=hi<=cap, + 'Ordered integer count bounds within the cap required') + low+=lo;high+=hi + mu_lo=max(Q(0),Q(low,n)-r) + mu_hi=min(Q(cap),Q(high,n)+r) + return cl.expectation_interval(cutoff,failure,mu_lo,mu_hi) diff --git a/experiments/periodic_h0/count_confidence_certificate.py b/experiments/periodic_h0/count_confidence_certificate.py new file mode 100644 index 000000000..4aae5e9c0 --- /dev/null +++ b/experiments/periodic_h0/count_confidence_certificate.py @@ -0,0 +1,191 @@ +"""Exact planning and finite-law controls for conditional count confidence.""" +import argparse +import hashlib +import itertools +import platform +import re +import sys +from datetime import datetime, timezone +from pathlib import Path +from fractions import Fraction as Q +import finite_certificate as fc +import finite_count_loss_certificate as prior +import count_confidence as cc +from gaussian_tail import exp_neg_bounds + +BASE=Path(__file__).resolve().parent +PARENT_DIR='results/finite_count_loss1' +PARENT_CERT=PARENT_DIR+'/CERTIFICATE.json' +PARENT_RUN=PARENT_DIR+'/RUN.json' +PARENT_SHA256='24aa80e76b45280f2562d040bc51136cb055ef3b9a5f54d156afef2a1f525d03' +PARENT_RUN_SHA256='dfc4a55c1ccf43f42d2db88e5b95d81e4aad1ed6337af8ad11084a71d81a499b' +SOURCE_PATHS=tuple(sorted(set(prior.SOURCE_PATHS)|{ + 'count_confidence.py','count_confidence_certificate.py','COUNT_CONFIDENCE.md', + PARENT_CERT,PARENT_RUN,PARENT_DIR+'/RUN.sha256',PARENT_DIR+'/RESULTS.md'})) +SCOPE=('Fixed-sample simultaneous confidence transfer for finite-cutoff expected ' + 'counts under the stated IID word law and pointwise row bounds. Exact ' + 'prospective plans and abstract finite-law controls, not observed Gaussian ' + 'data, authenticated sampling, infinite-field inference or lifetime-law confirmation.') +identity=prior.identity + + +def load_parent(): + fc.require(identity(BASE/PARENT_CERT)['sha256']==PARENT_SHA256,'Frozen count-loss certificate changed') + fc.require(identity(BASE/PARENT_RUN)['sha256']==PARENT_RUN_SHA256,'Frozen count-loss receipt changed') + # The unchanged parent's semantic replay is a separate required stage. + return prior.validate_directory(BASE/PARENT_DIR) + + +def toy_controls(): + exact=retained=discarded=adaptive_bad=0 + for bits in itertools.product((0,1),repeat=8): + rows=[(16*b,16*b) for b in bits] + lo,hi=cc.mean_interval(1,Q(0),rows,Q(4),8) + exact+=not(lo<=8<=hi) + partial=[None if b else (0,0) for b in bits] + retained+=cc.mean_interval(1,Q(0),partial,Q(4),8)[1]<8 + successes=[(0,0) for b in bits if not b] + if successes: + discarded+=cc.mean_interval(1,Q(0),successes,Q(4),len(successes))[1]<8 + adaptive=[None if (sum(bits)+i)%3==0 else row for i,row in enumerate(rows)] + alo,ahi=cc.mean_interval(1,Q(0),adaptive,Q(4),8) + adaptive_bad+=not(alo<=lo<=hi<=ahi) + family_bad=0 + for chosen in range(4): + intervals=[cc.mean_interval(1,Q(0),[(16*int(j==chosen),)*2],Q(10),1) for j in range(4)] + family_bad+=any(not(lo<=4<=hi) for lo,hi in intervals) + dependent_bad=0 + for b in (0,1): + lo,hi=cc.mean_interval(1,Q(0),[(16*b,16*b)]*8,Q(6),8) + dependent_bad+=not(lo<=8<=hi) + return {'kind':'abstract finite laws, not field observations','enumerated_sequences':256, + 'exact_two_sided_failure':str(Q(exact,256)), + 'correct_two_sided_risk':str(cc.risk_upper(1,8,1,Q(4))), + 'wrong_capless_risk':str(2*exp_neg_bounds(Q(256))[1]), + 'retained_unresolved_upper_failure':str(Q(retained,256)), + 'discarding_failure':str(Q(discarded,256)), + 'discarding_empty_sequences':1,'adaptive_widening_violations':adaptive_bad, + 'family_failure':str(Q(family_bad,4)), + 'wrong_single_bin_risk':str(cc.risk_upper(1,1,1,Q(10))), + 'correct_family_risk':str(cc.risk_upper(1,1,4,Q(10))), + 'dependent_row_failure':str(Q(dependent_bad,2)), + 'wrong_independent_risk':str(cc.risk_upper(1,8,1,Q(6)))} + + +def certify(): + parent=load_parent();plans=[] + for row in parent['budgets']: + k=row['cutoff'];cap=row['finite_bar_cap'];r=Q(cap,100) + risk=cc.risk_upper(k,40000,8,r) + plans.append({'cutoff':k,'finite_bar_cap':cap,'sample_count':40000,'bins':8, + 'radius':str(r),'risk_upper':str(risk),'risk_decimal_up':fc.decimal_up(risk,18), + 'sample_count_for_radius_one':4*cap*cap, + 'clipping_failure_upper':row['clipping_failure_upper'], + 'expected_count_loss_upper':row['expected_count_loss_upper']}) + example=cc.mean_interval(1,Q(1,1000),[(4,5),None,(2,3),(6,8)],Q(1,2),4) + return {'schema_version':1,'scope':SCOPE, + 'target':'Finite Gaussian F64,K on the side24 torus with fixed S_alpha,64 normalization; K in {1,24,32}.', + 'parent_certificate_sha256':PARENT_SHA256,'parent_receipt_sha256':PARENT_RUN_SHA256, + 'input_law_is_hypothesis':True,'iid_input_law_certified':False, + 'prospective_n_bins_radius_required':True,'pointwise_row_evidence_required':True, + 'adaptive_grid_refinement_allowed':True,'all_draws_retained_required':True, + 'family_risk_formula':'min(1,2*m*exp(-2*n*(r/(16*K^2))^2))', + 'interval_formula':'[max(0,mean(L)-r-16*K^2*p), min(16*K^2,mean(U)+r+16*K^2*p)]', + 'plans':plans,'toy_controls':toy_controls(), + 'arithmetic_example':{'kind':'invented numeric rows only; no authenticated grid or sampler budget', + 'rows':[[4,5],None,[2,3],[6,8]],'sample_count':4,'radius':'1/2', + 'illustrative_probability':'1/1000','interval':[str(x) for x in example]}, + 'new_gaussian_barcodes':0,'new_deterministic_barcodes':0, + 'observed_ensemble_means_computed':False,'infinite_field_expected_count_certified':False, + 'lifetime_law_certified':False,'formal_proof_certified':False, + 'next_obligation':'Actual inference needs a fixed plan, the declared IID source and all pointwise certified rows; infinite-field count moments and numerical lifetime remainder remain separate.'} + + +def verify(cert): + fc.require(fc.canonical_bytes(cert)==fc.canonical_bytes(certify()),'Confidence certificate differs from exact replay') + return True + + +def render_report(c): + lines=['# What sampling error would cost','', + 'The finite-cutoff bar cap gives simultaneous mean-confidence intervals', + 'under a fixed plan and the declared independent uniform-word input law.', + 'For eight bins and 40,000 draws, a radius of 1% of the cap has the', + 'following exact upper bound on family failure probability. These are', + '**prospective calculations; no ensemble has been sampled.**','', + '| Cutoff | Cap | Count radius | Failure bound | Draws for radius one at the same bound |', + '|---|---:|---:|---:|---:|'] + for r in c['plans']: + lines.append('| '+' | '.join(str(r[k]) for k in ('cutoff','finite_bar_cap','radius','risk_decimal_up','sample_count_for_radius_one'))+' |') + lines+=['','The intervals are', + '`[max(0, mean(L)-r-C*p), min(C, mean(U)+r+C*p)]`, with `C=16*K^2`.', + 'Every draw remains in the denominator. An unresolved computation supplies', + '`[0,C]`. Grid refinement may depend on the whole sample because concentration', + 'is applied to fixed latent polynomial counts and rows only bound those counts.', + 'Bins, radius and sample count must be fixed before inspecting the sample.','', + 'The large sample sizes at larger cutoffs expose the cost of this worst-case', + 'bound. They are not a recommendation to launch an ensemble. The gap between', + 'lower and upper grid means and the inherited clipping correction add uncertainty.','', + 'Exact abstract finite-law checks detect omitted cap scaling, omitted bin', + 'multiplicity, dependent rows and discarding unresolved outcomes. They are', + 'neither polynomial data nor evidence of an IID physical source.','', + 'The arithmetic checks do not authenticate input-law or row-certificate premises.', + 'No observed ensemble mean, infinite-field inference or lifetime-law confirmation', + 'is certified. The existing deterministic word fixture remains deterministic.','', + '[Proof and assumptions](../../COUNT_CONFIDENCE.md) · [Certificate](CERTIFICATE.json) · [Receipt](RUN.json)','', + '```sh', + 'python -B -S experiments/periodic_h0/count_confidence_certificate.py --verify experiments/periodic_h0/results/count_confidence1', + '```','',SCOPE,''] + return '\n'.join(lines) + + +def validate_directory(directory): + directory=Path(directory);r=fc.load_json(directory/'RUN.json') + fc.require(type(r) is dict and set(r)=={'schema_version','utc','python','platform','sources','outputs','scope'},'Invalid receipt fields') + fc.require(type(r['schema_version']) is int and r['schema_version']==1 and r['scope']==SCOPE,'Invalid receipt version/scope') + fc.require(type(r['utc']) is str and re.fullmatch(r'\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}\+00:00',r['utc']) is not None,'Invalid UTC') + stamp=datetime.fromisoformat(r['utc']) + fc.require(stamp.tzinfo==timezone.utc and stamp.isoformat(timespec='microseconds')==r['utc'],'Invalid UTC') + for key in ('python','platform'): + fc.require(type(r[key]) is str and 00,'Invalid byte count') + fc.require(type(item['sha256']) is str and re.fullmatch('[0-9a-f]{64}',item['sha256']) is not None,'Invalid hash') + fc.require((directory/'RUN.sha256').read_bytes()==(identity(directory/'RUN.json')['sha256']+'\n').encode(),'Receipt binding mismatch') + for name in SOURCE_PATHS:fc.require(identity(BASE/name)==r['sources'][name],'Source binding mismatch: '+name) + fc.require(identity(directory/'CERTIFICATE.json')==r['outputs']['CERTIFICATE.json'],'Output binding mismatch') + cert=fc.load_json(directory/'CERTIFICATE.json') + fc.require((directory/'RESULTS.md').read_bytes()==render_report(cert).encode(),'Report mismatch') + return cert + + +def verify_directory(directory): + verify(validate_directory(directory));return True + + +def produce(directory): + directory=Path(directory);fc.require(not directory.exists(),'Output must be new') + cert=certify();directory.mkdir(parents=True) + (directory/'CERTIFICATE.json').write_bytes(fc.canonical_bytes(cert)) + r={'schema_version':1,'utc':datetime.now(timezone.utc).isoformat(timespec='microseconds'), + 'python':sys.version,'platform':platform.platform(),'scope':SCOPE, + 'sources':{name:identity(BASE/name) for name in SOURCE_PATHS}, + 'outputs':{'CERTIFICATE.json':identity(directory/'CERTIFICATE.json')}} + raw=fc.canonical_bytes(r);(directory/'RUN.json').write_bytes(raw) + (directory/'RUN.sha256').write_text(hashlib.sha256(raw).hexdigest()+'\n') + (directory/'RESULTS.md').write_text(render_report(cert)) + return cert + + +def main(): + p=argparse.ArgumentParser(description=__doc__);g=p.add_mutually_exclusive_group(required=True) + g.add_argument('--produce',type=Path);g.add_argument('--verify',type=Path);a=p.parse_args() + if a.verify:verify_directory(a.verify) + else:produce(a.produce) + print('Exact fixed-sample confidence replay passed; sampling and row-evidence premises remain explicit.') + + +if __name__=='__main__':main() diff --git a/experiments/periodic_h0/results/count_confidence1/CERTIFICATE.json b/experiments/periodic_h0/results/count_confidence1/CERTIFICATE.json new file mode 100644 index 000000000..050eb324f --- /dev/null +++ b/experiments/periodic_h0/results/count_confidence1/CERTIFICATE.json @@ -0,0 +1 @@ +{"adaptive_grid_refinement_allowed":true,"all_draws_retained_required":true,"arithmetic_example":{"illustrative_probability":"1/1000","interval":["621/250","2129/250"],"kind":"invented numeric rows only; no authenticated grid or sampler budget","radius":"1/2","rows":[[4,5],null,[2,3],[6,8]],"sample_count":4},"family_risk_formula":"min(1,2*m*exp(-2*n*(r/(16*K^2))^2))","formal_proof_certified":false,"iid_input_law_certified":false,"infinite_field_expected_count_certified":false,"input_law_is_hypothesis":true,"interval_formula":"[max(0,mean(L)-r-16*K^2*p), min(16*K^2,mean(U)+r+16*K^2*p)]","lifetime_law_certified":false,"new_deterministic_barcodes":0,"new_gaussian_barcodes":0,"next_obligation":"Actual inference needs a fixed plan, the declared IID source and all pointwise certified rows; infinite-field count moments and numerical lifetime remainder remain separate.","observed_ensemble_means_computed":false,"parent_certificate_sha256":"24aa80e76b45280f2562d040bc51136cb055ef3b9a5f54d156afef2a1f525d03","parent_receipt_sha256":"dfc4a55c1ccf43f42d2db88e5b95d81e4aad1ed6337af8ad11084a71d81a499b","plans":[{"bins":8,"clipping_failure_upper":"13197691686391724259346892823029860133055019446312255466208347137/1160990899443410951245400337897717501357688570052027679898752546123172928290816","cutoff":1,"expected_count_loss_upper":"13197691686391724259346892823029860133055019446312255466208347137/72561931215213184452837521118607343834855535628251729993672034132698308018176","finite_bar_cap":16,"radius":"4/25","risk_decimal_up":"0.005367402046440190","risk_upper":"2427744909117015545311070063866556095783666140261164988714958908467391535/452312848583266388373324160190187140051835877600158453279131187530910662656","sample_count":40000,"sample_count_for_radius_one":1024},{"bins":8,"clipping_failure_upper":"3520850859891836660743543296454966019940566854510636152707360163993/1160990899443410951245400337897717501357688570052027679898752546123172928290816","cutoff":24,"expected_count_loss_upper":"31687657739026529946691889668094694179465101690595725374366241475937/1133780175237706007075586267478239747419617744191433281151125533323411062784","finite_bar_cap":9216,"radius":"2304/25","risk_decimal_up":"0.005367402046440190","risk_upper":"2427744909117015545311070063866556095783666140261164988714958908467391535/452312848583266388373324160190187140051835877600158453279131187530910662656","sample_count":40000,"sample_count_for_radius_one":339738624},{"bins":8,"clipping_failure_upper":"6195583041667226110637846908589017673573050795629919927192251850425/1160990899443410951245400337897717501357688570052027679898752546123172928290816","cutoff":32,"expected_count_loss_upper":"6195583041667226110637846908589017673573050795629919927192251850425/70861260952356625442224141717389984213726109011964580071945345832713191424","finite_bar_cap":16384,"radius":"4096/25","risk_decimal_up":"0.005367402046440190","risk_upper":"2427744909117015545311070063866556095783666140261164988714958908467391535/452312848583266388373324160190187140051835877600158453279131187530910662656","sample_count":40000,"sample_count_for_radius_one":1073741824}],"pointwise_row_evidence_required":true,"prospective_n_bins_radius_required":true,"schema_version":1,"scope":"Fixed-sample simultaneous confidence transfer for finite-cutoff expected counts under the stated IID word law and pointwise row bounds. Exact prospective plans and abstract finite-law controls, not observed Gaussian data, authenticated sampling, infinite-field inference or lifetime-law confirmation.","target":"Finite Gaussian F64,K on the side24 torus with fixed S_alpha,64 normalization; K in {1,24,32}.","toy_controls":{"adaptive_widening_violations":0,"correct_family_risk":"1","correct_two_sided_risk":"21298764540348831456955801040300466007493857928255494872408911038212689096057/28948022309329048855892746252171976963317496166410141009864396001978282409984","dependent_row_failure":"1","discarding_empty_sequences":1,"discarding_failure":"255/256","enumerated_sequences":256,"exact_two_sided_failure":"9/128","family_failure":"1","kind":"abstract finite laws, not field observations","retained_unresolved_upper_failure":"9/256","wrong_capless_risk":"1/57896044618658097711785492504343953926634992332820282019728792003956564819968","wrong_independent_risk":"6102198208005662132172278128672893843388761391536771416188385609858016893971/28948022309329048855892746252171976963317496166410141009864396001978282409984","wrong_single_bin_risk":"53013481482079227725673490684575034660984007019187160526073819637649085445657/57896044618658097711785492504343953926634992332820282019728792003956564819968"}} diff --git a/experiments/periodic_h0/results/count_confidence1/RESULTS.md b/experiments/periodic_h0/results/count_confidence1/RESULTS.md new file mode 100644 index 000000000..3002d327c --- /dev/null +++ b/experiments/periodic_h0/results/count_confidence1/RESULTS.md @@ -0,0 +1,40 @@ +# What sampling error would cost + +The finite-cutoff bar cap gives simultaneous mean-confidence intervals +under a fixed plan and the declared independent uniform-word input law. +For eight bins and 40,000 draws, a radius of 1% of the cap has the +following exact upper bound on family failure probability. These are +**prospective calculations; no ensemble has been sampled.** + +| Cutoff | Cap | Count radius | Failure bound | Draws for radius one at the same bound | +|---|---:|---:|---:|---:| +| 1 | 16 | 4/25 | 0.005367402046440190 | 1024 | +| 24 | 9216 | 2304/25 | 0.005367402046440190 | 339738624 | +| 32 | 16384 | 4096/25 | 0.005367402046440190 | 1073741824 | + +The intervals are +`[max(0, mean(L)-r-C*p), min(C, mean(U)+r+C*p)]`, with `C=16*K^2`. +Every draw remains in the denominator. An unresolved computation supplies +`[0,C]`. Grid refinement may depend on the whole sample because concentration +is applied to fixed latent polynomial counts and rows only bound those counts. +Bins, radius and sample count must be fixed before inspecting the sample. + +The large sample sizes at larger cutoffs expose the cost of this worst-case +bound. They are not a recommendation to launch an ensemble. The gap between +lower and upper grid means and the inherited clipping correction add uncertainty. + +Exact abstract finite-law checks detect omitted cap scaling, omitted bin +multiplicity, dependent rows and discarding unresolved outcomes. They are +neither polynomial data nor evidence of an IID physical source. + +The arithmetic checks do not authenticate input-law or row-certificate premises. +No observed ensemble mean, infinite-field inference or lifetime-law confirmation +is certified. The existing deterministic word fixture remains deterministic. + +[Proof and assumptions](../../COUNT_CONFIDENCE.md) · [Certificate](CERTIFICATE.json) · [Receipt](RUN.json) + +```sh +python -B -S experiments/periodic_h0/count_confidence_certificate.py --verify experiments/periodic_h0/results/count_confidence1 +``` + +Fixed-sample simultaneous confidence transfer for finite-cutoff expected counts under the stated IID word law and pointwise row bounds. Exact prospective plans and abstract finite-law controls, not observed Gaussian data, authenticated sampling, infinite-field inference or lifetime-law confirmation. diff --git a/experiments/periodic_h0/results/count_confidence1/RUN.json b/experiments/periodic_h0/results/count_confidence1/RUN.json new file mode 100644 index 000000000..37356728c --- /dev/null +++ b/experiments/periodic_h0/results/count_confidence1/RUN.json @@ -0,0 +1 @@ +{"outputs":{"CERTIFICATE.json":{"bytes":4656,"sha256":"7d6cb43b5e6ccb51256a13e561b03e88158a9f18325eaad12cf32887cc3c0b3d"}},"platform":"macOS-15.7.4-arm64-arm-64bit","python":"3.9.6 (default, Dec 2 2025, 07:27:58) \n[Clang 17.0.0 (clang-1700.6.3.2)]","schema_version":1,"scope":"Fixed-sample simultaneous confidence transfer for finite-cutoff expected counts under the stated IID word law and pointwise row bounds. Exact prospective plans and abstract finite-law controls, not observed Gaussian data, authenticated sampling, infinite-field inference or lifetime-law confirmation.","sources":{"APPROXIMATION.md":{"bytes":17970,"sha256":"dae4e01b35602077442796a1150294cce3eb544f2d0c2297f8fa7aa6ab16caef"},"COUNT_CONFIDENCE.md":{"bytes":13338,"sha256":"5e81b55f68aa62691d430deb20510bd3100b4098806052eee84950be646c9fd0"},"EXACT_H0.md":{"bytes":14491,"sha256":"a788b46b1ea5640661e2692b84816bb3acfd1bae5a1fd3083dd18d5d8ba19fff"},"FINITE_CERTIFICATE.md":{"bytes":9966,"sha256":"4c9991db82a94725a893526cf310bd84221b7787e704b649a94e161591efa7aa"},"FINITE_COUNT_LOSS.md":{"bytes":13881,"sha256":"395989b3181e480586229257d811b9b67faf948da8f7722df523a814b3ad77d2"},"GAUSSIAN_COUPLING.md":{"bytes":9302,"sha256":"d83abd492ee9404dc47071303b8410106e755a166ef2ae0b03b1bead8fa12f78"},"GAUSSIAN_TAIL.md":{"bytes":9791,"sha256":"7a0ddc8d390dbc2b06e90731a49be8d4f36d6b8614168c17a05e9bdf818c8807"},"HESSIAN_GRID.md":{"bytes":8683,"sha256":"a6e7053da42e10f7fdf637c66e4948e62136e26e80a2d0d80bde9b822d052225"},"NODAL_CERTIFICATE.md":{"bytes":8477,"sha256":"6b39f935c66a129dc3661f464586912bc034bd46a47a8f96a9a3167c26601940"},"count_confidence.py":{"bytes":2559,"sha256":"727af78f864eebfff68929490459517944f79f06a0fa3b40797ca4b67483f176"},"count_confidence_certificate.py":{"bytes":11318,"sha256":"352bf902d760f77add19ea693fd0cd7fa30cd0fc8db1727ef51d820f14bf7645"},"exact_barcode_certificate.py":{"bytes":10590,"sha256":"986da88dd703b4598ebf7782f874854124272ef6dbf67d7deb130972a86a217b"},"exact_h0.py":{"bytes":9089,"sha256":"48ee16f2316cb1a233594ed10466340aa321d553c2b888198fe86b4bd9052970"},"experiment.py":{"bytes":7020,"sha256":"affcefd3e3e0c44dbd312be25a5e8294ea270a9287db22fdc018d7aad99cb733"},"finite_certificate.py":{"bytes":14843,"sha256":"0674a2621dff6c040cbb24cc0b6e6df7847541ebc171ebdb28070afa05e04e6b"},"finite_count_loss.py":{"bytes":2698,"sha256":"85fca300f2dcb1af6102a3d82205e80cf5cb7f345b945186f2deb14d6b7f4317"},"finite_count_loss_certificate.py":{"bytes":10228,"sha256":"3b0ad8629702c1be93c7a84ae0715575e92fcd888a201ff2705c9b82df43625e"},"gaussian_coupling.py":{"bytes":6036,"sha256":"07e4d38720b778fb2a7487996a1beeafe29ffae34273491f5d6e1245e4dddffe"},"gaussian_coupling_certificate.py":{"bytes":8319,"sha256":"75023f4ab771ffd86a434ef3fc3bc9e9744ca6906c225ee986d85aec58a803b6"},"gaussian_tail.py":{"bytes":4688,"sha256":"07e55a62ed0bb6da6a9395762e2e0c033126f83b46abd48db4c24df710779db8"},"gaussian_tail_certificate.py":{"bytes":8456,"sha256":"a6855f836f04fe43aa3837f9d517237f09c0b886db3abb38a56fc3734d565631"},"hessian_grid_certificate.py":{"bytes":10447,"sha256":"3cc56eff4bfc3e648ad9ac74917db819288b606f7eddc5af5c24f8b835467690"},"hessian_grid_core.py":{"bytes":4304,"sha256":"0cd8cc11fc8c87893400b56153a5c8ce3e5aea9ec9e97df95b699a823aedc119"},"nodal_core.py":{"bytes":6388,"sha256":"a9b326664bb9f9fb9983491566cbf2030eaa0533f776ccd7a4f64ba809cc7b7e"},"results/certificate8/COEFFICIENTS.json":{"bytes":857299,"sha256":"f9703c9098bff546efda6eb8da6f012ac0e8f23b84b48cb2d997562d235faf71"},"results/exact_h0_1/CERTIFICATE.json":{"bytes":7635,"sha256":"845dc940e1781e570d4a6614a00889f33b239274c00e367dc2af1e3b86906fb8"},"results/exact_h0_1/RUN.json":{"bytes":2297,"sha256":"e51fba013218e746c6845283312cd9ac1e688a8b960e9a2c577a097be5b54c45"},"results/exact_h0_1/RUN.sha256":{"bytes":65,"sha256":"3d51e65e03a26bd2017a00ee601e4844e604c30bfb1795573b0fd8eec7fa44d5"},"results/finite_count_loss1/CERTIFICATE.json":{"bytes":4997,"sha256":"24aa80e76b45280f2562d040bc51136cb055ef3b9a5f54d156afef2a1f525d03"},"results/finite_count_loss1/RESULTS.md":{"bytes":2548,"sha256":"39e363b01b161b262e1b5d367dd7b999c98f03017b676d60a1bbf083228e059a"},"results/finite_count_loss1/RUN.json":{"bytes":4668,"sha256":"dfc4a55c1ccf43f42d2db88e5b95d81e4aad1ed6337af8ad11084a71d81a499b"},"results/finite_count_loss1/RUN.sha256":{"bytes":65,"sha256":"cd95bc57a44eea9114d26ced1b2a489d3282b59f8644263a9c1e985b3a463428"},"results/gaussian_coupling1/CERTIFICATE.json":{"bytes":18341,"sha256":"1ab5e225ec3e0a570910afc11026adf38ce39d01a4a8a16caa9ad487c95e1e32"},"results/gaussian_coupling1/RUN.json":{"bytes":3851,"sha256":"dbc5b27e6ea7e147133b48194889599a7fe1471bdb218c0513cb1ccb96a77d61"},"results/gaussian_coupling1/RUN.sha256":{"bytes":65,"sha256":"5401d9a451d79197a2ef8d8b5658e3e5485d9daeae8ae485bd673a3c2ba23899"},"results/gaussian_tail1/CERTIFICATE.json":{"bytes":15004,"sha256":"9284099183648476bbceb6ddc6cd54bb212713402b1b8c15a8684e237587c960"},"results/gaussian_tail1/RUN.json":{"bytes":3100,"sha256":"2bab16d8bb51c55f599d30ff119aba57bf31d24bcb5ce1192658e085a25a199c"},"results/gaussian_tail1/RUN.sha256":{"bytes":65,"sha256":"ba49dcace0e45b866a11bec1d674120b8d055f5a6671fc669d572dab6a61ed02"},"results/hessian1/CERTIFICATE.json":{"bytes":25301,"sha256":"c46cfc061465b951968f675270b649cd6b61c1dc4989635a1c3c7a3f7a564519"},"results/hessian1/RUN.json":{"bytes":1573,"sha256":"3bea8119b5fc3b8aadf887b439d3032f7d88377771c338db44e320dfc60979e1"},"results/hessian1/RUN.sha256":{"bytes":65,"sha256":"ad4536f2bcfc15863af27f7f26176c30973beb4a87efaee95ca34410a0e7bb4b"}},"utc":"2026-10-01T11:22:20.087708+00:00"} diff --git a/experiments/periodic_h0/results/count_confidence1/RUN.sha256 b/experiments/periodic_h0/results/count_confidence1/RUN.sha256 new file mode 100644 index 000000000..ddc1b4cdb --- /dev/null +++ b/experiments/periodic_h0/results/count_confidence1/RUN.sha256 @@ -0,0 +1 @@ +502f535796c28d54a77ef8ca59667a6d86ab279bc29a3e7ae3981f46fc57bd2d diff --git a/experiments/periodic_h0/test_count_confidence.py b/experiments/periodic_h0/test_count_confidence.py new file mode 100644 index 000000000..fafad99a7 --- /dev/null +++ b/experiments/periodic_h0/test_count_confidence.py @@ -0,0 +1,75 @@ +"""Fixed-sample inference controls; no empirical field sample is generated.""" +import importlib +import importlib.util +import itertools +import unittest +from fractions import Fraction as Q + + +class CountConfidenceTests(unittest.TestCase): + @classmethod + def setUpClass(cls): + if importlib.util.find_spec('count_confidence') is None: + raise AssertionError('Fixed-sample confidence implementation is missing') + cls.m=importlib.import_module('count_confidence') + + def test_family_risk_pays_for_both_sides_and_all_bins(self): + risk=self.m.risk_upper(1,40000,8,Q(4,25)) + self.assertGreater(risk,Q(5367402046440189,10**18)) + self.assertLess(risk,Q(5367402046440190,10**18)) + self.assertEqual(risk,16*self.m.risk_upper(1,40000,1,Q(4,25))/2) + self.assertEqual(self.m.risk_upper(24,40000,8,Q(2304,25)),risk) + + def test_missing_rows_keep_original_denominator_and_universal_upper(self): + rows=[(4,5),None,(2,3),(6,8)] + self.assertEqual(self.m.mean_interval(1,Q(1,1000),rows,Q(1,2),4), + (Q(621,250),Q(2129,250))) + with self.assertRaises(ValueError): + self.m.mean_interval(1,Q(1,1000),rows[:3],Q(1,2),4) + self.assertEqual(self.m.mean_interval(1,Q(0),[None]*4,Q(1,2),4),(Q(0),Q(16))) + + def test_count_weighted_clipping_and_clamps_are_not_omitted(self): + self.assertEqual(self.m.mean_interval(1,Q(1,10),[(4,5)],Q(1),1),(Q(7,5),Q(38,5))) + self.assertEqual(self.m.mean_interval(1,Q(0),[(0,16)],Q(1),1),(Q(0),Q(16))) + + def test_invalid_inputs_do_not_become_probability_claims(self): + for k,n,m,r in [(True,5,1,Q(1)),(1,True,1,Q(1)),(1,0,1,Q(1)), + (1,5,0,Q(1)),(1,5,True,Q(1)),(1,5,1,0.1), + (1,5,1,Q(0)),(1,5,1,Q(-1))]: + with self.assertRaises(ValueError):self.m.risk_upper(k,n,m,r) + for rows in [[],[(False,2)],[(3,2)],[(0,17)],[(0.0,2)],[(0,2,3)]]: + with self.assertRaises(ValueError):self.m.mean_interval(1,Q(0),rows,Q(1),1) + for p in [Q(-1),Q(2),0.01]: + with self.assertRaises(ValueError):self.m.mean_interval(1,p,[(0,1)],Q(1),1) + + def test_large_exponents_stay_outward_and_vacuous_risk_is_clipped(self): + self.assertEqual(self.m.risk_upper(1,1,8,Q(1,100)),Q(1)) + self.assertGreater(self.m.risk_upper(1,10**20,8,Q(1)),Q(0)) + self.assertLess(self.m.risk_upper(1,10**20,8,Q(1)),Q(1,10**30)) + + def test_exact_iid_finite_law_with_adaptive_grid_failures(self): + # Latent fixed count is 16*Bernoulli(1/2), mean8. Processing may + # depend on the whole sequence. Missing rows cannot damage coverage. + n=8;r=Q(6);covered=0;bad=0 + for bits in itertools.product((0,1),repeat=n): + rows=[None if (sum(bits)+i)%3==0 else (16*x,16*x) for i,x in enumerate(bits)] + lo,hi=self.m.mean_interval(1,Q(0),rows,r,n) + covered+=lo<=8<=hi + bad+=not (lo<=8<=hi) + self.assertEqual(covered+bad,256) + self.assertLessEqual(Q(bad,256),self.m.risk_upper(1,n,1,r)) + + def test_dependence_and_success_only_selection_break_the_premises(self): + # Repeating one random bit eight times has miss probability1, + # larger than the IID budget. The API cannot detect that dependence. + n=8;r=Q(6) + for bit in (0,1): + lo,hi=self.m.mean_interval(1,Q(0),[(16*bit,16*bit)]*n,r,n) + self.assertFalse(lo<=8<=hi) + self.assertLess(self.m.risk_upper(1,n,1,r),Q(1)) + # Keeping only zero-count successes can report [0,6] although mu=8. + lo,hi=self.m.mean_interval(1,Q(0),[(0,0)]*n,r,n) + self.assertLess(hi,Q(8)) + + +if __name__=='__main__':unittest.main() diff --git a/experiments/periodic_h0/test_count_confidence_certificate.py b/experiments/periodic_h0/test_count_confidence_certificate.py new file mode 100644 index 000000000..56faeb15b --- /dev/null +++ b/experiments/periodic_h0/test_count_confidence_certificate.py @@ -0,0 +1,71 @@ +"""Exact finite-law controls and rejection of rebound false confidence claims.""" +import copy +import importlib +import importlib.util +import tempfile +import unittest +from pathlib import Path +from fractions import Fraction as Q +import finite_certificate as fc + + +class ConfidenceCertificateTests(unittest.TestCase): + @classmethod + def setUpClass(cls): + if importlib.util.find_spec('count_confidence_certificate') is None: + raise AssertionError('Confidence certificate is missing') + cls.m=importlib.import_module('count_confidence_certificate') + cls.c=cls.m.certify() + + def test_planning_scales_and_parent_loss(self): + for row,cap,n in zip(self.c['plans'],[16,9216,16384],[1024,339738624,1073741824]): + self.assertEqual(row['finite_bar_cap'],cap) + self.assertEqual(Q(row['radius']),Q(cap,100)) + self.assertEqual(row['sample_count_for_radius_one'],n) + self.assertEqual(Q(row['risk_decimal_up']),Q('0.005367402046440190')) + self.assertLessEqual(Q(row['risk_upper']),Q(row['risk_decimal_up'])) + self.assertEqual(Q(row['expected_count_loss_upper']),cap*Q(row['clipping_failure_upper'])) + self.assertTrue(self.m.verify(self.c)) + + def test_exhaustive_toy_laws_and_invalid_shortcuts(self): + c=self.c['toy_controls'] + self.assertEqual(c['enumerated_sequences'],256) + self.assertEqual(Q(c['exact_two_sided_failure']),Q(9,128)) + self.assertEqual(Q(c['retained_unresolved_upper_failure']),Q(9,256)) + self.assertEqual(Q(c['discarding_failure']),Q(255,256)) + self.assertEqual(c['adaptive_widening_violations'],0) + self.assertEqual(Q(c['family_failure']),1) + self.assertLess(Q(c['wrong_single_bin_risk']),1) + self.assertEqual(Q(c['correct_family_risk']),1) + self.assertEqual(Q(c['dependent_row_failure']),1) + self.assertLess(Q(c['wrong_independent_risk']),1) + self.assertLess(Q(c['wrong_capless_risk']),Q(9,128)) + self.assertGreater(Q(c['correct_two_sided_risk']),Q(9,128)) + + def test_semantic_changes_rejected_even_with_rebound_receipt(self): + mutations=[lambda c:c['plans'][0].update(sample_count=39999), + lambda c:c['plans'][0].update(bins=1), + lambda c:c['plans'][0].update(cutoff=24), + lambda c:c['plans'][0].update(clipping_failure_upper='0'), + lambda c:c['plans'][0].update(risk_upper='0'), + lambda c:c['toy_controls'].update(exact_two_sided_failure='0'), + lambda c:c.update(iid_input_law_certified=True), + lambda c:c.update(observed_ensemble_means_computed=True), + lambda c:c.update(infinite_field_expected_count_certified=True), + lambda c:c.update(scope='Unconditional observed Gaussian confidence')] + for change in mutations: + c=copy.deepcopy(self.c);change(c) + with self.assertRaises(ValueError):self.m.verify(c) + with tempfile.TemporaryDirectory() as tmp: + d=Path(tmp)/'run';self.m.produce(d) + self.assertTrue(self.m.verify_directory(d)) + c=fc.load_json(d/'CERTIFICATE.json');c['plans'][0]['risk_upper']='0' + (d/'CERTIFICATE.json').write_bytes(fc.canonical_bytes(c)) + (d/'RESULTS.md').write_text(self.m.render_report(c)) + r=fc.load_json(d/'RUN.json');r['outputs']['CERTIFICATE.json']=self.m.identity(d/'CERTIFICATE.json') + (d/'RUN.json').write_bytes(fc.canonical_bytes(r)) + (d/'RUN.sha256').write_text(self.m.identity(d/'RUN.json')['sha256']+'\n') + with self.assertRaises(ValueError):self.m.verify_directory(d) + + +if __name__=='__main__':unittest.main()