deepcharles / ruptures

ruptures: change point detection in Python
BSD 2-Clause "Simplified" License
1.6k stars 163 forks source link

Min_size=1 with kernel change point detection but no segments of 1 #269

Closed christina-l-cleveland closed 1 year ago

christina-l-cleveland commented 2 years ago

Hello!

I was hoping to identify segments of down to 1 point in size with kernel change point detection but no matter how low I drop the penalty, the minimum segment size I observe is 2. Is this a feature of kernel change point detection? that a segment of 1 is basically not possible?

deepcharles commented 1 year ago

Hi,

can you share the line of code that you use? There is indeed one problem with min_size for some methods.

christina-l-cleveland commented 1 year ago

sure! roughly the code is

rupture_model = rpt.KernelCPD(kernel=kernel, min_size=min_size) seg_brkpts = rupture_model.fit_predict(seg_values, pen=penalty)

where kernel="rbf", min_size=1, penalty=2 though I tried a very low penalty out of curiosity (0.00001) and still only achieved segments of minimum size 2. is it not possible with the gaussian kernel to create a segment of min_size<2?

deepcharles commented 1 year ago

Thanks, there is a bug in the min_size is handled. Basically, rupture_model.min_size is 2 even if you set min_size=1 in the argument. Try doing

rupture_model = rpt.KernelCPD(kernel=kernel, min_size=min_size)
rupture_model.min_size = 1   # force min_size to be 1
seg_brkpts = rupture_model.fit_predict(seg_values, pen=penalty)
christina-l-cleveland commented 1 year ago

that worked! Thanks a lot!

deepcharles commented 1 year ago

It should be fixed (#270) in the next version (1.1.8).