Methods to get the probability of a changepoint in a time series.

Overview

Bayesian Changepoint Detection

Methods to get the probability of a changepoint in a time series. Both online and offline methods are available. Read the following papers to really understand the methods:

[1] Paul Fearnhead, Exact and Efficient Bayesian Inference for Multiple
Changepoint problems, Statistics and computing 16.2 (2006), pp. 203--213

[2] Ryan P. Adams, David J.C. MacKay, Bayesian Online Changepoint Detection,
arXiv 0710.3742 (2007)

[3] Xuan Xiang, Kevin Murphy, Modeling Changing Dependency Structure in
Multivariate Time Series, ICML (2007), pp. 1055--1062

To see it in action have a look at the example notebook.

Comments
  • Other observation models besides Gaussian

    Other observation models besides Gaussian

    Hi. I was wondering if you had any insight in extending your code to include other emission models besides gaussian. In particular, how about a GMM with known number of gaussians?

    I was going to take a stab at implementing it and submit a PR, but wanted to get your input first.

    Thanks

    Dan

    enhancement 
    opened by mathDR 16
  • CD automation for deployment to PyPI

    CD automation for deployment to PyPI

    What is this feature about? CD for deploying package to PyPI. It makes use of Github's workflow.

    Closes Issues: https://github.com/hildensia/bayesian_changepoint_detection/issues/32

    Pre-req for owner @hildensia before merging this :

    1. Create a new API tokens inside your PyPI account where this project lives https://pypi.org/
    2. Creating two Repository secrets inside the github project setting. (Steps defined here) A. Secret name PYPI_USERNAME which value __token__
      B. Secret name PYPI_PROD_PASSWORD with the token value from step #1

    How to release a package? Leveraging github release feature This can only be done by project admin/maintainer. @hildensia Right now have made the release to based on manual action. We have to make use the of Releases option shown by github, provide a version tag number and description. If we want to change the release strategy we can update the cd.yml accordingly but usually I have seen projects follow manual release.

    What Testing was done? I have tested this pipeline where the package was deployed to my Test PyPI account. https://github.com/zillow/bayesian_changepoint_detection/actions/runs/1966108484

    opened by shahsmit14 12
  • Add pyx file again

    Add pyx file again

    Was removed during a PR. Is there a good way to keep cython and python in sync. I'm not sure if I prefer one over the other (python is better for debugging, cython is faster).

    opened by hildensia 5
  • How to utilize R matrix to detect change points?

    How to utilize R matrix to detect change points?

    In the current version of code, Nw=10; ax.plot(R[Nw,Nw:-1]) is used to exhibit the changpoints. Although it works fine, I am really confused about the moral behind it. I tried to plot the run length with maximum prob in each time step i.e. the y index of maximum prob in each x col, but the result showed the run length keeps going up... I also went back to Admas's paper but found nothing about change point indentification stuff (he just stop at R matrix)... I also tried to find Adams's MATLAB code, but the code seems to have been removed...

    I am trying to use this method in my work, and I believe it's the best to fully understand it before any deployment. Any help will be appreciated and thanks a lot!

    opened by mike-ocean 4
  • Corrected scale and beta factor calculation

    Corrected scale and beta factor calculation

    The scale factor should be the standard deviation. There was a small bug in the betaT0 calculation, this makes it consistent with the paper/gaussdemo.m file.

    opened by nariox 3
  • Example notebook does not work

    Example notebook does not work

    If I click on the "example notebook" work - an nbviewer link - I get a "too many redirects" error.

    It would be nice if the example notebook was easily accessible in the repo (maybe I overlooked it... ) because we don't need a live notebook / nbviewer to figure out whether the example fits our use case.

    opened by chryss 2
  • Updating parameters for bayesian online change point

    Updating parameters for bayesian online change point

    I think my question is related to the one, which was not answered and is already closed: https://github.com/hildensia/bayesian_changepoint_detection/issues/19

    In your example, you have applied the student t-distribution as a likelihood. I understand the distribution, its parameters, but I have a question about how you set up prior and update its parameters in the code. So the following is:

    df = 2*self.alpha
    scale = np.sqrt(self.beta * (self.kappa+1) / (self.alpha * self.kappa))
    

    I don't understand what alpha, beta and kappa correspond to. How have you come across this expression? The paper by Adams and McKey refers to updating sufficient statistics. Is your expression related to that? If so, how can I do that for any other distribution, let's say gaussian? In my comment, I refer to the following formula in the paper:

    equation

    opened by celdorwow 2
  • Scipy Import Error on newer versions

    Scipy Import Error on newer versions

    Hi guys,

    there is an import issue if one uses newer scipy versions.

    Would be a quick fix if you adapt the import statement at offline_changepoint_detection.py

    try:  # SciPy >= 0.19
        from scipy.special import comb, logsumexp
    except ImportError:
        from scipy.misc import comb, logsumexp  # noqa
    
    opened by fhaselbeck 2
  • Multivariate T

    Multivariate T

    • Introduces a pluggable prior/posterior config for multivariate Gaussian data, with sensible defaults. Note that this only works for scipy > 1.6.0, where they introduced the multivariate t PDF. The library will remind you to upgrade if you have an old version.
    • Adds a test for this new configuration, as well as for the univariate one
    • Adds a "dev" and "multivariate" setup extra, meaning that you can pip install bayesian_changepoint_detection[dev] for development work (currently this installs pytest), or pip install bayesian_changepoint_detection[multivariate] (enforces that you have a new enough scipy version for this new feature)
    opened by multimeric 2
  • Why the probability exceeds one?

    Why the probability exceeds one?

    I ran the given online detection example in the notebook, and I assumed the y axis indicating the probability of changepoint (am I right?). But the y value ranged from zero to hundreds. I am not very familiar with the math, so can anyone please explain this outcome?

    Thanks.

    opened by mike-ocean 2
  • Fix full covariance method and add example

    Fix full covariance method and add example

    This fixes the full cov method and adds an example similar to the original ipython notebook. If you prefer, I can merge them separately, but since they are related, I thought it'd be fine to merge them together.

    opened by nariox 2
  • About the conditions to use bocpd

    About the conditions to use bocpd

    Hi,nice to meet you,and i want to aks a basic question,if i don’t know the distribution of data(not the normal distribution),then could i use the bocpd? Thank you!

    opened by Codergers 0
  • Scaling of Data

    Scaling of Data

    Hi, I've noticed is the scaling of the data can have an effect on the result, but I am not sure why it would and can't find any reason for it in the code or references. Below I have the CP probabilities for the same data with or without a constant factor, which are somewhat different.

    Are there some assumptions about the input data I am missing? Thanks

    image image

    opened by stefan37 3
  • How to adjust the sensitivity of the BOCD algorithm?

    How to adjust the sensitivity of the BOCD algorithm?

    There is always a tradeoff between false alarms and missed alarms, and when the algorithm is more sensitive we should have higher false alarm rate and lower missed alarm rate. My question is, is it possible to adjust the sensitivity level of this algorithm by changing the hyperparameter (e.g., alpha, beta, kappa, mu)? Thank you!

    opened by gqffqggqf 4
  • 'FloatingPointError: underflow encountered in logaddexp'  occurs when setting np.seterr(all='raise')

    'FloatingPointError: underflow encountered in logaddexp' occurs when setting np.seterr(all='raise')

    Hi,

    I installed bayesian_changepoint_detection from this github repository.

    By setting (accidentally) np.seterr(all='raise'), I was able to cause the following exception.

    I am not sure whether this would have any relevance for the further processing, but I just wanted to draw attention to people working on / with this library.

    /home/user/venv/env01/bin/python3.6 /home/user/PycharmProjects/project01/snippet.py
    Use scipy logsumexp().
    Traceback (most recent call last):
      File "/home/user/PycharmProjects/project01/snippet.py", line 68, in <module>
        Q, P, Pcp = offcd.offline_changepoint_detection(data, partial(offcd.const_prior, l=(len(data) + 1)), offcd.gaussian_obs_log_likelihood, truncate=-40)
      File "/home/user/experiments/original-unforked/bayesian_changepoint_detection/bayesian_changepoint_detection/offline_changepoint_detection.py", line 98, in offline_changepoint_detection
        Q[t] = np.logaddexp(P_next_cp, P[t, n-1] + antiG)
    FloatingPointError: underflow encountered in logaddexp
    
    Process finished with exit code 1
    
    
    opened by alatif-alatif 0
  • Added Normal known precision, Poisson distributions + alternate hazard function

    Added Normal known precision, Poisson distributions + alternate hazard function

    For someone whoever is interested, I have added Normal known precision, poisson distributions in my fork below. Also tried adding another type of hazard function which is normally distributed over time. Usage of the same is updated in Example code as well. Find my fork here - https://github.com/kmsravindra/bayesian_changepoint_detection

    opened by kmsravindra 2
  • Confused about the R matrix interpretation

    Confused about the R matrix interpretation

    Hi,

    I am confused about the returned R matrix interpretation in the online detection algorithm. In the notebook example, the third plot is R[Nw,Nw:-1], where it is mentioned to be "the probability at each time step for a sequence length of 0, i.e. the probability of the current time step to be a changepoint." So why do we choose the indices R[Nw,Nw:-1] ? why not R[Nw,:]

    Also, it was mentioned as an example that R[7,3] means the probability at time step 7 taking a sequence of length 3, so does R[Nw,Nw:-1] means that we are taking all the probabilities at time step Nw ?

    Any suggestions to help me to understand the output R ?

    Thanks

    opened by RanaElnaggar 4
Releases(v0.4)
Owner
Johannes Kulick
Machine Learning and Robotics Scientist
Johannes Kulick
Finite difference solution of 2D Poisson equation. Can handle Dirichlet, Neumann and mixed boundary conditions.

Poisson-solver-2D Finite difference solution of 2D Poisson equation Current version can handle Dirichlet, Neumann, and mixed (combination of Dirichlet

Mohammad Asif Zaman 34 Dec 23, 2022
Codes for our paper "SentiLARE: Sentiment-Aware Language Representation Learning with Linguistic Knowledge" (EMNLP 2020)

SentiLARE: Sentiment-Aware Language Representation Learning with Linguistic Knowledge Introduction SentiLARE is a sentiment-aware pre-trained language

74 Dec 30, 2022
Adversarial Graph Augmentation to Improve Graph Contrastive Learning

ADGCL : Adversarial Graph Augmentation to Improve Graph Contrastive Learning Introduction This repo contains the Pytorch [1] implementation of Adversa

susheel suresh 62 Nov 19, 2022
Convert onnx models to pytorch.

onnx2torch onnx2torch is an ONNX to PyTorch converter. Our converter: Is easy to use – Convert the ONNX model with the function call convert; Is easy

ENOT 264 Dec 30, 2022
An unofficial implementation of "Unpaired Image Super-Resolution using Pseudo-Supervision." CVPR2020

UnpairedSR An unofficial implementation of "Unpaired Image Super-Resolution using Pseudo-Supervision." CVPR2020 turn RCAN(modified) -- xmodel(xilinx

JiaKui Hu 10 Oct 28, 2022
A toy compiler that can convert Python scripts to pickle bytecode 🥒

Pickora 🐰 A small compiler that can convert Python scripts to pickle bytecode. Requirements Python 3.8+ No third-party modules are required. Usage us

ꌗᖘ꒒ꀤ꓄꒒ꀤꈤꍟ 68 Jan 04, 2023
LibMTL: A PyTorch Library for Multi-Task Learning

LibMTL LibMTL is an open-source library built on PyTorch for Multi-Task Learning (MTL). See the latest documentation for detailed introductions and AP

765 Jan 06, 2023
Alpha-IoU: A Family of Power Intersection over Union Losses for Bounding Box Regression

Alpha-IoU: A Family of Power Intersection over Union Losses for Bounding Box Regression YOLOv5 with alpha-IoU losses implemented in PyTorch. Example r

Jacobi(Jiabo He) 147 Dec 05, 2022
Dirty Pixels: Towards End-to-End Image Processing and Perception

Dirty Pixels: Towards End-to-End Image Processing and Perception This repository contains the code for the paper Dirty Pixels: Towards End-to-End Imag

50 Nov 18, 2022
How to train a CNN to 99% accuracy on MNIST in less than a second on a laptop

Training a NN to 99% accuracy on MNIST in 0.76 seconds A quick study on how fast you can reach 99% accuracy on MNIST with a single laptop. Our answer

Tuomas Oikarinen 42 Dec 10, 2022
Code for our ALiBi method for transformer language models.

Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation This repository contains the code and models for our paper Tra

Ofir Press 211 Dec 31, 2022
The official repository for Deep Image Matting with Flexible Guidance Input

FGI-Matting The official repository for Deep Image Matting with Flexible Guidance Input. Paper: https://arxiv.org/abs/2110.10898 Requirements easydict

Hang Cheng 51 Nov 10, 2022
DCT-Mask: Discrete Cosine Transform Mask Representation for Instance Segmentation

DCT-Mask: Discrete Cosine Transform Mask Representation for Instance Segmentation This project hosts the code for implementing the DCT-MASK algorithms

Alibaba Cloud 57 Nov 27, 2022
Structure Information is the Key: Self-Attention RoI Feature Extractor in 3D Object Detection

Structure Information is the Key: Self-Attention RoI Feature Extractor in 3D Object Detection abstract:Unlike 2D object detection where all RoI featur

DK. Zhang 2 Oct 07, 2022
Using Convolutional Neural Networks (CNN) for Semantic Segmentation of Breast Cancer Lesions (BRCA)

Using Convolutional Neural Networks (CNN) for Semantic Segmentation of Breast Cancer Lesions (BRCA). Master's thesis documents. Bibliography, experiments and reports.

Erick Cobos 73 Dec 04, 2022
Release of the ConditionalQA dataset

ConditionalQA Datasets accompanying the paper ConditionalQA: A Complex Reading Comprehension Dataset with Conditional Answers. Disclaimer This dataset

14 Oct 17, 2022
Codebase for the Summary Loop paper at ACL2020

Summary Loop This repository contains the code for ACL2020 paper: The Summary Loop: Learning to Write Abstractive Summaries Without Examples. Training

Canny Lab @ The University of California, Berkeley 44 Nov 04, 2022
[NeurIPS 2021] “Improving Contrastive Learning on Imbalanced Data via Open-World Sampling”,

Improving Contrastive Learning on Imbalanced Data via Open-World Sampling Introduction Contrastive learning approaches have achieved great success in

VITA 24 Dec 17, 2022
CDTrans: Cross-domain Transformer for Unsupervised Domain Adaptation

CDTrans: Cross-domain Transformer for Unsupervised Domain Adaptation [arxiv] This is the official repository for CDTrans: Cross-domain Transformer for

238 Dec 22, 2022
Python package for visualizing the loss landscape of parameterized quantum algorithms.

orqviz A Python package for easily visualizing the loss landscape of Variational Quantum Algorithms by Zapata Computing Inc. orqviz provides a collect

Zapata Computing, Inc. 75 Dec 30, 2022