Mercurial > hg > smallbox
comparison toolboxes/alps/generate_vector.m @ 154:0de08f68256b ivand_dev
ALPS toolbox - Algebraic Pursuit added to smallbox
author | Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk> |
---|---|
date | Fri, 12 Aug 2011 11:17:47 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
153:af307f247ac7 | 154:0de08f68256b |
---|---|
1 function [x] = generate_vector(N, K, ensemble, sigma, p) | |
2 % ========================================================================= | |
3 % Sparse vector generator | |
4 % ========================================================================= | |
5 % INPUT ARGUMENTS: | |
6 % N Size of sparse vector. | |
7 % K Sparsity of vector. | |
8 % ensemble Ensemble type of measurement matrix. Possible | |
9 % values are: | |
10 % -'Gaussian': K non-zero elements of the sparse vector | |
11 % are drawn from normal distribution N(0,1). | |
12 % -'sGaussian': K non-zero elements of the sparse vector | |
13 % are drawn from normal distribution N(0,sigma^2). | |
14 % -'Bernoulli': K non-zero elements of the sparse vector | |
15 % are drawn from Bernoulli distribution (1/2,1/2). | |
16 % -'pBernoulli': K non-zero elements of the sparse vector | |
17 % are drawn from Bernoulli distribution (p,1-p). | |
18 % sigma Standard deviation of Gaussian distribution. | |
19 % p Parameter of Bernoulli distribution. | |
20 % ========================================================================= | |
21 % OUTPUT ARGUMENTS: | |
22 % x K-sparse vector. | |
23 % ========================================================================= | |
24 % 01/04/2011, by Anastasios Kyrillidis. anastasios.kyrillidis@epfl.ch, EPFL. | |
25 % ========================================================================= | |
26 | |
27 if nargin < 3 | |
28 ensemble = 'Gaussian'; | |
29 end; | |
30 | |
31 if nargin < 4 | |
32 sigma = 1; | |
33 p = 0.5; | |
34 end; | |
35 | |
36 x = zeros(N,1); | |
37 rand_indices = randperm(N); | |
38 | |
39 switch ensemble | |
40 case 'Gaussian' | |
41 x(rand_indices(1:K)) = randn(K,1); % Standard normal distribution ~ N(0,1) | |
42 case 'sGaussian' | |
43 x(rand_indices(1:K)) = sigma*randn(K,1); % Normal distribution ~ N(0,sigma^2) | |
44 case 'Uniform' | |
45 x(rand_indices(1:K)) = rand(K,1); % Uniform [0,1] distribution | |
46 case 'Bernoulli' | |
47 x(rand_indices(1:K)) = (-1).^round(rand(K,1)); % Bernoulli ~ (1/2, 1/2) distribution | |
48 case 'pBernoulli' | |
49 x(rand_indices(1:K)) = (-1).^(rand(K,1) > p); % Bernoulli ~ (p, 1-p) distribution | |
50 end; | |
51 | |
52 x = x/norm(x); |