-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdemo.m
More file actions
199 lines (139 loc) · 4.04 KB
/
Copy pathdemo.m
File metadata and controls
199 lines (139 loc) · 4.04 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
%% Add path to D-REX model code directory
% addpath(.);
%% Simple example of Gaussian sequence with one change
rng(10);
x = [2*randn(50,1); 6*randn(50,1)];
params = [];
params.distribution = 'gaussian';
params.D = 1;
params.prior = estimate_suffstat(std(x)*randn(1000,1),params);
x = [2*randn(50,1); 6*randn(50,1)];
out = run_DREX_model(x,params);
figure(1); clf;
display_DREX_output(out,x)
%% Same example w/ finite maxhyp
rng(10);
x = [2*randn(50,1); 6*randn(50,1)];
params = [];
params.distribution = 'gaussian';
params.D = 1;
params.prior = estimate_suffstat(std(x)*randn(1000,1),params);
params.maxhyp = 30; % limits number of context hypotheses to 30, pruning by beliefs
x = [2*randn(50,1); 6*randn(50,1)];
out = run_DREX_model(x,params);
figure(1); clf;
display_DREX_output(out,x)
%% Gaussian mixture example with single wide component in prior
x = [-5+randn(1,50), 5+randn(1,50)]';
x = x(randperm(length(x)));
x = [rand(100,1)*range(x) + min(x); x];
params = [];
params.distribution = 'gmm';
params.max_ncomp = 10;
params.beta = 0.001;
params.D = 1;
params.prior = estimate_suffstat(randn(1000,1),params);
params.maxhyp = inf;
params.memory = inf;
out = run_DREX_model(x,params);
figure(1); clf;
display_DREX_output(out,x)
%% Gaussian mixture example with spread out multi-component prior
x = [-5+randn(1,50), 5+randn(1,50)]';
x = x(randperm(length(x)));
x = [rand(100,1)*range(x) + min(x); x];
params = [];
params.distribution = 'gmm';
params.max_ncomp = 10;
params.beta = 0.001;
params.D = 1;
params.prior = estimate_suffstat(randn(1000,1),params);
params.prior.mu = {[-8:2:8 nan]};
params.prior.sigma = {[0.1*ones(1,9) nan]};
params.prior.n = {[ones(1,9) nan]};
params.prior.pi = {[1/9*ones(1,9) 0]};
params.prior.sp = {[ones(1,9) 0]};
params.prior.k = {9};
params.maxhyp = inf;
params.memory = inf;
out = run_DREX_model(x,params);
figure(1); clf;
display_DREX_output(out,x)
%% Simple example w/ prior from several different sequences
exposure = cell(3,1);
exposure{1} = 2*randn(50,1);
exposure{2} = 6*randn(20,1);
exposure{3} = 0.5*randn(80,1);
x = [2*randn(50,1); 6*randn(50,1)];
params = [];
params.D = 1;
params.prior = estimate_suffstat(exposure,params); % priors calculated from exposure set
out = run_DREX_model(x,params);
figure(1); clf;
display_DREX_output(out,x)
%% Example with temporal dependence D = 2
x = zeros(100,1); % input: Gaussian random walk
for t = 2:100
if t < 50
s = .2;
else
s = -.2;
end
x(t) = x(t-1)+2*(randn(1)+s);
end
params = [];
params.D = 2;
params.memory = inf;
params.prior = estimate_suffstat(x,params);
out = run_DREX_model(x,params);
figure(1); clf;
display_DREX_output(out,x)
%% Example with temporal dependence D >> 1
exposure = 5*randn(100,1);
x = 5*repmat(randn(5,1),15,1)+randn(75,1); % noisy cycle
params = [];
params.D = 6;
params.memory = inf;
params.prior = estimate_suffstat(exposure,params);
out = run_DREX_model(x,params);
figure(1); clf;
display_DREX_output(out,x)
%% Example with finite memory
x = [2*randn(50,1); 6*randn(50,1)];
params = [];
params.D = 1;
params.memory = 30;
params.prior = estimate_suffstat(permute(x,[1,3,2]),params);
out = run_DREX_model(x,params);
figure(1); clf;
display_DREX_output(out,x)
%% Example with observation noise
x = [2*randn(50,1); 6*randn(50,1)];
params = [];
params.D = 1;
params.memory = inf;
params.obsnz = 3;
params.prior = estimate_suffstat(permute(x,[1,3,2]),params);
out = run_DREX_model(x,params);
figure(1); clf;
display_DREX_output(out,x)
%% Example with missing/silent observations
x = [2*randn(50,1); 6*randn(50,1)];
x([30:35, 70:80]) = nan;
params = [];
params.D = 1;
params.prior = estimate_suffstat(permute(x,[1,3,2]),params);
out = run_DREX_model(x,params);
figure(1); clf;
display_DREX_output(out,x)
%% Example with multiple features
x1 = [2*randn(70,1); 6*randn(30,1)];
x2 = [6*randn(50,1); 2*randn(50,1)];
x3 = [2*randn(30,1); 8+2*randn(70,1)];
x = [x1, x2, x3];
params = [];
params.D = 1;
params.prior = estimate_suffstat(permute(x,[1,3,2]),params);
out = run_DREX_model(x,params);
figure(1); clf;
display_DREX_output(out,x)