With pip3 from terminal:
$ pip3 install ruptures.
Or download the source codes from latest release and run the following lines from inside the folder
$ python3 setup.py install or
$ python3 setup.py develop.
This section explains how to use implemented algorithms.
ruptures has an object-oriented modelling approach: change point detection algorithms are
broken down into two conceptual objects that inherits from base classes:
Initializing a new estimator¶
Each change point detection algorithm inherits from the base class
When a class that inherits from the base estimator is created, the
.__init__() method initializes
an estimator with the following arguments:
'model': “l1”, “l2”, “normal”, “rbf”, “linear”, “ar”. Cost function to use to compute the approximation error.
'cost': a custom cost function to the detection algorithm. Should be a
'jump': reduce the set of possible change point indexes; predicted change points can only be a multiple of
'min_size': minimum number of samples between two change points.
Making a prediction¶
The main methods are
.fit(): generally takes a signal as input and fit the algorithm on the data
.predict(): performs the change point detection. This method returns a list of indexes corresponding to the end of each regimes. By design, the last element of this list is the number of samples.
.fit_predict(): helper method which calls
Creating a new cost function¶
In order to define custom cost functions, simply create a class that inherits from
ruptures.base.BaseCost and implement the methods
- The method
.fit(signal)takes a signal as input and sets parameters. It returns
- The method
.error(start, end)takes two indexes
'end'and returns the cost on the segment start:end.
An example can be found in Custom cost class.