Optimally partitioning data into piece-wise linear segments.
Project description
Nunchaku: Optimally partitioning data into piece-wise linear segments
nunchaku
is a statistically rigorous, Bayesian algorithm to infer the optimal partitioning of a data set into contiguous piece-wise linear segments.
Who might find this useful?
Scientists and engineers who are interested in regions where one variable depends linearly on the other within a 2D dataset.
How does it work?
- Given a 2D dataset, it infers the piece-wise linear description that best approximates the dataset.
- It provides statistics for each linear segment, from which users select the segment(s) of most interest.
Installation
Type in Terminal (for Linux/Mac OS users) or Anaconda/Miniconda Prompt (for Windows users):
> pip install nunchaku
For developers, create a virtual environment, install poetry and then install nunchaku
with Poetry:
> git clone https://git.ecdf.ed.ac.uk/s1856140/nunchaku.git
> cd nunchaku
> poetry install --with dev
Quickstart
Data x
is a list or a 1D Numpy array, sorted ascendingly; the data y
is a list or a 1D Numpy array, or a 2D Numpy array with each row being one replicate of the measurement.
Below is a script to analyse the built-in example data.
>>> from nunchaku import Nunchaku, get_example_data
>>> x, y = get_example_data()
>>> # load data and set the prior of the gradient
>>> nc = Nunchaku(x, y, prior=[-5,5])
>>> # compare models with 1, 2, 3 and 4 linear segments
>>> numseg, evidences = nc.get_number(max_num=4)
>>> # get the mean and standard deviation of the boundary points
>>> bds, bds_std = nc.get_iboundaries(numseg)
>>> # get the information of all segments
>>> info_df = nc.get_info(bds)
>>> # plot the data and the segments
>>> nc.plot(info_df)
Documentation
Detailed documentation is available on Readthedocs.
Citation
A preprint on BioRxiv is coming soon.
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
Hashes for nunchaku-0.12.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60ebf96b4abab24ef133ba23a8a1ef3cedb88a485c983267527528356d6ac89a |
|
MD5 | ca662b8c471056f7a1382cef207747b9 |
|
BLAKE2b-256 | 5b9e7435a02e3f36903ce08cdc6602f1be42389904a0674bc612cd06aa59fc71 |