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