1- function pipelineArtificialData(pathToRepo )
1+ % function pipelineArtificialData(pathToRepo)
22%
33% Overview:
44% Loads artificially generated data and applies change point
@@ -31,8 +31,8 @@ function pipelineArtificialData(pathToRepo)
3131settings.tolerance = 5 ; % tolerance in seconds for determining if change point is detected;
3232 % if estimated change point (ecp) is within true change point (tcp),
3333 % the change point is detected.
34- settings.act = 1 ; % 1: work with actigraphy data
35- settings.figs = 0 ; % 1: plot tcp & ecp on time series
34+ settings.act = 0 ; % 1: work with actigraphy data
35+ settings.figs = 1 ; % 1: plot tcp & ecp on time series
3636settings.iterations = 1000 ;
3737
3838% Choose parameter set according to each method
@@ -55,16 +55,34 @@ function pipelineArtificialData(pathToRepo)
5555
5656 % Create random seed
5757 seed = rand(1 )*1e3 ;
58+
59+ % Generate artificial data
60+ if settings .act ~= 1
61+ % 24 hour RR time series
62+ vector_length = 86400 ;
5863
59- % Generate a random vector length between 1e3 and 9e3
60- vector_length = 1000 ;
61-
62- % Create RR time series with 'rrgen_sys' exe (compiled from c file)
63- [data , tcp ] = rrgenV3_wrapper(seed , vector_length , 0 , 0 , pathToRepo );
64+ % Create RR time series with 'rrgen_sys' exe (compiled from c file)
65+ [data , tcp , sleepStart , sleepEnd ] = rrgenV3_wrapper(seed , vector_length , 0 , 0 , pathToRepo );
66+
67+ % Calculate sleep length
68+ sleepLength = (sleepEnd - sleepStart ) / 3600 ;
69+
70+ hold off ;
71+ plot(data ); hold on ; plot(sleepStart ,data(sleepStart ),' ro' ); hold on ; plot(sleepEnd ,data(sleepEnd ),' ro' );
6472
65- % Can also specify probability of ectopy and noise: rrgen_2003(seed, vector_length, prob_ectopy, prob_noise);
66-
67- time = cumsum(data ); % Time of RR time series is found by cumulative summation
73+ % Extract sleep portion of data
74+ data = data(sleepStart : sleepEnd );
75+
76+ % Adjust changepoints for sleep portion
77+ tcp_idx = find((tcp > sleepStart ) & (tcp < sleepEnd ));
78+ tcp = tcp(tcp_idx ) - sleepStart ;
79+
80+ time = cumsum(data ); % Time of RR time series is found by cumulative summation
81+ else
82+ vector_length = 24000 ;
83+ [data , tcp , sleepStart , sleepEnd ] = rrgenV3_wrapper(seed , vector_length , 0 , 0 , pathToRepo );
84+ time = cumsum(data );
85+ end
6886
6987 % Converting rrgen data to actigraphy data
7088 if settings .act == 1
@@ -122,11 +140,7 @@ function pipelineArtificialData(pathToRepo)
122140
123141 %% Modified Bayesian Online Changepoint Detection
124142
125- rl = mbocd(data , lambda , ' gamma' );
126-
127- % Locate estimated changepoints
128- [~ , ecp ] = findpeaks(rl(: ,1 ));
129- ecp(end ) = []; % last index is errenous
143+ ecp = msegWin(data , lambda , 30000 );
130144
131145 % Plot true and estimated change points
132146 if settings .figs == 1
@@ -141,9 +155,7 @@ function pipelineArtificialData(pathToRepo)
141155
142156 %% BOCD Original Code
143157
144- [~ , maxes ] = bocd(data , lambda2 );
145-
146- [~ , ecp ] = findpeaks(maxes(: ,1 ));
158+ ecp = segWin(data ,lambda2 , 30000 );
147159
148160 % Plot true and estimated change points
149161 if settings .figs == 1
@@ -367,4 +379,4 @@ function pipelineArtificialData(pathToRepo)
367379
368380tightfig ;
369381
370- end
382+ % end
0 commit comments