ivan@154
|
1 function [x] = generate_vector(N, K, ensemble, sigma, p)
|
ivan@154
|
2 % =========================================================================
|
ivan@154
|
3 % Sparse vector generator
|
ivan@154
|
4 % =========================================================================
|
ivan@154
|
5 % INPUT ARGUMENTS:
|
ivan@154
|
6 % N Size of sparse vector.
|
ivan@154
|
7 % K Sparsity of vector.
|
ivan@154
|
8 % ensemble Ensemble type of measurement matrix. Possible
|
ivan@154
|
9 % values are:
|
ivan@154
|
10 % -'Gaussian': K non-zero elements of the sparse vector
|
ivan@154
|
11 % are drawn from normal distribution N(0,1).
|
ivan@154
|
12 % -'sGaussian': K non-zero elements of the sparse vector
|
ivan@154
|
13 % are drawn from normal distribution N(0,sigma^2).
|
ivan@154
|
14 % -'Bernoulli': K non-zero elements of the sparse vector
|
ivan@154
|
15 % are drawn from Bernoulli distribution (1/2,1/2).
|
ivan@154
|
16 % -'pBernoulli': K non-zero elements of the sparse vector
|
ivan@154
|
17 % are drawn from Bernoulli distribution (p,1-p).
|
ivan@154
|
18 % sigma Standard deviation of Gaussian distribution.
|
ivan@154
|
19 % p Parameter of Bernoulli distribution.
|
ivan@154
|
20 % =========================================================================
|
ivan@154
|
21 % OUTPUT ARGUMENTS:
|
ivan@154
|
22 % x K-sparse vector.
|
ivan@154
|
23 % =========================================================================
|
ivan@154
|
24 % 01/04/2011, by Anastasios Kyrillidis. anastasios.kyrillidis@epfl.ch, EPFL.
|
ivan@154
|
25 % =========================================================================
|
ivan@154
|
26
|
ivan@154
|
27 if nargin < 3
|
ivan@154
|
28 ensemble = 'Gaussian';
|
ivan@154
|
29 end;
|
ivan@154
|
30
|
ivan@154
|
31 if nargin < 4
|
ivan@154
|
32 sigma = 1;
|
ivan@154
|
33 p = 0.5;
|
ivan@154
|
34 end;
|
ivan@154
|
35
|
ivan@154
|
36 x = zeros(N,1);
|
ivan@154
|
37 rand_indices = randperm(N);
|
ivan@154
|
38
|
ivan@154
|
39 switch ensemble
|
ivan@154
|
40 case 'Gaussian'
|
ivan@154
|
41 x(rand_indices(1:K)) = randn(K,1); % Standard normal distribution ~ N(0,1)
|
ivan@154
|
42 case 'sGaussian'
|
ivan@154
|
43 x(rand_indices(1:K)) = sigma*randn(K,1); % Normal distribution ~ N(0,sigma^2)
|
ivan@154
|
44 case 'Uniform'
|
ivan@154
|
45 x(rand_indices(1:K)) = rand(K,1); % Uniform [0,1] distribution
|
ivan@154
|
46 case 'Bernoulli'
|
ivan@154
|
47 x(rand_indices(1:K)) = (-1).^round(rand(K,1)); % Bernoulli ~ (1/2, 1/2) distribution
|
ivan@154
|
48 case 'pBernoulli'
|
ivan@154
|
49 x(rand_indices(1:K)) = (-1).^(rand(K,1) > p); % Bernoulli ~ (p, 1-p) distribution
|
ivan@154
|
50 end;
|
ivan@154
|
51
|
ivan@154
|
52 x = x/norm(x); |