Skip to content

Identifying the direction of change #281

Answered by deepcharles
Meligui asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, thanks for your interest in ruptures.

It is not coded in the library by it can easily be done:

import ruptures as rpt

def triplewise(iterable):
    "Return overlapping triplets from an iterable"
    # triplewise('ABCDEFG') --> ABC BCD CDE DEF EFG
    for (a, _), (b, c) in rpt.pairwise(rpt.pairwise(iterable)):
        yield a, b, c

# assume a variable `signal` and a list of change-points `bkps`
for (left, mid, right) in triplewise([0] + bkps):
    left_mean = signal[left:mid].mean()
    right_mean = signal[mid:right].mean()
    if left_mean > right_mean:
        print(f"Increase at {mid}")
    else:
        print(f"Decrease at {mid}")

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Meligui
Comment options

@deepcharles
Comment options

@Meligui
Comment options

Answer selected by Meligui
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants