-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrain_bss_gen_problem.m
131 lines (103 loc) · 2.7 KB
/
brain_bss_gen_problem.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
function [truth, model, y] = brain_bss_gen_problem(params)
load('data/brain_data_66', 'CC')
assert(size(CC, 1) == size(CC, 2))
% Number of nodes.
N = size(CC, 2);
if ~exist('params', 'var')
params = struct;
end
if isfield(params, 'brain_idxs')
brain_idxs = params.brain_idxs;
else
if isfield(params, 'numGraphs')
if params.numGraphs > size(CC, 3)
error('Maximum number of graphs is %d (%d provided)', size(CC, 3), ...
params.numGraphs);
end
brain_idxs = randperm(size(CC, 3), params.numGraphs);
else
brain_idxs = randperm(size(CC, 3), 2);
end
end
R = length(brain_idxs);
% Order of the filters (number of filter coefficients).
if isfield(params, 'L')
L = params.L;
else
L = 2;
end
% Number of non-zero input nodes.
if isfield(params, 'S')
S = params.S;
else
S = 1;
end
data_distribution = DataDistribution.Normal;
shift_operator = ShiftOperator.Laplacian;
for i = 1:R
% Adjacency matrix.
brain_graph = reshape(CC(:,:,brain_idxs(i)), N, N)*100;
model.G(i).W = double(brain_graph >= min(max(brain_graph)));
% Graph Laplacian.
model.G(i).L = diag(sum(model.G(i).W))-model.G(i).W;
assert(issymmetric(model.G(i).W))
assert(issymmetric(model.G(i).L))
switch shift_operator
case ShiftOperator.Adjacency
model.G(i).S = model.G(i).W;
case ShiftOperator.Laplacian
model.G(i).S = model.G(i).L;
end
[model.G(i).V, Lambda, model.G(i).U] = eig(model.G(i).S);
model.G(i).lambda = diag(Lambda);
end
model.V = reshape([model.G.V], [N, N, R]);
% Filter coefficients.
truth.h = zeros(L, R);
switch data_distribution
case DataDistribution.Normal
truth.h = randn(L, R);
truth.h = truth.h ./ repmat(norms(truth.h, 2, 1), L, 1);
case DataDistribution.Uniform
truth.h = rand(L, R);
truth.h = truth.h ./ repmat(norms(truth.h, 2, 1), L, 1);
end
for i = 1:R
model.Psi{i} = repmat(model.G(i).lambda, 1, L).^repmat([0:L-1], N, 1);
% disp(minmax(vec(model.Psi{i})'))
end
% Build filter matrices.
H = zeros(N, N * R);
for i = 1:R
Hi = truth.h(1, i)*eye(N);
for l = 1:L-1
Hi = Hi + truth.h(l+1, i)*model.G(i).S^l;
end
H(:, N*(i-1)+1:N*i) = Hi;
end
% Input.
truth.xSupport = zeros(R, S);
for i = 1:R
truth.xSupport(i, :) = randperm(N, S);
end
truth.x = zeros(N, R);
switch data_distribution
case DataDistribution.Normal
for i = 1:R
truth.x(truth.xSupport(i, :), i) = randn(S, 1);
truth.x(:, i) = truth.x(:, i) ./ norm(truth.x(:, i));
end
case DataDistribution.Uniform
for i = 1:R
truth.x(truth.xSupport(i, :), i) = rand(S, 1);
truth.x(:, i) = truth.x(:, i) ./ norm(truth.x(:, i));
end
end
y = H*truth.x(:);
for i = 1:R
model.A{i} = kr(model.Psi{i}', model.G(i).U)';
end
for i = 1:R
truth.Z{i} = truth.x(:, i)*truth.h(:, i)';
end
end