Skip to content

Base classes (ruptures.base)#

All estimators and cost functions are subclasses of.

BaseEstimator and BaseCost respectively.

BaseCost #

Bases: object

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).

Source code in ruptures/base.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class BaseCost(object, metaclass=abc.ABCMeta):
    """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``).
    """

    @abc.abstractmethod
    def fit(self, *args, **kwargs):
        """Set the parameters of the cost function, for instance the Gram
        matrix, etc."""
        pass

    @abc.abstractmethod
    def error(self, start, end):
        """Returns the cost on segment [start:end]."""
        pass

    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

    @property
    @abc.abstractmethod
    def model(self):
        pass

error(start, end) abstractmethod #

Returns the cost on segment [start:end].

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

fit(*args, **kwargs) abstractmethod #

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

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

sum_of_costs(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:

Name Type Description
float

sum of costs

Source code in ruptures/base.py
55
56
57
58
59
60
61
62
63
64
65
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).

Source code in ruptures/base.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class BaseEstimator(metaclass=abc.ABCMeta):
    """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``).
    """

    @abc.abstractmethod
    def fit(self, *args, **kwargs):
        """To call the segmentation algorithm."""
        pass

    @abc.abstractmethod
    def predict(self, *args, **kwargs):
        """To call the segmentation algorithm."""
        pass

    @abc.abstractmethod
    def fit_predict(self, *args, **kwargs):
        """To call the segmentation algorithm."""
        pass

fit(*args, **kwargs) abstractmethod #

To call the segmentation algorithm.

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

fit_predict(*args, **kwargs) abstractmethod #

To call the segmentation algorithm.

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

predict(*args, **kwargs) abstractmethod #

To call the segmentation algorithm.

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