Skip to contents

fastcpd_kcp() and fastcpd.kcp() detect change points in the full distribution of the data using the kernel change point (KCP) approach. The RBF kernel \(k(x,y)=\exp(-\|x-y\|^2/(2\sigma^2))\) is approximated by random Fourier features via Bochner's theorem, and change points in the resulting kernel mean embedding are detected with the existing PELT infrastructure. This is \(O(nD)\) in time — compared to \(O(n^2)\) for the exact kernel PELT — where \(D\) is order[1].

Usage

fastcpd_kcp(data, order = c(100L, 0), ...)

fastcpd.kcp(data, order = c(100L, 0), ...)

Arguments

data

A numeric vector or a matrix with one row per observation.

order

A numeric vector of length up to 2: order[1] is the number of random Fourier features (default 100; larger values improve accuracy at the cost of speed) and order[2] is the RBF kernel bandwidth \(\sigma\) (default 0, which triggers the median heuristic \(\sigma = \sqrt{\mathrm{median}(d^2)/2}\) on a subsample of up to 1000 observations). Call set.seed() before this function for reproducible results.

...

Other arguments passed to fastcpd(), for example, segment_count.

Value

A fastcpd object.

See also

Examples

set.seed(1)
p_values <- c(runif(200, 0, 0.05), runif(200, 0, 1))
result <- fastcpd_kcp(p_values)
summary(result)
#> 
#> Call:
#> fastcpd_kcp(data = p_values)
#> 
#> Change points:
#> 200 
#> 
#> Cost values:
#> 0.7189455 61.38592 
#> 
#> Parameters:
#>        segment 1     segment 2
#> 1    0.063830461  0.1081747500
#> 2    0.137803918 -0.0151099914
#> 3    0.053672061 -0.0360899059
#> 4   -0.007565691 -0.0960820029
#> 5    0.120920474  0.0050971783
#> 6    0.134583490  0.0006240994
#> 7   -0.094999268 -0.0439464497
#> 8   -0.118131870 -0.0591299535
#> 9    0.134666988  0.1329728153
#> 10   0.103298666 -0.0450497966
#> 11   0.128182162  0.0864101470
#> 12  -0.087862495 -0.1040620162
#> 13  -0.139875561 -0.0665024602
#> 14  -0.140477774 -0.0045954567
#> 15  -0.009181973  0.0242019741
#> 16  -0.131759161 -0.0038747127
#> 17   0.086647635  0.1214163676
#> 18  -0.050659136  0.0272825215
#> 19  -0.088058518  0.0559193913
#> 20   0.132680806  0.1372090513
#> 21   0.049865560 -0.0253066276
#> 22   0.032842109  0.0320459847
#> 23  -0.139686052 -0.0090940078
#> 24   0.098128878  0.1170995485
#> 25  -0.039874451  0.0234489806
#> 26  -0.070031750  0.0203243945
#> 27   0.002102121  0.0933107898
#> 28  -0.116252769 -0.0044023752
#> 29  -0.141158557 -0.1185479546
#> 30   0.132973022  0.1188205918
#> 31   0.069950547 -0.0207712840
#> 32  -0.040858393  0.0151714961
#> 33  -0.041994874  0.0671460465
#> 34   0.077868800  0.0725479195
#> 35  -0.134589962 -0.1251501272
#> 36  -0.054858267 -0.0183941835
#> 37   0.107740753 -0.0456610721
#> 38   0.137364195  0.0168665840
#> 39  -0.028898771  0.0226696105
#> 40  -0.069747209 -0.0715198840
#> 41   0.124722937  0.0189806428
#> 42  -0.066145916 -0.0230164910
#> 43   0.130952729  0.1278968814
#> 44   0.060195933  0.0253824175
#> 45   0.061298755  0.0296320450
#> 46   0.063970107 -0.0032733339
#> 47   0.140472727  0.0227924228
#> 48   0.087071025 -0.0031442068
#> 49  -0.059468821 -0.1047581880
#> 50   0.138051731  0.0081166495
#> 51  -0.060782047 -0.0103838715
#> 52   0.085492825  0.1071537193
#> 53  -0.090238313 -0.0676957132
#> 54  -0.106716009 -0.0240933863
#> 55  -0.121427215  0.0372564294
#> 56   0.100147976 -0.0117760454
#> 57   0.092894371  0.0198732322
#> 58  -0.112963627  0.0422379855
#> 59   0.009719596  0.0991296266
#> 60   0.087685357 -0.0466033013
#> 61  -0.111823473 -0.0141616578
#> 62   0.034291692 -0.0789383874
#> 63   0.134145109  0.1126996403
#> 64  -0.086425449  0.0318130884
#> 65  -0.113276184  0.0042111990
#> 66  -0.117069307 -0.0311817083
#> 67   0.115960163 -0.0164605340
#> 68   0.068224273  0.0308669356
#> 69  -0.090615628  0.0224629524
#> 70  -0.084509561 -0.0194625493
#> 71   0.010310227 -0.0744387510
#> 72  -0.138465626 -0.0347934457
#> 73   0.049116707 -0.0352915272
#> 74  -0.114751189  0.0151441630
#> 75  -0.141319438 -0.1222230792
#> 76  -0.133496771 -0.0174485113
#> 77  -0.046712386  0.0055457372
#> 78   0.088527184 -0.0463131700
#> 79  -0.013207662  0.0355578291
#> 80  -0.043465999 -0.0250881256
#> 81   0.026715426  0.1041629231
#> 82   0.015868548 -0.0893842252
#> 83   0.062105021 -0.0299826268
#> 84  -0.141174034  0.0092732262
#> 85  -0.122658920 -0.0452378942
#> 86  -0.139898369  0.0009756315
#> 87  -0.096179361  0.0511229614
#> 88  -0.134075665 -0.0057968564
#> 89   0.139897214  0.0290654292
#> 90   0.132510237  0.0102879968
#> 91   0.128045739  0.0916389691
#> 92  -0.140561050 -0.0504239505
#> 93   0.065239851  0.1170235022
#> 94  -0.129784634 -0.0139422572
#> 95  -0.137271855  0.0167899242
#> 96  -0.130580180 -0.0999160648
#> 97   0.050634306  0.0400064864
#> 98   0.050416523 -0.0244643044
#> 99   0.138776277  0.1332355195
#> 100 -0.138123802 -0.0623973463