bclr - Bayesian changepoint detection via Logistic Regression
Project description
BCLR
A package for Bayesian Changepoint detection via Logistic Regression.
These methods were developed in Thomas, Jauch, and Matteson (2025).
Installation
To install the package, is to install from PyPI via the code:
$ pip install bclr
Alternatively, if you would like to install the source code, you can clone the repository and then install via pip (Linux/Mac):
$ git clone https://github.com/manilasoldier/bclr.git
$ cd bclr
$ pip install .
or run
$ pip install git+https://github.com/manilasoldier/bclr.git
Running the code
import bclr
import numpy as np
np.random.seed(800037)
a1 = np.random.standard_t(10, size=(320, 6))
a2 = np.random.standard_t(1.5, size=(480, 6))
# "Gaussian" type embedding
Xs = np.exp(-np.r_[a1, a2]**2)
Let's first investigate the single changepoint setup, before moving the multiple one.
First, let's specify a prior for the $\beta$ coefficients (we need to provide a mean and covariance for the single changepoint setup).
Single changepoint setup
rng1 = np.random.default_rng(800037) #for reproducibility
prior_covS = np.diag(np.repeat(3, 6))
prior_mean = np.repeat(0, 6)
bclrS = bclr.BayesCC(X = Xs, prior_mean = prior_mean, prior_cov = prior_covS,
n_iter = 2000)
bclrS.fit(rng = rng1)
bclrS.transform(verbose=False)
bclrS.plot_k()
Multiple changepoint setup
Now we consider the multiple changepoint setup and the whole series $X$, where specify $J = 10$ (i.e. cps=10).
Then, we will go ahead and fit bclr to the data and estimate (predict) the changes.
Note: there is no need to specify a prior_mean for the multiple changepoint setup.
np.random.seed(199203)
b1 = np.random.randn(100, 10)
b2 = np.random.randn(80, 10) + np.broadcast_to(np.random.randn(10), (80, 10))
b3 = np.random.randn(140, 10) + np.broadcast_to(np.random.randn(10), (140, 10))
b4 = np.random.randn(80, 10) + np.broadcast_to(np.random.randn(10), (80, 10))
Xm = np.r_[b1, b2, b3, b4]
rng2 = np.random.default_rng(199203) #for reproducibility
prior_covM = np.diag(np.repeat(3, 10))
bclrM = bclr.MultiBayesCC(X = Xm, cps = 10, prior_cov = prior_covM,
rng = rng2, warnings=False)
cps = bclrM.fit_predict()
Now we can look at
- where the changes are estimated to be located,
- the posterior probability of the estimates, and
- the normalized entropy of the segment distribution.
print(cps)
Location Posterior Probability Normalized Entropy
0 99.0 0.946 0.047544
1 180.0 1.000 0.000000
2 320.0 0.996 0.005354
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bclr-0.3.2.tar.gz.
File metadata
- Download URL: bclr-0.3.2.tar.gz
- Upload date:
- Size: 38.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e70fc6a949fc2bd683e7573391cf957c603df734a7aa05ede8efe74f0b3c9f9c
|
|
| MD5 |
ccde6c26a33e3a3f44c8a20636d3a0ee
|
|
| BLAKE2b-256 |
5b68cf007020a13e027a625f0d1210a73f6ad547659350e656f46377a8f56b05
|
File details
Details for the file bclr-0.3.2-py3-none-any.whl.
File metadata
- Download URL: bclr-0.3.2-py3-none-any.whl
- Upload date:
- Size: 33.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c1009eeec49c0eafce432e02e6154fb60f24c3c98d0a00fcd4c337c08bb0d27
|
|
| MD5 |
9d0aed99347f671d7598b04294ec5204
|
|
| BLAKE2b-256 |
1ef88f85b8c48255b8e286c3f43a03be03795146dff617c5cc9e99c5df49795b
|