-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathload_generic_norm_dist_data.m
104 lines (84 loc) · 2.87 KB
/
load_generic_norm_dist_data.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
% LOAD_GENERIC_NORM_DIST_DATA Generate data following normal distributions
%
% [DATA, CP] = LOAD_GENERIC_NORM_DIST_DATA(SIZE, TYPE)
%
% The SIZE indicates the length of the requested data sequence (default
% 100)
%
% The TYPE sets the type of segments/distributions. The options are:
% - 'alternating: (default) generate with alternating variances of 5 and
% 1, mean 0
% - 'paper': Use the patern of the paper on CUSUM by Inclan and Tiao.
% Mean 0 and variances in segment [1 : 391] -> 1, [391 : 518] -> 0.365
% and [518 : 700] -> 1.033
% - 'homogeneous': single segment with mean 0 and variance 1.
% - 'single': two segments with mean 0 and variances 1 and 2
%
% The vector CHANGE_POINTS containts the data times at which the pattern
% changed
function [ data, change_points ] = load_generic_norm_dist_data(size,type)
if nargin < 2
type = 'alternating';
if nargin < 1
size = 100;
end
end
% Determine which generation function to use
switch type
case 'alternating'
[data, change_points] = AlternatingVariance(size, 5, [1, 5, 1, 5, 1]);
case 'paper'
[data, change_points] = PaperExample();
case 'homogeneous'
[data, change_points] = AlternatingVariance(size, 1, 1);
case 'single'
[data, change_points] = AlternatingVariance(size, 2, [1, 2]);
otherwise
warning('Unexpected function type.');
end
change_points(1) = [];
end
function [values, change_points] = AlternatingVariance(size, segments, variances)
% ALTERNATING_VARIANCE Generate a sequence of data with alternating
% variance. Mean is fixed at 0.
fprintf('Generating alternating variance data \n');
change_points = ones(segments-1,1);
if nargin < 3
variances = [1, 3, 1];
if nargin < 2
segments = 3;
if nargin < 1
size = 100;
end
end
end
values = zeros(1, size);
per_segment = size / segments;
j = 1;
for segment = 1:segments
variance = variances(segment);
fprintf(' new segment at %i with variance %i \n', j, variance );
change_points(segment) = j;
for i = 1:per_segment
values(j) = normrnd(0, variance);
j = j + 1;
end
end
end
function [values, change_points] = PaperExample()
fprintf('Generating data following the scheme in the paper: \n');
fprintf(' [1 : 391]: 1 \n');
fprintf(' [391 : 518]: 0.365 \n');
fprintf(' [518 : 700]: 1.033 \n');
change_points = [1, 391 518 700];
values = zeros(1,700);
for i=1:391
values(i) = normrnd(0, 1);
end
for i=392:518
values(i) = normrnd(0, 0.365);
end
for i=519:700
values(i) = normrnd(0,1.033);
end
end