Skip to content

Base classes (ruptures.base)#

All estimators and cost functions are subclasses of BaseEstimator and BaseCost respectively.

BaseCost #

Base class for all segment cost classes.

Notes

All classes should specify all the parameters that can be set at the class level in their __init__ as explicit keyword arguments (no *args or **kwargs).

error(self, start, end) #

Returns the cost on segment [start:end].

Source code in ruptures/base.py
@abc.abstractmethod
def error(self, start, end):
    """Returns the cost on segment [start:end]."""
    pass

fit(self, *args, **kwargs) #

Set the parameters of the cost function, for instance the Gram matrix, etc.

Source code in ruptures/base.py
@abc.abstractmethod
def fit(self, *args, **kwargs):
    """Set the parameters of the cost function, for instance the Gram
    matrix, etc."""
    pass

sum_of_costs(self, bkps) #

Returns the sum of segments cost for the given segmentation.

Parameters:

Name Type Description Default
bkps list

list of change points. By convention, bkps[-1]==n_samples.

required

Returns:

Type Description
float

sum of costs

Source code in ruptures/base.py
def sum_of_costs(self, bkps):
    """Returns the sum of segments cost for the given segmentation.

    Args:
        bkps (list): list of change points. By convention, bkps[-1]==n_samples.

    Returns:
        float: sum of costs
    """
    soc = sum(self.error(start, end) for start, end in pairwise([0] + bkps))
    return soc

BaseEstimator #

Base class for all change point detection estimators.

Notes

All estimators should specify all the parameters that can be set at the class level in their __init__ as explicit keyword arguments (no *args or **kwargs).

fit(self, *args, **kwargs) #

To call the segmentation algorithm.

Source code in ruptures/base.py
@abc.abstractmethod
def fit(self, *args, **kwargs):
    """To call the segmentation algorithm."""
    pass

fit_predict(self, *args, **kwargs) #

To call the segmentation algorithm.

Source code in ruptures/base.py
@abc.abstractmethod
def fit_predict(self, *args, **kwargs):
    """To call the segmentation algorithm."""
    pass

predict(self, *args, **kwargs) #

To call the segmentation algorithm.

Source code in ruptures/base.py
@abc.abstractmethod
def predict(self, *args, **kwargs):
    """To call the segmentation algorithm."""
    pass