Skip to main content

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?

  1. Given a 2D dataset, it infers the piece-wise linear description that best approximates the dataset.
  2. 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

Our manuscript is still in the peer review process. If you find this useful, please cite this preprint:

Yu Huo, Hongpei Li, Xiao Wang, Xiaochen Du, Peter S. Swain, bioRxiv 2023.05.26.542406; doi: https://doi.org/10.1101/2023.05.26.542406

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nunchaku-0.14.0.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nunchaku-0.14.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file nunchaku-0.14.0.tar.gz.

File metadata

  • Download URL: nunchaku-0.14.0.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.12 Linux/6.4.10-zen1-1-zen

File hashes

Hashes for nunchaku-0.14.0.tar.gz
Algorithm Hash digest
SHA256 26556509a36805107414f73898864ded7f3599ecc2b0143498e49b7a0223f49b
MD5 a8c7e6f5266e7d5b67502c8f56214eed
BLAKE2b-256 61e0bf1c3ab65a0d60d3853aee6cefc9bafd1f0b8dfe26f62f8058670368fbc6

See more details on using hashes here.

File details

Details for the file nunchaku-0.14.0-py3-none-any.whl.

File metadata

  • Download URL: nunchaku-0.14.0-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.12 Linux/6.4.10-zen1-1-zen

File hashes

Hashes for nunchaku-0.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 19e67879b51a0eb7bf63a3d3bdbf9cbb0647302ffce112a4b12dd6beb6d3f68b
MD5 392815b165272866baa1c08c5e048682
BLAKE2b-256 bb20fdc4ca049e9e2d3f55f3fb42c390db2fab1822f775d2ea4e91a66416b084

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page