Auditing calibration feasibility before trusting weights
Source:vignettes/calibcheck.Rmd
calibcheck.Rmd
library(calibcheck)
M <- rbind(c(1,0),c(0,1),c(1,0),c(0,1))
f <- check_feasibility(M,c(.9,.1,.1,.9),target_num=c(9,1,1,9),target_den=10)
f[c("status","scope","lower","upper","exact")]## $status
## [1] "infeasible_to_tolerance"
##
## $scope
## [1] "unrestricted_simplex"
##
## $lower
## [1] 0.4
##
## $upper
## [1] 0.4
##
## $exact
## [1] TRUE
f$certificate[c("lower_num","lower_den","upper_num","upper_den")]## $lower_num
## [1] 4194304
##
## $lower_den
## [1] 10485760
##
## $upper_num
## [1] 4194304
##
## $upper_den
## [1] 10485760
The columns have identical patterns across the two margins. No nonnegative normalized weights can attain conflicting targets. A producer’s success flag is not a feasibility certificate. The exact bracket uses independently verified integer witnesses; it proves infeasibility at the requested tolerance for the specified rational target, not merely that the LP implementation reported failure.
audit_calibration(M,c(.9,.1,.1,.9),raw=c(.1,.9),converged=TRUE,
margin=c("A","A","B","B"),level=rep(c("1","2"),2))$raw$ledger## margin level target achieved residual
## 1 A 1 0.9 0.1 -0.8
## 2 A 2 0.1 0.9 0.8
## 3 B 1 0.1 0.1 0.0
## 4 B 2 0.9 0.9 0.0
Feasible does not mean practically usable. A target may require almost all weight on a single observation. Box constraints change the attainable set.
M <- matrix(c(1,0,0,0),1)
check_feasibility(M,.97)$min_max_weight## [1] 0.97
check_feasibility(M,.97,upper=.5)[c("scope","status","lower","upper")]## $scope
## [1] "bounded_simplex"
##
## $status
## [1] "infeasible_to_tolerance"
##
## $lower
## [1] 0.47
##
## $upper
## [1] 0.47
The four-task target requires at least 97% on the first task at exact balance; with a 50% cap the discrepancy is at least 0.47. The bounded result is numerical, not an exact certificate. Base weights can be translated into normalized per-task lower and upper bounds if that is the intended domain; no distance-to-base-weight objective is implemented.
z <- calibration_matrix(data.frame(region = c("a", "a", "b")),
list(region = c(a = .5, b = .25, c = .25)))
audit_calibration(z$M, z$target, raw = c(1, 1, 1),
margin = z$margin, level = z$level)$raw$ledger## margin level target achieved residual
## 1 region a 0.50 0.6666667 0.16666667
## 2 region b 0.25 0.3333333 0.08333333
## 3 region c 0.25 0.0000000 -0.25000000
The missing level is retained rather than silently dropped. The target mass assigned to it is a lower bound on the residual. Bounded concentration is computed over individual weight caps, not just aggregate pattern counts.
The public tests use synthetic matrices, exact target counts and independent optimization oracles.
Limitations
The exact verifier currently uses bounded integer arithmetic, not
arbitrary precision. For large target denominators, a 2^20 witness can
be insufficient at tolerance 1e-6; the automatic routine retries at 2^31
and larger safe scales. Arbitrary binary floating-point targets can
exceed the cap; no rational target is silently approximated. A numerical
verdict and a certified verdict are distinguished by exact
and the certificate field. Exact zero discrepancy is not guaranteed by
finite witness rounding. Bounded problems are numerical only.