How to use the ruptures.Pelt 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 openpowerquality / opq / mauka / analysis.py View on Github external
def segment_array(data: np.ndarray) -> List[np.ndarray]:
    """
    Split up data into segments.
    :param data:
    :return:
    """

    if data is None or len(data) == 0:
        return []

    if len(data) == 1:
        return [np.array([1])]

    try:
        algo = rpt.Pelt().fit(data)
        segment_idxs = algo.predict(pen=1)

        segments: List[np.ndarray] = []
        start = 0
        for idx in segment_idxs:
            segments.append(data[start:idx])
            start = idx

        return segments
    except Exception as e:
        logging.error(str(e))
        return []
github ModelOriented / SAFE / SafeTransformer / SafeTransformer.py View on Github external
def fit(self, model, X, verbose):
		if verbose:
			print('Fitting variable:' + str(self.original_name))
		pdp, axis = self._get_partial_dependence(model, X, grid_resolution=1000)
		algo = rpt.Pelt(model=self.pelt_model).fit(pdp)
		self.changepoints = algo.predict(pen=self.penalty)
		self.changepoint_values = [axis[i] for i in self.changepoints[:-1]]
		changepoint_names = ['%.2f' % self.changepoint_values[i]
		    for i in range(len(self.changepoint_values))] + ['Inf']
		self.new_names = [str(self.original_name) + "_[" + changepoint_names[i] + ", " +
			changepoint_names[i + 1] + ")" for i in range(len(changepoint_names) - 1)]
		return self