Skip to main content

engine.solvers.acceptance

engine.solvers.acceptance

Agent evaluation solvers: what a set of graded trials supports about a configuration.

Domain implementations behind mlsysim.solvers (added 2026-10-20). Each model is arithmetic on stated trial counts, verdicts, and costs: Wald and Wilson binomial intervals; the task counts a precision or detection target needs; a paired candidate-against-baseline comparison (Newcombe’s method 10, McNemar’s exact test, and the variance pairing removes); repeated runs of one task against new tasks; and batch versus sequential selection under one candidate cap. Repeated-run consistency over k recurrences is horizon compounding (HorizonCompoundingModel).

Classes

Name Description
BinomialIntervalsModel Wald and Wilson intervals for several success counts out of trials.
CappedSelectionCostModel Batch against sequential selection of up to cap candidates under an exact checker.
PairedComparisonModel A candidate against a baseline, one trial of each on the same tasks.
ProportionPlanningModel How many independent tasks a precision or a detection target needs.
TaskMixConsistencyModel All-pass probability of k runs: one task repeated against k new tasks.

BinomialIntervalsModel

engine.solvers.acceptance.BinomialIntervalsModel()

Wald and Wilson intervals for several success counts out of trials.

Wald collapses to zero width at x = 0 and leaves [0, 1] near the boundaries; Wilson keeps a nonzero width and stays inside, and the two nearly coincide near one half. The Wilson upper limit at x = 0 is z^2 / (n + z^2).

Methods

Name Description
solve Compare Wald and Wilson intervals for specified success counts.
solve
engine.solvers.acceptance.BinomialIntervalsModel.solve(
    trials,
    successes,
    confidence=0.95,
)

Compare Wald and Wilson intervals for specified success counts.

Parameters
Name Type Description Default
trials int Positive number of independent Bernoulli trials shared by each count. required
successes Sequence[int] Success counts from zero through trials, inclusive. required
confidence float Central confidence probability in (0, 1); default 0.95. 0.95
Returns
Name Type Description
BinomialIntervalsResult Dimensionless critical value and interval endpoints keyed by success count.
See Also

mlsysim.physics.statistics.calc_wald_interval : Uncorrected normal interval for a binomial rate. mlsysim.physics.statistics.calc_wilson_interval : Score interval that handles boundary success counts.

Notes

Equation: Wald uses p +/- z sqrt(p(1-p)/n); Wilson inverts the binomial score test. The normal quantile z is shared by both.

Assumptions: Each count represents independent trials with a common success probability.

Excludes: Repeated-task dependence, multiple-comparison correction, and exact coverage guarantees for the Wald approximation.

References

Wilson (1927), Probable Inference, the Law of Succession, and Statistical Inference. https://www.jstor.org/stable/2276774 The solver composes the two interval functions without changing their formulas.

Examples
>>> result = BinomialIntervalsModel().solve(10, [0, 5])
>>> result.wald[0] == (0.0, 0.0) and result.wilson[0][1] > 0
True

CappedSelectionCostModel

engine.solvers.acceptance.CappedSelectionCostModel()

Batch against sequential selection of up to cap candidates under an exact checker.

Both policies return a passing candidate with q = 1 - (1 - p)^cap. The batch generates and checks all cap; sequential selection stops at the first pass and starts q / p candidates on average. Charging every initiated trial to the accepted ones gives cap c / q against (c / p), where c is generation plus checking: sequential cost per accepted task does not depend on the cap, and only p lowers it.

Methods

Name Description
solve Compare batch and early-stopping selection under one candidate cap.
solve
engine.solvers.acceptance.CappedSelectionCostModel.solve(
    pass_rate,
    cap,
    generation_cost,
    check_cost,
)

Compare batch and early-stopping selection under one candidate cap.

Parameters
Name Type Description Default
pass_rate float Independent candidate acceptance probability in (0, 1]. required
cap int Positive maximum candidates per task. required
generation_cost Quantity Nonnegative generation cost per candidate, convertible to USD. required
check_cost Quantity Nonnegative exact-checker cost per candidate, convertible to USD; total unit cost must be positive. required
Returns
Name Type Description
CappedSelectionCostResult Dimensionless availability and counts; trial and accepted-task costs in USD.
See Also

mlsysim.physics.agents.calc_independent_success : Probability that at least one independent candidate passes.

Notes

Equation: q = 1 - (1-p)^cap; E[N_sequential] = q/p; batch cost per acceptance = cap*c/q and sequential cost per acceptance = c/p.

Assumptions: Independent identically distributed candidates, an exact checker, constant generation/check costs, and immediate stopping after acceptance.

Excludes: Parallel latency, checker errors, correlated candidates, and a feasible interpretation of the doubled-rate counterfactual when 2p exceeds one.

References

Derivation: sum the truncated geometric survival probabilities for expected starts and divide total trial cost by probability of acceptance.

Examples
>>> result = CappedSelectionCostModel().solve(0.25, 4, 1 * USD, 0.1 * USD)
>>> result.batch_per_accepted > result.sequential_per_accepted
True

PairedComparisonModel

engine.solvers.acceptance.PairedComparisonModel()

A candidate against a baseline, one trial of each on the same tasks.

Only discordant pairs move the difference; Newcombe’s method 10 gives its interval, and a noninferiority gate needs the lower limit above -tolerance. Lower half-widths shrink as 1 / sqrt(n), so the pairs that center the expected lower limit on the margin are n [(delta - lower) / (delta + tolerance)]^2 (even odds of clearing), and a true gain of zero needs the half-width inside the tolerance itself. The paired outcome has variance d - delta^2 per pair against p_c (1 - p_c) + p_b (1 - p_b) for two independent arms. McNemar’s exact test answers the separate equality question.

Methods

Name Description
solve Evaluate paired binary outcomes and approximate further sample needs.
solve
engine.solvers.acceptance.PairedComparisonModel.solve(
    both,
    candidate_only,
    baseline_only,
    neither,
    tolerance,
    confidence=0.95,
)

Evaluate paired binary outcomes and approximate further sample needs.

Parameters
Name Type Description Default
both int Nonnegative number of tasks accepted by both configurations. required
candidate_only int Nonnegative number accepted only by the candidate. required
baseline_only int Nonnegative number accepted only by the baseline. required
neither int Nonnegative number accepted by neither; total pairs must be positive. required
tolerance float Positive noninferiority margin in probability units. The observed gain plus tolerance and both variance denominators must be nonzero. required
confidence float Central interval probability in (0, 1); default 0.95. 0.95
Returns
Name Type Description
PairedComparisonResult Rates, interval endpoints, p-value, variance ratios, Boolean gates, and approximate integer pair counts.
See Also

mlsysim.physics.statistics.calc_newcombe_paired_difference : Paired difference with the method-10 score interval. mlsysim.physics.statistics.calc_mcnemar_exact_two_sided : Exact equality test using discordant pair counts.

Notes

Equation: delta = (candidate_only - baseline_only)/n; paired variance = discordant_fraction - delta^2. Newcombe method 10 supplies the interval. Planning scales n by squared current-width/target-width ratios.

Assumptions: Independent task pairs and stable population rates. Both methods observe the same tasks. The projected sample counts use inverse-square-root interval-width scaling.

Excludes: Sequential testing, task clusters, zero-variance degenerate cases, and a power guarantee for the projected pair counts.

References

Newcombe (1998), Improved confidence intervals for the difference between binomial proportions based on paired data. https://doi.org/10.1002/(SICI)1097-0258(19981130)17:22%3C2635::AID-SIM954%3E3.0.CO;2-C The additional sample projection is a solver approximation, not the interval method.

Examples
>>> result = PairedComparisonModel().solve(50, 20, 10, 20, 0.05)
>>> result.candidate_rate > result.baseline_rate and result.pairs == 100
True

ProportionPlanningModel

engine.solvers.acceptance.ProportionPlanningModel()

How many independent tasks a precision or a detection target needs.

One rate: the normal half-width z sqrt(p (1 - p) / n) shrinks as 1 / sqrt(n), and ceil(z^2 p (1 - p) / h^2) tasks reach a half-width h. Two independent arms at average rate p: about 2 (z_alpha + z_beta)^2 p (1 - p) / delta^2 tasks per arm detect a difference delta, so halving delta quadruples the count. The detection quantiles are the rounded planning values the caller states.

Methods

Name Description
solve Plan independent trial counts from precision and detection targets.
solve
engine.solvers.acceptance.ProportionPlanningModel.solve(
    rate,
    planning_tasks,
    target_half_width,
    differences,
    z_alpha,
    z_beta,
    confidence=0.95,
)

Plan independent trial counts from precision and detection targets.

Parameters
Name Type Description Default
rate float Planning success probability in the open interval (0, 1). required
planning_tasks int Positive number of independent tasks in the proposed evaluation. required
target_half_width float Positive target half-width in probability units. required
differences Sequence[float] Positive differences in probabilities to detect between independent arms. required
z_alpha float Positive normal critical value selected for the detection significance level. required
z_beta float Positive normal quantile selected for the desired detection power. required
confidence float Central probability for the single-rate interval; default 0.95. 0.95
Returns
Name Type Description
ProportionPlanningResult Dimensionless interval widths and integer sample counts, including counts per arm.
See Also

mlsysim.physics.statistics.calc_proportion_half_width : Normal standard-error half-width for one proportion. mlsysim.physics.statistics.calc_samples_for_half_width : Invert a requested one-rate interval half-width. mlsysim.physics.statistics.calc_two_proportion_sample_size : Equal-arm normal-approximation detection planning.

Notes

Equation: h = z sqrt(p(1-p)/n); n_target = ceil(z^2 p(1-p)/h^2). Two-arm planning uses ceil(2(z_alpha+z_beta)^2 p(1-p)/delta^2).

Assumptions: Independent Bernoulli tasks; the planning rate is supplied, not estimated by this solver. The Wilson comparison rounds rate times planning_tasks to a whole success count.

Excludes: Clustered tasks, paired-arm gains, attrition, and exact power calculations.

References

Derivation: solve the normal-approximation standard error for the sample count. The two-arm expression adds equal independent Bernoulli variances. The Wilson comparison is implemented by calc_wilson_interval.

Examples
>>> result = ProportionPlanningModel().solve(0.5, 100, 0.1, [0.1, 0.2], 1.96, 0.84)
>>> result.per_arm[0.1] > result.per_arm[0.2]
True

TaskMixConsistencyModel

engine.solvers.acceptance.TaskMixConsistencyModel()

All-pass probability of k runs: one task repeated against k new tasks.

Repeating one randomly drawn task passes every run with E[p_i^k]; k independently drawn tasks all pass with (E[p_i])^k, which Jensen’s inequality places at or below it (with inequality when task difficulty varies and k >= 2). Task types are equally weighted.

Methods

Name Description
solve Compare all-pass probabilities for repeated versus newly sampled tasks.
solve
engine.solvers.acceptance.TaskMixConsistencyModel.solve(
    task_pass_rates,
    repetitions,
)

Compare all-pass probabilities for repeated versus newly sampled tasks.

Parameters
Name Type Description Default
task_pass_rates Sequence[float] Nonempty sequence of per-task success probabilities in [0, 1]. required
repetitions int Positive number of runs in each all-pass event. required
Returns
Name Type Description
TaskMixConsistencyResult Dimensionless mean rate and all-pass probabilities under the two sampling policies.
Notes

Equation: same_task_all = mean(p_i^k); new_tasks_all = mean(p_i)^k.

Assumptions: Task types have equal weight; runs are independent conditional on their task type. New tasks are sampled independently with replacement.

Excludes: State carried across runs, correlated failures, and empirical uncertainty in task rates.

References

Derivation: condition on task type before multiplying conditional pass probabilities; average the conditional products for repeated tasks.

Examples
>>> result = TaskMixConsistencyModel().solve([0.2, 0.8], 2)
>>> result.same_task_all > result.new_tasks_all
True

Functions

Name Description
z_for_confidence Return the standard-normal critical value for a two-sided interval.

z_for_confidence

engine.solvers.acceptance.z_for_confidence(confidence)

Return the standard-normal critical value for a two-sided interval.

Parameters

Name Type Description Default
confidence float Central probability in (0, 1), dimensionless. required

Returns

Name Type Description
float Positive dimensionless normal quantile.

Notes

Equation: z = Phi^{-1}((1 + confidence) / 2).

Assumptions: Equal probability is allocated to each tail of a standard normal distribution.

Excludes: Student-t corrections and exact finite-sample binomial coverage.

References

Derivation: symmetry places the upper tail at (1 - confidence) / 2; inverting the normal cumulative distribution gives the critical value.

Examples

>>> z_for_confidence(0.95) > z_for_confidence(0.90)
True
Back to top