2007-09-25 18:25:25 +02:00
|
|
|
function B = rand_matrix_normal(n, p, M, Omega_lower_chol, Sigma_lower_chol)
|
|
|
|
% rand_matrix_normal Pseudo random matrices drawn from a
|
|
|
|
% matrix-normal distribution
|
|
|
|
%
|
|
|
|
% B = rand_matrix_normal(n, p, M, Omega_lower_chol, Sigma_lower_chol)
|
|
|
|
%
|
|
|
|
% Returns an n-by-p matrix drawn from a Matrix-normal distribution
|
2007-09-28 15:43:21 +02:00
|
|
|
%
|
|
|
|
% B ~ MN_n*p(M, Omega, Sigma)
|
|
|
|
%
|
|
|
|
% Equivalent to vec(B) ~ N(vec(Mu), kron(Omega, Sigma))
|
|
|
|
%
|
2007-09-25 18:25:25 +02:00
|
|
|
% Same notations than: http://en.wikipedia.org/wiki/Matrix_normal_distribution
|
2007-09-28 15:43:21 +02:00
|
|
|
%
|
2007-09-25 18:25:25 +02:00
|
|
|
% M is the mean, n-by-p matrix
|
2007-09-28 15:43:21 +02:00
|
|
|
% Omega_lower_chol is p-by-p, lower Cholesky decomposition of Omega
|
2007-09-25 18:25:25 +02:00
|
|
|
% (Omega_lower_chol = chol(Omega, 'lower'))
|
2007-09-28 15:43:21 +02:00
|
|
|
% Sigma_lower_chol is n-by-n, lower Cholesky decomposition of Sigma
|
2007-09-25 18:25:25 +02:00
|
|
|
% (Sigma_lower_chol = chol(Sigma, 'lower'))
|
|
|
|
|
|
|
|
B1 = randn(n * p, 1);
|
2007-09-28 15:43:21 +02:00
|
|
|
B2 = kron(Omega_lower_chol, Sigma_lower_chol) * B1;
|
2007-09-25 18:25:25 +02:00
|
|
|
B3 = reshape(B2, n, p);
|
2007-09-28 15:43:21 +02:00
|
|
|
B = B3 + M;
|