Skip to content

Piecewise Gaussian (pw_normal)#

ruptures.datasets.pw_normal.pw_normal(n_samples=200, n_bkps=3) #

Return a 2D piecewise Gaussian signal and the associated changepoints.

Parameters:

Name Type Description Default
n_samples int

signal length

200
n_bkps int

number of change points

3

Returns:

Type Description
tuple

signal of shape (n_samples, 2), list of breakpoints

Source code in ruptures/datasets/pw_normal.py
def pw_normal(n_samples=200, n_bkps=3):
    """Return a 2D piecewise Gaussian signal and the associated changepoints.

    Args:
        n_samples (int, optional): signal length
        n_bkps (int, optional): number of change points

    Returns:
        tuple: signal of shape (n_samples, 2), list of breakpoints
    """
    # breakpoints
    bkps = draw_bkps(n_samples, n_bkps)
    # we create the signal
    signal = np.zeros((n_samples, 2), dtype=float)
    cov1 = np.array([[1, 0.9], [0.9, 1]])
    cov2 = np.array([[1, -0.9], [-0.9, 1]])
    for sub, cov in zip(np.split(signal, bkps), cycle((cov1, cov2))):
        n_sub, _ = sub.shape
        sub += rd.multivariate_normal([0, 0], cov, size=n_sub)

    return signal, bkps