Saturday 27 August 2016

linear algebra - Algorithm for generating positive semidefinite matrices



I'm looking for an efficient algorithm to generate large positive semidefinite matrices.



One possible way I know of is:




  • generate a random square matrix

  • multiply it with its transpose.

  • calculate all eigenvalues of the result matrix and check if all of them are non-negative.




However, this approach is infeasible given a large matrix, say $1000 \times 1000$ or more.



Could anyone please suggest an efficient way to generate a positive semidefinite matrix?
Is there any MATLAB function for this job?



Thanks,


Answer



Any matrix multiplied by it's transpose is going to be PSD; you don't have to check it. On my computer raw Octave, without SSE, takes 2 seconds to multiply a 1000x1000 matrix with itself. So not all that infeasible.




If you don't like that, you can always just generate a random diagonal matrix. That's sort of the trivial way, though :) What do you need the matrix for? If it's as test input to another algorithm, I'd just spend some time generating random PSD matrices using the above matrix-matrix multiplication and save the results off to disk.


No comments:

Post a Comment

real analysis - How to find $lim_{hrightarrow 0}frac{sin(ha)}{h}$

How to find $\lim_{h\rightarrow 0}\frac{\sin(ha)}{h}$ without lhopital rule? I know when I use lhopital I easy get $$ \lim_{h\rightarrow 0}...