Identifying the direction of change #281
|
Hi, I was using the library for an application where I would also like to identify the direction of the change (i.e., at the change point whether the algorithm is detecting increased or decreased values of the time series in question) I thought of implementing it by just checking averages of a few samples before and after the change point and identifying the change direction this way but was wondering if there is a better way to do it using the library itself. I looked through the documentation but couldn't find a way. Thanks. |
Answered by
deepcharles
Dec 7, 2022
Replies: 1 comment 3 replies
|
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}") |
3 replies
Answer selected by
Meligui
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, thanks for your interest in ruptures.
It is not coded in the library by it can easily be done: