How to use the ruptures.base.BaseEstimator function in ruptures

To help you get started, we’ve selected a few ruptures examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github deepcharles / ruptures / ruptures / dynamic_programming / dynamic_programming.py View on Github external
tmp_err = err_func(start, tmp_bkp)
                tmp = dynamic_prog(
                    err_func, d - 1, tmp_bkp, end, jump, min_size)
                tmp_min = sum(tmp.values()) + tmp_err
                if current_min is None:
                    current_min = tmp_min
                    current_breaks = tmp.copy()
                    current_breaks.update({(start, tmp_bkp): tmp_err})
                elif tmp_min < current_min:
                    current_min = tmp_min
                    current_breaks = tmp.copy()
                    current_breaks.update({(start, tmp_bkp): tmp_err})
        return current_breaks


class dynp(BaseEstimator):
    """Wrapper qui sera utilisé pour appeler la fonction dynamic_prog.
    Tous les paramètres sont définis dans __init__ et la méthode fit
    calcule la segmentation et renvoie les temps de ruptures."""

    def __init__(self, error_func, n, n_regimes, min_size=2, jump=1):
        self.error_func = error_func
        assert isinstance(n, int)
        assert n > n_regimes  # at least three points
        self.n = n
        self.n_regimes = n_regimes
        assert min_size > 0
        self.min_size = min_size
        self.jump = jump
        self.chg = list()  # will contain the changepoint indexes.

    def fit(self):
github deepcharles / ruptures / ruptures / detection / dynp.py View on Github external
Code explanation
----------------------------------------------------------------------------------------------------
.. autoclass:: ruptures.detection.Dynp
    :members:
    :special-members: __init__

"""
from functools import lru_cache

from ruptures.utils import sanity_check
from ruptures.costs import cost_factory
from ruptures.base import BaseCost, BaseEstimator


class Dynp(BaseEstimator):

    """ Find optimal change points using dynamic programming.

    Given a segment model, it computes the best partition for which the sum of errors is minimum.

    """

    def __init__(self, model="l2", custom_cost=None, min_size=2, jump=5, params=None):
        """Creates a Dynp instance.

        Args:
            model (str, optional): segment model, ["l1", "l2", "rbf"]. Not used if ``'custom_cost'`` is not None.
            custom_cost (BaseCost, optional): custom cost function. Defaults to None.
            min_size (int, optional): minimum segment length.
            jump (int, optional): subsample (one every *jump* points).
            params (dict, optional): a dictionary of parameters for the cost instance.
github deepcharles / ruptures / ruptures / detection / bottomup.py View on Github external
.. bibliography:: ../biblio.bib
    :style: alpha
    :cited:
    :labelprefix: BU
    :keyprefix: bu-

"""
from functools import lru_cache

from ruptures.base import BaseCost, BaseEstimator
from ruptures.costs import cost_factory

from ruptures.utils import Bnode, pairwise


class BottomUp(BaseEstimator):

    """Bottom-up segmentation."""

    def __init__(self, model="l2", custom_cost=None, min_size=2, jump=5, params=None):
        """Initialize a BottomUp instance.


        Args:
            model (str, optional): segment model, ["l1", "l2", "rbf"]. Not used if ``'custom_cost'`` is not None.
            custom_cost (BaseCost, optional): custom cost function. Defaults to None.
            min_size (int, optional): minimum segment length. Defaults to 2 samples.
            jump (int, optional): subsample (one every *jump* points). Defaults to 5 samples.
            params (dict, optional): a dictionary of parameters for the cost instance.

        Returns:
            self
github deepcharles / ruptures / ruptures / detection / omp.py View on Github external
Orthogonal matching pursuit for changepoint detection.

Fast but approximate.

Euclidean norm.

"""
import numpy as np
from numpy.linalg import norm

from ruptures.utils import pairwise
from ruptures.base import BaseEstimator


class Omp(BaseEstimator):

    """Contient l'algorithme de parcours des partitions."""

    def __init__(self, min_size=2, jump=5):
        """Initialize an Omp instance

        Args:
            min_size (int, optional): minimum segment length. Defaults to 2 samples.
            jump (int, optional): subsample (one every "jump" points). Defaults to 5 samples.

        Returns:
            self
        """
        self.min_size = min_size  # not used
        self.jump = jump  # not used
        self.n_samples = None
github deepcharles / ruptures / ruptures / detection / window.py View on Github external
.. autoclass:: ruptures.detection.Window
    :members:
    :special-members: __init__

"""


import numpy as np
from scipy.signal import argrelmax

from ruptures.base import BaseCost, BaseEstimator
from ruptures.costs import cost_factory
from ruptures.utils import unzip


class Window(BaseEstimator):

    """Window sliding method."""

    def __init__(self, width=100, model="l2", custom_cost=None, min_size=2, jump=5, params=None):
        """Instanciate with window length.

        Args:
            width (int, optional): window length. Defaults to 100 samples.
            model (str, optional): segment model, ["l1", "l2", "rbf"]. Not used if
            ``'custom_cost'`` is not None.
            custom_cost (BaseCost, optional): custom cost function. Defaults to None.
            min_size (int, optional): minimum segment length.
            jump (int, optional): subsample (one every *jump* points).
            params (dict, optional): a dictionary of parameters for the cost instance.

        Returns:
github deepcharles / ruptures / ruptures / detection / binseg.py View on Github external
.. rubric:: References

.. bibliography:: ../biblio.bib
    :style: alpha
    :cited:
    :labelprefix: BS
    :keyprefix: bs-

"""
from functools import lru_cache
from ruptures.base import BaseCost, BaseEstimator
from ruptures.costs import cost_factory
from ruptures.utils import pairwise


class Binseg(BaseEstimator):

    """Binary segmentation."""

    def __init__(self, model="l2", custom_cost=None, min_size=2, jump=5, params=None):
        """Initialize a Binseg instance.

        Args:
            model (str, optional): segment model, ["l1", "l2", "rbf",...]. Not used if ``'custom_cost'`` is not None.
            custom_cost (BaseCost, optional): custom cost function. Defaults to None.
            min_size (int, optional): minimum segment length. Defaults to 2 samples.
            jump (int, optional): subsample (one every *jump* points). Defaults to 5 samples.
            params (dict, optional): a dictionary of parameters for the cost instance.


        Returns:
            self
github deepcharles / ruptures / ruptures / detection / pelt.py View on Github external
.. rubric:: References

.. bibliography:: ../biblio.bib
    :style: alpha
    :cited:
    :labelprefix: B
    :keyprefix: b-
"""
from math import floor

from ruptures.costs import cost_factory
from ruptures.base import BaseCost, BaseEstimator


class Pelt(BaseEstimator):

    """Penalized change point detection.

    For a given model and penalty level, computes the segmentation which minimizes the constrained
    sum of approximation errors.

    """

    def __init__(self, model="l2", custom_cost=None, min_size=2, jump=5, params=None):
        """Initialize a Pelt instance.

        Args:
            model (str, optional): segment model, ["l1", "l2", "rbf"]. Not used if ``'custom_cost'`` is not None.
            custom_cost (BaseCost, optional): custom cost function. Defaults to None.
            min_size (int, optional): minimum segment length.
            jump (int, optional): subsample (one every *jump* points).