-
Notifications
You must be signed in to change notification settings - Fork 3
/
demo.m
131 lines (105 loc) · 3.64 KB
/
demo.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
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
%% Demo for PAA codes
% copyright (c) Sohan Seth, sohan.seth@hiit.fi
%% Poisson observation
close all
rng default,
options = generate_options();
options.verbose = true;
options.display = true;
options.eps = 10^-10;
options.maxIter = 100000;
options.matFeatLat = [];
n = 100;
% Generating data
matFeatSam = [ceil(rand(1,n)*10); ceil(rand(1,n)*10)];
% Learning archetypes
[matSamLat, matLatSam_1, ~] = paa_Poisson(matFeatSam, 4, options);
archetypes = matFeatSam * matSamLat;
axis([0 11 0 11]), box on, set(gca, 'fontsize', 20)
% Computing projections given archetypes
options.matFeatLat = archetypes;
options.display = false;
[~, matLatSam_2, ~] = paa_Poisson(matFeatSam, [], options);
fprintf('difference between projections %0.6f\n', ...
norm(archetypes * matLatSam_2 - archetypes * matLatSam_1, 1) / numel(matFeatSam))
%% Bernoulli observation
close all
rng default,
options = generate_options();
options.verbose = true;
options.display = true;
options.eps = 10^-6;
options.maxIter = 1000;
options.matFeatLat = [];
n = 500;
% Generating data
matFeatSam = [rand(1,n) > 0.8; rand(1,n) > 0.2];
% Learning archetypes
[matSamLat, matLatSam_1, ~] = paa_Bernoulli(matFeatSam, 4, options);
archetypes = matFeatSam * matSamLat;
axis([-0.1 1.1 -0.1 1.1]), box on, set(gca, 'fontsize', 20)
% Computing projections given archetypes
options.matFeatLat = archetypes;
options.display = false;
[~, matLatSam_2, ~] = paa_Bernoulli(matFeatSam, [], options);
fprintf('difference between projections %0.6f\n', ...
norm(archetypes * matLatSam_2 - archetypes * matLatSam_1, 1) / numel(matFeatSam))
%% Multinomial observations
close all
rng default,
options = generate_options();
options.verbose = true;
options.display = true;
options.eps = 10^-6;
options.maxIter = 10000;
options.matFeatLat = [];
n = 500;
% Generating data
matFeatSam = rand(3, n); matFeatSam = bsxfun(@rdivide, matFeatSam, sum(matFeatSam));
nFeatSam = mnrnd(1000, matFeatSam')';
matFeatSam = bsxfun(@rdivide, nFeatSam, sum(nFeatSam)); % empirical probabilities
% Learning archetypes
[matSamLat, matLatSam_1, ~] = paa_stochastic(nFeatSam, 3, options);
archetypes = matFeatSam * matSamLat;
axis([0 1000 0 1000]), box on, set(gca, 'fontsize', 20)
% Computing projections given archetypes
options.matFeatLat = archetypes;
options.display = false;
[~, matLatSam_2, ~] = paa_stochastic(nFeatSam, [], options);
fprintf('difference between projections %0.6f\n', ...
norm(archetypes * matLatSam_2 - archetypes * matLatSam_1, 1) / numel(matFeatSam))
%% Normal observation
close all
rng default,
options = generate_options();
options.verbose = true;
options.display = true;
options.eps = 10^-6;
options.maxIter = 20;
options.matFeatLat = [];
n = 100;
% Generating data
matFeatSam = [rand(1,n); rand(1,n)];
% Learning archetypes
[matSamLat, matLatSam_1, ~] = paa_normal(matFeatSam, 4, options);
archetypes = matFeatSam * matSamLat;
axis([0 1 0 1]), box on, set(gca, 'fontsize', 20)
% Computing projections given archetypes
options.matFeatLat = archetypes;
options.display = false;
[~, matLatSam_2, ~] = paa_normal(matFeatSam, [], options);
fprintf('difference between projections %0.6f\n', ...
norm(archetypes * matLatSam_2 - archetypes * matLatSam_1, 1) / numel(matFeatSam))
%% Normal observation with R interface
close all
rng default,
% Generating data
matFeatSam = [rand(1,n); rand(1,n)];
% Learning archetypes
[matSamLat, matLatSam_1, ~] = classic_aa(matFeatSam, 4);
archetypes = matFeatSam * matSamLat;
% Computing projections given archetypes
matLatSam_2 = classic_aa_test(matFeatSam);
fprintf('difference between projections %0.6f\n', ...
norm(archetypes * matLatSam_2 - archetypes * matLatSam_1, 1) / numel(matFeatSam))
publish('')