/linear_segment

Segmentation of linear data

Primary LanguageCGNU General Public License v2.0GPL-2.0

Linear Segmentation

Build Status PyPI version Coffee

linear_segmentation using Bayesian Change Point Segmentation or Circular Binary segmentation.

Install

If you dont already have numpy and scipy installed, it is best to download Anaconda, a python distribution that has them included.

    https://continuum.io/downloads

Dependencies can be installed by:

    pip install -r requirements.txt

PyPI install, presuming you have all its requirements installed:

	pip install linear_segment

Usage

from linear_segment import segment
import numpy as np

# Create data
np.random.seed(10)
T = 50
x = np.zeros(T)
x[10:20] = 1.0
x[30:40] = 1.0

labels = np.repeat("a", T)   # "a" is a dummy label

# Calculate segments
segments = segment(x, labels, method="online_both", cutoff=0.3, offset=5)
print(segments)

LabeledIntervalArray
   (0-10, a)
   (10-20, a)
   (20-30, a)
   (30-40, a)
   (40-50, a)
segments = segment(x, labels, method="cbs", shuffles=200, p=0.05)
print(segments)

LabeledIntervalArray
   (0-10, a)
   (10-20, a)
   (20-30, a)
   (30-40, a)
   (40-50, a)