| 40 | } |
| 41 | |
| 42 | mat egiw::sample_mat(int n) const { |
| 43 | // TODO - correct approach - convert to product of norm * Wishart |
| 44 | mat M; |
| 45 | ldmat Vz; |
| 46 | ldmat Lam; |
| 47 | factorize(M,Vz,Lam); |
| 48 | |
| 49 | chmat ChLam(Lam.to_mat()); |
| 50 | chmat iChLam; |
| 51 | ChLam.inv(iChLam); |
| 52 | |
| 53 | eWishartCh Omega; //inverse Wishart, result is R, |
| 54 | Omega.set_parameters(iChLam,nu-2*nPsi-dimx); // 2*nPsi is there to match numercial simulations - check if analytically correct |
| 55 | |
| 56 | mat OmChi; |
| 57 | mat Z(M.rows(),M.cols()); |
| 58 | |
| 59 | mat Mi; |
| 60 | mat RChiT; |
| 61 | mat tmp(dimension(), n); |
| 62 | for (int i=0; i<n;i++){ |
| 63 | OmChi=Omega.sample_mat(); |
| 64 | RChiT=inv(OmChi); |
| 65 | Z=randn(M.rows(), M.cols()); |
| 66 | Mi = M + RChiT * Z * inv(Vz._L().T() *diag(sqrt(Vz._D()))); |
| 67 | |
| 68 | tmp.set_col(i,concat (cvectorize(Mi),cvectorize(RChiT*RChiT.T()))); |
| 69 | } |
| 70 | return tmp; |