Skip to content

An implementation of Adams & MacKay 2007 "Bayesian Online Changepoint Detection" for a binomial input

License

Notifications You must be signed in to change notification settings

laurentperrinet/bayesianchangepoint

 
 

Repository files navigation

Binder

bayesianchangepoint

An implementation of Adams & MacKay 2007 "Bayesian Online Changepoint Detection" for a binomial input. In pure Python.

@TECHREPORT{ adams-mackay-2007,
AUTHOR = {Ryan Prescott Adams and David J.C. MacKay},
TITLE  = "{B}ayesian Online Changepoint Detection",
INSTITUTION = "University of Cambridge",
ADDRESS = "Cambridge, UK",
YEAR = "2007",
NOTE = "arXiv:0710.3742v1 [stat.ML]",
URL = "http://arxiv.org/abs/0710.3742"
}

In a nutshell, you observe a sequence of binary trials (ON/OFF, Left/Right, 0/1, ...), which have an underlying structure for their cause:

BSM

The goal is to retrieve the moments of the switches which define epochs and the values of the probability biases within each epoch:

BBCP

try it out!

@article{PasturelMontagniniPerrinet20,
    title = {Humans adapt their anticipatory eye movements to the volatility of visual motion properties},
    journal = {PLoS Computational Biology},
    author = {Pasturel, Chloé and Montagnini, Anna and Perrinet, Laurent U},
    date = {2020-01-26},
    doi = {10.1101/784116},
    keywords = {motion anticipation},
    preprint = {https://www.biorxiv.org/content/10.1101/784116v3},
    url = {https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1007438},
    url_code = {https://github.com/laurentperrinet/PasturelMontagniniPerrinet2020},
    url_pdf = {https://www.biorxiv.org/content/biorxiv/early/2019/09/26/784116.full-text.pdf},
    year = {2020}
}

algorithm

  1. Initialize
  • $P(r_0)= S(r)$ or $P(r_0=0)=1$ and
  • $ν^{(0)}1 = ν{prior}$ and $χ^{(0)}1 = χ{prior}$
  1. Observe New Datum $x_t$
  2. Evaluate Predictive Probability $π_{1:t} = P(x |ν^{(r)}_t,χ^{(r)}_t)$
  3. Calculate Growth Probabilities $P(r_t=r_{t-1}+1, x_{1:t}) = P(r_{t-1}, x_{1:t-1}) π^{(r)}t (1−H(r^{(r)}{t-1}))$
  4. Calculate Changepoint Probabilities $P(r_t=0, x_{1:t})= \sum_{r_{t-1}} P(r_{t-1}, x_{1:t-1}) π^{(r)}t H(r^{(r)}{t-1})$
  5. Calculate Evidence $P(x_{1:t}) = \sum_{r_{t-1}} P (r_t, x_{1:t})$
  6. Determine Run Length Distribution $P (r_t | x_{1:t}) = P (r_t, x_{1:t})/P (x_{1:t}) $
  7. Update Sufficient Statistics :
  • $ν^{(0)}{t+1} = ν{prior}$, $χ^{(0)}{t+1} = χ{prior}$
  • $ν^{(r+1)}{t+1} = ν^{(r)}{t} +1$, $χ^{(r+1)}{t+1} = χ^{(r)}{t} + u(x_t)$
  1. Perform Prediction $P (x_{t+1} | x_{1:t}) = P (x_{t+1}|x_{1:t} , r_t) P (r_t|x_{1:t})$
  2. go to (2)

other applications

An application is to analyze long sequences of binary events, such as detailed in the following example:

Trump Tweets

credits

About

An implementation of Adams & MacKay 2007 "Bayesian Online Changepoint Detection" for a binomial input

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 99.9%
  • Python 0.1%