-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_lds_velocity.m
90 lines (80 loc) · 1.82 KB
/
test_lds_velocity.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
A = [1 1; 0 1];
Gamma = [0 0; 0 1]/10;
C = eye(2);
Sigma = eye(2)/2;
m1 = [0;1];
v1 = Gamma;
lds = lds_density(A, Gamma, m1, v1, C, Sigma);
disp(lds);
n = 20;
[data, states] = sample(lds, n);
figure(1)
%subplot(2,1,1);
plot(1:n, data(1, :), '-o', 1:n, states(1, :), '--');
xlabel('time');
ylabel('position');
title('Measurement sequence');
%subplot(2,1,2);
%plot(1:n, data(2, :), 1:n, states(2, :), '--');
%xlabel('time');
%ylabel('velocity');
% orient landscape
% print -dpsc2 lds_measurement.ps
if 1
% hide part of the state
data = data(1, :);
C = [1 0];
Sigma = Sigma(1);
lds = lds_density(A, Gamma, m1, v1, C, Sigma);
end
[p, means] = logProb(lds, {data});
figure(3)
subplot(2,1,1);
plot(1:n, means(1, :), 1:n, states(1, :), '--');
xlabel('time');
ylabel('position');
title('Forward estimates');
subplot(2,1,2);
plot(1:n, means(2, :), 1:n, states(2, :), '--');
xlabel('time');
ylabel('velocity');
% print -dpsc2 lds_forward.ps
[means, vars, covs, likelihood] = classify(lds, data);
figure(2)
subplot(2,1,1);
plot(1:n, means(1, :), 1:n, states(1, :), '--');
xlabel('time');
ylabel('position');
title('Smoothed estimates');
subplot(2,1,2);
plot(1:n, means(2, :), 1:n, states(2, :), '--');
xlabel('time');
ylabel('velocity');
% print -dpsc2 lds_smoothed.ps
figure(4)
subplot(2,1,1)
plot(1:n, vars(1, :));
xlabel('time');
ylabel('position variance');
title('Estimate variances');
subplot(2,1,2)
plot(1:n, vars(4, :));
xlabel('time');
ylabel('velocity variance');
% print -dpsc2 lds_variance.ps
if 0
% for comparison, sample from the equivalent Gaussian distribution
gauss = asGaussian(lds, n);
x = sample(gauss);
x = vtrans(x, rows(A));
figure(2);
plot(x(1, :), x(2, :), 'o');
end
% hide part of the state
data = data(1, :);
if 0
C = [1 0; 0 0];
Sigma = eye(1)/10;
obj = lds_density(A, Gamma, m1, v1, C, Sigma);
disp(train(obj, {data}));
end