Conformal Test Martingales¶
Martingales¶
online_cp.martingale.PluginMartingale
¶
Bases: ConformalTestMartingale
Plugin martingale using a betting strategy for density estimation.
The martingale wraps a BettingStrategy whose bet(p) method provides
the predictive density (betting function) at each step. The strategy is
updated after the bet — predict-then-learn order — preserving the
martingale property.
Protocol per step:
1. Predict: evaluate strategy.bet(p) (uses past data only)
2. Accumulate: logM += log(bet)
3. Learn: call strategy.update(p)
4. Expose: set b_n and B_n for the next step
For cautious behaviour during early steps (small sample), use
:class:ExpertAggregationStrategy to mix the primary strategy with a
uniform baseline, or wrap in a :class:SleeperStayer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
betting_strategy
|
BettingStrategy or type
|
An instantiated strategy, or a class to be instantiated with kwargs. |
GaussianKDE
|
**kwargs
|
Any
|
Passed to the strategy constructor if a class is given. |
{}
|
Examples:
>>> from online_cp.betting import FixedStrategy
>>> strat = FixedStrategy(pdf=lambda x: 1.5 if x < 0.5 else 0.5, check_integration=False)
>>> m = PluginMartingale(betting_strategy=strat)
>>> m.update(0.1)
>>> bool(np.isclose(m.M, 1.5))
True
>>> m.update(0.9)
>>> bool(np.isclose(m.M, 0.75))
True
Source code in src/online_cp/martingale/jumpers.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
update(p: float) -> None
¶
Bet on one p-value with the current strategy, then learn from it.
Evaluates the betting density at p, multiplies it into the
martingale (guarding against invalid densities), records the value, and
updates the underlying betting strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
New p-value in \([0, 1]\). |
required |
Source code in src/online_cp/martingale/jumpers.py
online_cp.martingale.SimpleMixtureMartingale
¶
Bases: ConformalTestMartingale
Simple Mixture Martingale using the incomplete gamma function.
This is the canonical "parameter-free" test martingale that averages over all power alternatives t^epsilon with epsilon ~ Exp(1). It has a closed-form solution based on the regularized incomplete gamma function.
After each step, b_n and B_n are set analytically:
- b_n(p) = M_n(p) / M_{n-1} where M_n(p) is the martingale value if the
next observation were p.
- B_n(p) = integral of b_n from 0 to p.
Examples:
>>> sm = SimpleMixtureMartingale()
>>> sm.update(0.01)
>>> sm.update(0.01)
>>> bool(sm.M > 1)
True
>>> sm.update(1.0)
>>> bool(sm.M < sm.martingale_values[-2])
True
Source code in src/online_cp/martingale/jumpers.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
update(p: float) -> None
¶
Advance the simple mixture martingale by one p-value.
Accumulates \(\sum \log p\) and recomputes the closed-form mixture log-martingale from the running count and log-sum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
New p-value in \([0, 1]\). |
required |
Source code in src/online_cp/martingale/jumpers.py
online_cp.martingale.SimpleJumper
¶
Bases: ConformalTestMartingale
Simple Jumper betting martingale (Algorithm 8.1 of ALRW2).
Uses a set of experts indexed by epsilon with betting functions f_epsilon(p) = 1 + epsilon*(p - 0.5). A Markov chain with jump rate J tracks the best expert, enabling adaptation to changing alternatives.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
J
|
float
|
Jump rate (probability of switching expert per step). |
0.01
|
E
|
list of float or None
|
Expert grid. Default is [-1, -0.5, 0, 0.5, 1] (Algorithm 8.1). |
None
|
References
Vovk, Gammerman & Shafer (2022). Algorithmic Learning in a Random World, 2nd edition, Algorithm 8.1. Cambridge University Press.
Examples:
Source code in src/online_cp/martingale/jumpers.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
update(p: float) -> None
¶
Advance the Simple Jumper mixture by one p-value.
Mixes a sleeping family of constant betting functions indexed by
\(\epsilon\) with jump probability J, updating the per-\(\epsilon\) and
pooled log-wealth in log-space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
New p-value in \([0, 1]\). |
required |
Source code in src/online_cp/martingale/jumpers.py
online_cp.martingale.CompositeJumper
¶
Bases: ConformalTestMartingale
Composite Jumper that averages over multiple jump rates.
Examples:
Source code in src/online_cp/martingale/jumpers.py
update(p: float) -> None
¶
Advance every sub-jumper and recompute the pooled martingale.
Updates each component jumper on p and sets the composite
log-martingale to the (equal-weight) log-mean of the components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
New p-value in \([0, 1]\). |
required |
Source code in src/online_cp/martingale/jumpers.py
online_cp.martingale.SleeperStayer
¶
Bases: ConformalTestMartingale
Sleeper/Stayer conformal test martingale (Algorithm 9.4 of ALRW2).
Maintains a grid of piecewise-constant betting experts indexed by (a, b) together with a sleeping capital account. At each step, a fraction R of the sleeping capital is redistributed equally to all active experts.
Each expert uses the betting function f_{(a,b)}(p) = b/a if p <= a, else (1-b)/(1-a). This targets change-points where the conformal p-values shift from Uniform to having mass b below threshold a.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
R
|
float
|
Wake-up rate: fraction of sleeping capital redistributed per step. |
0.001
|
G
|
int
|
Grid resolution. The grid is {1/G, 2/G, ..., (G-1)/G}^2. |
10
|
References
Vovk, Gammerman & Shafer (2022). Algorithmic Learning in a Random World, 2nd edition, Algorithm 9.4 (Sleeper). Cambridge University Press.
Examples:
>>> ss = SleeperStayer(R=0.01, G=5)
>>> for _ in range(50):
... ss.update(0.05)
>>> bool(ss.M > 1.0)
True
Source code in src/online_cp/martingale/sleepers.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
update(p: float) -> None
¶
Advance the Sleeper/Stayer martingale by one p-value.
Each active threshold expert bets on p (left vs right of its
threshold) while a sleeping reserve preserves capital; the martingale is
the total capital across the sleeping and active experts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
New p-value in \([0, 1]\). |
required |
Source code in src/online_cp/martingale/sleepers.py
online_cp.martingale.SleeperDrifter
¶
Bases: ConformalTestMartingale
Sleeper/Drifter conformal test martingale (Algorithm 9.5 of ALRW2).
Extension of the Sleeper/Stayer that wakes experts in batches every M steps and uses a drifting threshold that interpolates between the initial guess a and the target b over time.
The drifting threshold for expert (i, a, b) at step n is: a' = (iM/n)a + (1 - iM/n)b
This makes the martingale more sensitive to gradual distribution shifts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
R
|
float
|
Wake-up rate per batch: fraction of sleeping capital allocated when a new batch wakes up. |
0.001
|
G
|
int
|
Grid resolution. The grid is {1/G, 2/G, ..., (G-1)/G}^2. |
10
|
M
|
int
|
Batch interval: new experts wake up every M steps. |
100
|
References
Vovk, Gammerman & Shafer (2022). Algorithmic Learning in a Random World, 2nd edition, Algorithm 9.5 (Drifter). Cambridge University Press.
Examples:
>>> sd = SleeperDrifter(R=0.01, G=5, M=10)
>>> for _ in range(50):
... sd.update(0.05)
>>> bool(sd.M > 1.0)
True
Source code in src/online_cp/martingale/sleepers.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
update(p: float) -> None
¶
Advance the Sleeper/Drifter martingale by one p-value.
Like :class:SleeperStayer, but each expert's threshold drifts over
time, so the bet uses the current drifted threshold of every active
expert before pooling their capital.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
New p-value in \([0, 1]\). |
required |
Source code in src/online_cp/martingale/sleepers.py
Legendre Jumper Martingales¶
online_cp.martingale.SimpleLegendreJumper
¶
Bases: ConformalTestMartingale
Simple Legendre Jumper betting martingale (Algorithm 2).
Uses the betting function f_eps^(k)(p) = 1 + eps * P_k(2p-1) with a Markov chain over the state space E and jump rate J.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order
|
int
|
Degree k >= 1 of the shifted Legendre polynomial. |
1
|
J
|
float
|
Jump rate in (0, 1]. |
0.01
|
epsilon_grid
|
tuple of float
|
State space E. Default is the paper's 5-point grid. |
STANDARD_GRID
|
Examples:
>>> slj = SimpleLegendreJumper(order=1, J=0.01)
>>> for _ in range(10):
... slj.update(0.01)
>>> slj.M > 1.0
True
Source code in src/online_cp/martingale/legendre.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
update(p: float) -> None
¶
Advance the simple Legendre jumper by one p-value.
Performs the jump (mixing over the \(\epsilon\) grid) then bets with the shifted-Legendre density of the configured order, all in log-space ([LegendreJumper, preprint]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
New p-value in \([0, 1]\). |
required |
Source code in src/online_cp/martingale/legendre.py
online_cp.martingale.ProductLegendreJumper
¶
Bases: ConformalTestMartingale
Product Legendre Jumper betting martingale (Algorithm 3).
Maintains a single Markov chain over the full Cartesian product state space E = E_1 x E_2 x ... x E_K, with betting function:
f_eps^K(p) = prod_k (1 + eps_k * P_k(p)) / Z(eps)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orders
|
list of int
|
Set K of Legendre polynomial degrees (each >= 1). |
None
|
J
|
float
|
Jump rate in (0, 1]. |
0.01
|
epsilon_grid
|
tuple of float
|
Per-order state space E_k. Default is the paper's 5-point grid. |
STANDARD_GRID
|
Examples:
>>> plj = ProductLegendreJumper(orders=[1, 2], J=0.01)
>>> for _ in range(10):
... plj.update(0.01)
>>> plj.M > 1.0
True
Source code in src/online_cp/martingale/legendre.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | |
update(p: float) -> None
¶
Advance the product Legendre jumper by one p-value.
Bets with a product of shifted-Legendre densities over several orders, after the jump-mixing step over the \(\epsilon\) grid ([LegendreJumper, preprint]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
New p-value in \([0, 1]\). |
required |
Source code in src/online_cp/martingale/legendre.py
online_cp.martingale.VariationalLegendreJumper
¶
Bases: ConformalTestMartingale
Variational Legendre Jumper betting martingale (Algorithm 4).
Runs |K| independent sub-jumpers (each an instance of the SLJ logic), one per polynomial degree. At each step, consensus parameters are computed as the wealth-weighted mean epsilon from each sub-jumper, and the global martingale bets with the Z-normalised product betting function evaluated at these consensus parameters.
Computational cost: O(|K| * g) per step (linear, not exponential).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orders
|
list of int
|
Set K of Legendre polynomial degrees (each >= 1). |
None
|
J
|
float
|
Jump rate in (0, 1]. |
0.01
|
epsilon_grid
|
tuple of float
|
Per-order state space E_k. Default is the paper's 5-point grid. |
STANDARD_GRID
|
Examples:
>>> vlj = VariationalLegendreJumper(orders=[1, 2], J=0.01)
>>> for _ in range(10):
... vlj.update(0.01)
>>> vlj.M > 1.0
True
Source code in src/online_cp/martingale/legendre.py
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | |
update(p: float) -> None
¶
Advance the variational Legendre jumper by one p-value.
Maintains per-sub-jumper consensus parameters \(\bar\epsilon_k\) via a variational update before betting ([LegendreJumper, preprint]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
New p-value in \([0, 1]\). |
required |
Source code in src/online_cp/martingale/legendre.py
online_cp.martingale.CompositeLegendreJumper
¶
Bases: ConformalTestMartingale
Composite Legendre Jumper that averages over multiple jump rates.
Creates multiple instances of a base Legendre Jumper class (one per jumping rate) and computes the martingale as their arithmetic mean. This is the direct analogue of the Composite Jumper for Legendre martingales.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_class
|
class
|
The base martingale class to instantiate. Must accept a |
None
|
J
|
list of float or None
|
List of jumping rates. Default is [1e-4, 1e-3, 1e-2, 1e-1, 1.0]. |
None
|
**kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
Examples:
>>> clj = CompositeLegendreJumper()
>>> for _ in range(5):
... clj.update(0.01)
>>> clj.M > 1.0
True
>>> from online_cp.martingale import VariationalLegendreJumper
>>> clj = CompositeLegendreJumper(
... base_class=VariationalLegendreJumper, orders=[1, 2]
... )
>>> for _ in range(5):
... clj.update(0.01)
>>> clj.M > 1.0
True
Source code in src/online_cp/martingale/legendre.py
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 | |
update(p: float) -> None
¶
Advance every component Legendre jumper and pool them.
Updates each sub-jumper on p and sets the composite log-martingale to
the equal-weight log-mean of the components ([LegendreJumper, preprint]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
New p-value in \([0, 1]\). |
required |
Source code in src/online_cp/martingale/legendre.py
Change-Point Detection Wrappers¶
online_cp.martingale.VilleWrapper
¶
Ville's inequality procedure for change-point detection.
The simplest test based on a conformal test martingale: reject the exchangeability hypothesis when the running maximum of the martingale exceeds a threshold c. By Ville's inequality:
P(∃n : S_n >= c) <= 1/c
So threshold c = 20 gives a 5% significance level, c = 100 gives 1%, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
martingale
|
ConformalTestMartingale
|
The underlying martingale to wrap. |
required |
threshold
|
float
|
Default alarm threshold (default 20, i.e. 5% significance). |
20
|
References
Vovk, Gammerman & Shafer (2022). Algorithmic Learning in a Random World, 2nd edition, §8.4.1 (The Ville Procedure). Cambridge University Press.
Examples:
>>> from online_cp.martingale import SimpleJumper, VilleWrapper
>>> sj = SimpleJumper(J=0.1)
>>> ville = VilleWrapper(sj, threshold=20)
>>> for _ in range(10):
... ville.update(0.5)
>>> bool(ville.rejected)
False
Source code in src/online_cp/martingale/wrappers.py
log_max
property
¶
Log of the running maximum of the martingale.
max
property
¶
Running maximum of the martingale.
rejected
property
¶
Whether the exchangeability hypothesis has been rejected.
rejection_time
property
¶
Step at which the hypothesis was first rejected, or None.
update(p: float) -> None
¶
Update the inner martingale and track the running maximum.
Source code in src/online_cp/martingale/wrappers.py
alarm(threshold=None)
¶
Check whether max(S_n) exceeds the threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float or None
|
Override threshold. If None, uses the threshold set at construction. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the running maximum exceeds the threshold. |
Source code in src/online_cp/martingale/wrappers.py
online_cp.martingale.CUSUMWrapper
¶
CUSUM change-detection wrapper for any conformal test martingale.
Computes the Page CUSUM statistic as the ratio of the current martingale value to its running minimum:
gamma_n = S_n / min_{i <= n} S_i
In log-space: log(gamma_n) = logM_n - min_{i <= n} logM_i
This removes any accumulated "debt" from an initial in-control period, giving faster detection after the change-point. Optionally accepts a linear barrier for controlling the false alarm rate over long horizons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
martingale
|
ConformalTestMartingale
|
The underlying martingale to wrap. |
required |
barrier_slope
|
float or None
|
If not None, the alarm threshold grows linearly as barrier_slope * n. |
None
|
References
Vovk, Gammerman & Shafer (2022). Algorithmic Learning in a Random World, 2nd edition, §8.3. Cambridge University Press.
Examples:
>>> from online_cp.martingale import SimpleJumper, CUSUMWrapper
>>> sj = SimpleJumper(J=0.01)
>>> cusum = CUSUMWrapper(sj)
>>> for _ in range(10):
... cusum.update(0.5)
>>> bool(cusum.gamma >= 1.0) # gamma is always >= 1 (since S_n >= min S_i is not guaranteed)
True
Source code in src/online_cp/martingale/wrappers.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
gamma
property
¶
Current CUSUM statistic.
log_gamma
property
¶
Current log CUSUM statistic.
cusum_values
property
¶
All CUSUM statistic values.
log_cusum_values
property
¶
All log CUSUM statistic values.
update(p: float) -> None
¶
Update the inner martingale and recompute the CUSUM statistic.
Source code in src/online_cp/martingale/wrappers.py
alarm(threshold)
¶
Check whether gamma_n exceeds the threshold (optionally with barrier).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
The alarm threshold. If barrier_slope is set, the effective threshold at step n is threshold + barrier_slope * n. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if gamma_n exceeds the (possibly time-varying) threshold. |
Source code in src/online_cp/martingale/wrappers.py
online_cp.martingale.ShiryaevRobertsWrapper
¶
Shiryaev-Roberts change-detection wrapper for any conformal test martingale.
Computes the Shiryaev-Roberts statistic as:
R_n = sum_{i=1}^{n} S_n / S_i
In log-space: R_n = sum_{i=1}^{n} exp(logM_n - logM_{i-1})
This is always >= the CUSUM statistic (sum >= max), giving a slightly different power/false-alarm trade-off.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
martingale
|
ConformalTestMartingale
|
The underlying martingale to wrap. |
required |
References
Vovk, Gammerman & Shafer (2022). Algorithmic Learning in a Random World, 2nd edition, §8.3. Cambridge University Press.
Examples:
>>> from online_cp.martingale import SimpleJumper, ShiryaevRobertsWrapper
>>> sj = SimpleJumper(J=0.01)
>>> sr = ShiryaevRobertsWrapper(sj)
>>> for _ in range(10):
... sr.update(0.5)
>>> sr.R >= 0
True
Source code in src/online_cp/martingale/wrappers.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
R
property
¶
Current Shiryaev-Roberts statistic.
sr_values
property
¶
All Shiryaev-Roberts statistic values.
__init__(martingale)
¶
Wrap a martingale with the Shiryaev–Roberts statistic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
martingale
|
ConformalTestMartingale
|
The underlying conformal test martingale whose increments drive the Shiryaev–Roberts statistic. |
required |
Source code in src/online_cp/martingale/wrappers.py
update(p: float) -> None
¶
Update the inner martingale and recompute the SR statistic.
Uses the O(1) recursive formula (eq. 8.18 of ALRW2): R_n = (S_n / S_{n-1}) * (R_{n-1} + 1)
Source code in src/online_cp/martingale/wrappers.py
alarm(threshold)
¶
Check whether R_n exceeds the threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
The alarm threshold. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if R_n exceeds the threshold. |
Source code in src/online_cp/martingale/wrappers.py
For betting strategies (density estimators used by martingales), see Betting Strategies.