How to use the ruptures.utils.admissible_filter 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 / search_methods / binseg.py View on Github external
def single_bkp(self, start, end):
        """Return the optimal breakpoint of [start:end] (if it exists)."""
        filtre = admissible_filter(start, end, self.jump, self.min_size)

        subsignal = self.signal[
            start:end] - self.signal[start:end].mean(axis=0)
        objective = np.sum(subsignal.cumsum(axis=0)**2, axis=1)
        sub_sampling = ((ind, val) for ind, val in enumerate(objective, start=start + 1)
                        if filtre(ind))
        try:
            bkp, _ = max(sub_sampling, key=lambda x: x[1])
        except ValueError:  # if empty sub_sampling
            return None, 0
        gain = self.cost.error(start, end)
        gain -= self.cost.error(start, bkp) + self.cost.error(bkp, end)
        return bkp, gain