Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random permutation matrix

Is there an easy way to simulate a random permutation matrix (say of size 1000 by 1000) in Matlab? I would like to study the eigenvalue distribution of independent sum of such matrices.

Thanks in advance!

like image 862
Nguyen Huu Hoi Avatar asked Jan 17 '13 14:01

Nguyen Huu Hoi


People also ask

How do you generate a random permutation matrix in Matlab?

p = randperm( n ) returns a row vector containing a random permutation of the integers from 1 to n without repeating elements. p = randperm( n , k ) returns a row vector containing k unique integers selected randomly from 1 to n .

What is a permutation of a matrix?

A permutation matrix is a matrix obtained by permuting the rows of an identity matrix according to some permutation of the numbers 1 to . Every row and column therefore contains precisely a single 1 with 0s everywhere else, and every permutation corresponds to a unique permutation matrix.


1 Answers

You can generate a random permutation matrix like so:

  1. Create a unity matrix:

    A = eye( N );  %// N is the size of your matrix
    

    For large values of N it is better to use sparse matrices:

    A = speye( N ); % create sparse identity matrix
    
  2. Generate a random permutation:

    idx = randperm(1:N);
    
  3. Use vector indexing to rearrange the rows accordingly

    A = A(idx, :);
    

Voila!

like image 189
Eitan T Avatar answered Oct 11 '22 13:10

Eitan T