comparison toolboxes/alps/generate_matrix.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 [A] = generate_matrix(M, N, ensemble, p)
2 % =========================================================================
3 % Measerement matrix generator
4 % =========================================================================
5 % INPUT ARGUMENTS:
6 % M Number of measurements (number of rows).
7 % N Size of sparse vector (number of columns).
8 % ensemble Ensemble type of measurement matrix. Possible
9 % values are:
10 % -'Gaussian': creates a MxN measurement matrix with
11 % elements drawn from normal distribution N(0,1).%
12 % -'Bernoulli': creates a MxN measurement matrix with
13 % elements drawn from Bernoulli distribution (1/2,1/2).
14 % -'pBernoulli': creates a MxN measurement matrix with
15 % elements drawn from Bernoulli distribution (p,1-p).
16 % Parameter of Bernoulli distribution.
17 % -'sparseGaussian': creates a MxN sparse measurement
18 % matrix with elements drawn from normal distribution N(0,1).
19 % =========================================================================
20 % OUTPUT ARGUMENTS:
21 % A MxN measurement matrix with normalized columns.
22 % =========================================================================
23 % 01/04/2011, by Anastasios Kyrillidis. anastasios.kyrillidis@epfl.ch, EPFL.
24 % =========================================================================
25 if nargin < 3
26 ensemble = 'Gaussian';
27 end;
28
29 if nargin < 4
30 p = 0.5;
31 end;
32
33 switch ensemble
34 case 'Gaussian'
35 A = randn(M,N); % Standard normal distribution
36 for i = 1:N % Normalize columns
37 A(:,i) = A(:,i)/norm(A(:,i));
38 end;
39 case 'Bernoulli'
40 A = (-1).^round(rand(M,N)); % Bernoulli ~ (1/2, 1/2) distribution
41 for i = 1:N % Normalize columns
42 A(:,i) = A(:,i)/norm(A(:,i));
43 end;
44 case 'pBernoulli'
45 A = (-1).^(rand(M,N) > p); % Bernoulli ~ (p, 1-p) distribution
46 for i = 1:N % Normalize columns
47 A(:,i) = A(:,i)/norm(A(:,i));
48 end;
49 case 'sparseGaussian'
50 leftd = 8;
51 A = zeros(M,N);
52 for i = 1:N
53 ind = randperm(M);
54 A(ind(1:leftd),i)=1/leftd;
55 end
56 for i = 1:N % Normalize columns
57 A(:,i) = A(:,i)/norm(A(:,i));
58 end;
59 end;