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.7, 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.7
|
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
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 | |
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)
¶
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. |
False
|
Source code in bayesprop/resources/bayes_paired_laplace.py
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:PairedBayesPropTest (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 |
{}
|