Sequential designs¶
Warm-started, batch-by-batch updates with optional early stopping based on Bayes factor or ROPE thresholds.
Non-paired¶
SequentialNonPairedBayesPropTest(alpha0=1.0, beta0=1.0, threshold=0.5, bf_upper=10.0, bf_lower=0.1, n_max=None, n_min=0, decision_rule='all', rope_epsilon=0.02, seed=0, n_samples=20000, n_quad=100, verbose=False)
¶
Sequential / streaming non-paired Bayesian A/B test.
Maintains a running Beta posterior per arm and updates it as new batches of observations arrive. Because the Beta-Bernoulli model is conjugate, the current posterior is also the prior for the next batch — so the running posterior parameters are sufficient state.
On every :meth:update call the cumulative posterior is re-evaluated
via :class:NonPairedBayesPropTest, producing a snapshot containing
the posterior state, P(theta_B > theta_A), Savage-Dickey Bayes
factor, posterior probability of H₀, ROPE analysis, and a
sequential stopping decision.
Stopping rule: stop when the Savage-Dickey BF₁₀ exceeds
bf_upper (evidence for H₁), falls below bf_lower (evidence
for H₀), or when both arms reach n_max (if set).
Initialise the sequential non-paired test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha0
|
float
|
Prior alpha for both arms (used at look 0). |
1.0
|
beta0
|
float
|
Prior beta for both arms (used at look 0). |
1.0
|
threshold
|
float
|
Binarization threshold for continuous scores. |
0.5
|
bf_upper
|
float
|
Stop for H₁ when BF₁₀ ≥ this value. |
10.0
|
bf_lower
|
float
|
Stop for H₀ when BF₁₀ ≤ this value. |
0.1
|
n_max
|
int | None
|
If set, stop once min(n_A, n_B) ≥ n_max. |
None
|
n_min
|
int
|
Minimum samples per arm before any BF-based stopping decision is allowed (guards against unstable early BFs). |
0
|
decision_rule
|
DecisionRuleType
|
Decision framework passed to
:meth: |
'all'
|
rope_epsilon
|
float
|
Half-width of the ROPE on Δ = θ_A − θ_B. |
0.02
|
seed
|
int
|
Random seed for Monte Carlo draws of Δ. |
0
|
n_samples
|
int
|
Number of Monte Carlo draws per look. |
20000
|
n_quad
|
int
|
Gauss-Legendre quadrature nodes for P(B > A). |
100
|
verbose
|
bool
|
If True, print a one-line summary per look. |
False
|
Source code in bayesprop/resources/bayes_nonpaired.py
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 | |
stopped
property
¶
True once a stopping rule has triggered.
stop_reason
property
¶
Reason for stopping, or None if still continuing.
update(y_a_batch, y_b_batch)
¶
Incorporate a new batch and return the updated snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_a_batch
|
ArrayLike
|
New observations for arm A (continuous or binary). |
required |
y_b_batch
|
ArrayLike
|
New observations for arm B (continuous or binary). |
required |
Returns:
| Type | Description |
|---|---|
SequentialLookResult
|
class: |
SequentialLookResult
|
attr: |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called after the stopping rule has fired. |
Source code in bayesprop/resources/bayes_nonpaired.py
run(batches)
¶
Consume a stream of batches until stopping or exhaustion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batches
|
Iterable[tuple[ArrayLike, ArrayLike]]
|
Iterable yielding |
required |
Returns:
| Type | Description |
|---|---|
SequentialLookResult
|
The final :class: |
Source code in bayesprop/resources/bayes_nonpaired.py
history_frame()
¶
Return the per-look history as a tidy DataFrame for plotting.
Source code in bayesprop/resources/bayes_nonpaired.py
plot_trajectory(**kwargs)
¶
Plot BF₁₀ and P(B > A) trajectories across looks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Accepts |
{}
|
Source code in bayesprop/resources/bayes_nonpaired.py
Paired (Laplace)¶
SequentialPairedBayesPropTest(prior_sigma_delta=1.0, bf_upper=10.0, bf_lower=0.1, n_max=None, n_min=0, decision_rule='all', rope_epsilon=0.02, seed=0, n_samples=8000, verbose=False, threshold=0.5)
¶
Sequential / streaming paired Bayesian A/B test (Laplace).
Maintains running cumulative sufficient statistics
(n_A, k_A, n_B, k_B) and re-fits the pooled Bernoulli logistic
model via :class:PairedBayesPropTest after each batch. Because the
likelihood depends on the data only through these four counts, the
refit at look t returns exactly the same Laplace posterior as
fitting all accumulated data in one shot — there is no information
loss from streaming.
On every :meth:update call the cumulative posterior is re-evaluated,
producing a snapshot containing the Laplace posterior state
(mu_MAP, delta_A_MAP, Sigma), the posterior probability
P(p_A > p_B) on the probability scale, the Savage-Dickey Bayes
factor on delta_A = 0 (logit scale), the ROPE classification on
Delta = p_A - p_B, and a sequential stopping decision.
Stopping rule: stop when the Savage-Dickey BF₁₀ exceeds
bf_upper (evidence for H₁), falls below bf_lower
(evidence for H₀), or when both arms reach n_max (if set).
Initialise the sequential paired Laplace test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prior_sigma_delta
|
float
|
Standard deviation of the N(0, sigma) prior
on |
1.0
|
bf_upper
|
float
|
Stop for H₁ when BF₁₀ ≥ this value. |
10.0
|
bf_lower
|
float
|
Stop for H₀ when BF₁₀ ≤ this value. |
0.1
|
n_max
|
int | None
|
If set, stop once min(n_A, n_B) ≥ n_max. |
None
|
n_min
|
int
|
Minimum samples per arm before any BF-based stopping decision is allowed (guards against unstable early BFs). |
0
|
decision_rule
|
DecisionRuleType
|
Decision framework passed to
:meth: |
'all'
|
rope_epsilon
|
float
|
Half-width of the ROPE on Δ = p_A - p_B (probability scale). |
0.02
|
seed
|
int
|
Random seed for the Laplace posterior draws. |
0
|
n_samples
|
int
|
Number of draws from the Laplace posterior per look. |
8000
|
verbose
|
bool
|
If True, print a one-line summary per look (and a notice whenever continuous batches are binarised). |
False
|
threshold
|
float
|
Cutoff used to binarise continuous batches in
|
0.5
|
Source code in bayesprop/resources/bayes_paired_laplace.py
1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 | |
stopped
property
¶
True once a stopping rule has triggered.
stop_reason
property
¶
Reason for stopping, or None if still continuing.
last_model
property
¶
The most recently fitted :class:_PairedLaplace (or None).
update(y_a_batch, y_b_batch)
¶
Incorporate a new paired batch and return the updated snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_a_batch
|
ArrayLike
|
New binary observations for arm A (0/1). |
required |
y_b_batch
|
ArrayLike
|
New binary observations for arm B (0/1), same length
as |
required |
Returns:
| Type | Description |
|---|---|
SequentialLaplaceLookResult
|
class: |
SequentialLaplaceLookResult
|
appended to :attr: |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called after the stopping rule has fired. |
ValueError
|
If batch lengths differ or contain non-binary values. |
Source code in bayesprop/resources/bayes_paired_laplace.py
run(batches)
¶
Consume a stream of paired batches until stopping or exhaustion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batches
|
Iterable[tuple[ArrayLike, ArrayLike]]
|
Iterable yielding |
required |
Returns:
| Type | Description |
|---|---|
SequentialLaplaceLookResult
|
The final :class: |
Source code in bayesprop/resources/bayes_paired_laplace.py
history_frame()
¶
Return the per-look history as a tidy DataFrame for plotting.
Source code in bayesprop/resources/bayes_paired_laplace.py
plot_trajectory(**kwargs)
¶
Plot BF₁₀ and P(p_A > p_B) trajectories across looks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Accepts |
{}
|