-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrand_sparse_seq.m
111 lines (93 loc) · 2.89 KB
/
rand_sparse_seq.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
function [x, y, G, F] = rand_sparse_seq(varargin)
% [x, y, G, F] = rand_sparse_seq(x_dim, y_dim, sparse_num, init_var, ...
% num_iters, obs_var, dyn_var, poi_var)
%
% This function generates a sequence of sparse signals evolving with random
% permutations at each iteration. The innovations are sparse. Each signal
% is compressed with a Gaussian matrix to yield compressed measurements.
%
% The inputs are:
%
% x_dim: scalar value indicating the size of the signal
% y_dim: scalar value indicating the number of measurements
% sparse_num: scalar value indicating the signal sparsity
% init_var: Wavelet transform (sparsity basis)
% num_iters: scalar value for the number of time iterations to generate
% obs_var: scalar value for the variance of the measurement noise
% dyn_var: scalar value for the on-support variance of dynamics noise
% poi_var: scalar value for the innovations sparsity Poisson mean
%
% The outputs are:
%
% x: NxT array of dynamically evolving sparse signals
% y: MxT array of the compressed measurements of x
% G: MxNxT array of measurement matrices that gave y from x
% F: NxNxT array of dynamics matrices that approximately evolve x
%
%
% Code by Adam Charles,
% Department of Electrical and Computer Engineering,
% Georgia Institute of Technology
%
% Last updated August 20, 2012.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Parse inputs
if nargin >= 2
x_dim = varargin{1};
y_dim = varargin{2};
else
x_dim = 500;
y_dim = 70;
end
if nargin > 2
sparse_num = varargin{3};
else
sparse_num = 20;
end
if nargin > 3
init_var = varargin{4};
else
init_var = 1;
end
if nargin > 4
num_iters = varargin{5};
else
num_iters = 30;
end
if nargin > 5
obs_var = varargin{6};
else
obs_var = 0.1;
end
if nargin > 6
dyn_var = varargin{7};
else
dyn_var = 0.1;
end
if nargin > 7
poi_var = varargin{8};
else
poi_var = 1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Initialize the sequence
x = zeros(x_dim, num_iters+1);
y = zeros(y_dim, num_iters+1);
F = zeros(x_dim, x_dim, num_iters+1);
G = zeros(y_dim, x_dim, num_iters+1);
init_supp = randperm(x_dim);
x(init_supp(1:sparse_num), 1) = sqrt(init_var)*randn(sparse_num, 1);
G(:, :, 1) = randn(y_dim, x_dim)/sqrt(y_dim);
y(:, 1) = G(:, :, 1)*x(:, 1) + sqrt(obs_var)*randn(y_dim, 1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Generate the sequence
for ii = 2:num_iters
F(:, :, ii) = RandPermMat(x_dim, 1, 0.01);
x(:, ii) = noise_model(F(:, :, ii)*x(:, ii-1), dyn_var, poi_var);
G(:, :, ii) = randn(y_dim, x_dim)/sqrt(y_dim);
y(:, ii) = G(:, :, ii)*x(:, ii) + sqrt(obs_var)*randn(y_dim, 1);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%