inline bool hess ( Mat<typename T1::elem_type>& U, Mat<typename T1::elem_type>& H, const Base<typename T1::elem_type,T1>& X, const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( void_ptr(&U) == void_ptr(&H), "hess(): 'U' is an alias of 'H'" ); typedef typename T1::elem_type eT; Col<eT> tao; const bool status = auxlib::hess(H, X.get_ref(), tao); if(H.n_rows == 0) { U.reset(); } else if(H.n_rows == 1) { U.ones(1, 1); } else if(H.n_rows == 2) { U.eye(2, 2); } else { U.eye(size(H)); Col<eT> v; for(uword i=0; i < H.n_rows-2; ++i) { // TODO: generate v in a more efficient manner; // TODO: the .ones() operation is an overkill, as most of v is overwritten afterwards v.ones(H.n_rows-i-1); v(span(1, H.n_rows-i-2)) = H(span(i+2, H.n_rows-1), i); U(span::all, span(i+1, H.n_rows-1)) -= tao(i) * (U(span::all, span(i+1, H.n_rows-1)) * v * v.t()); } U(span::all, H.n_rows-1) = U(span::all, H.n_rows-1) * (eT(1) - tao(H.n_rows-2)); for(uword i=0; i < H.n_rows-2; ++i) { H(span(i+2, H.n_rows-1), i).zeros(); } } if(status == false) { U.soft_reset(); H.soft_reset(); arma_debug_warn("hess(): decomposition failed"); } return status; }
//Class constructor TimeSegmentation(Tobj &G, Col <T1> map_in, Col <T1> timeVec_in, uword a, uword b, uword c, uword interptype = 1, uword shots = 1) { cout << "Entering Class constructor" << endl; n1 = a; //Data size n2 = b;//Image size L = c; //number of time segments type = interptype; // type of time segmentation performed Nshots = shots; // number of shots obj = &G; fieldMap = map_in; cout << "N1 = " << n1 << endl; cout << "N2 = " << n2 << endl; cout << "L = " << L << endl; AA.set_size(n1, L); //time segments weights timeVec = timeVec_in; T_min =timeVec.min(); T1 rangt = timeVec.max()-T_min; tau = (rangt + datum::eps) / (L - 1); // it was L-1 before timeVec = timeVec-T_min; uword NOneShot = n1/Nshots; if (L==1) { tau = 0; AA.ones(); } else { Mat <CxT1> tempAA(NOneShot, L); if (type==1) {// Hanning interpolator cout << "Hanning interpolation" << endl; for (unsigned int ii = 0; ii<L; ii++) { for (unsigned int jj = 0; jj<NOneShot; jj++) { if ((std::abs(timeVec(jj)-((ii)*tau)))<=tau) { tempAA(jj, ii) = 0.5+0.5*std::cos((datum::pi)*(timeVec(jj)-((ii)*tau))/tau); } else { tempAA(jj, ii) = 0.0; } } } AA = repmat(tempAA, Nshots, 1); } else if (type==2) { // Min-max interpolator: Exact LS interpolator cout << "Min Max time segmentation" << endl; Mat <CxT1> Ltp; Ltp.ones(1, L); Col <CxT1> ggtp; ggtp.ones(n2, 1); Mat <CxT1> gg; gg = exp(i*fieldMap*tau)*Ltp; Mat <CxT1> iGTGGT; iGTGGT.set_size(L+1, n2); Mat <CxT1> gl; gl.zeros(n2, L); for (unsigned int ii = 0; ii<L; ii++) { for (unsigned int jj = 0; jj<n2; jj++) { gl(jj, ii) = pow(gg(jj, ii), (T1) (ii+1)); } } Mat <CxT1> G; G.set_size(n2, L); for (unsigned int jj = 0; jj<L; jj++) { if (jj==0) { G.col(jj) = ggtp; } else { G.col(jj) = gl.col(jj-1); } } Col <CxT1> glsum; Mat <CxT1> GTG; GTG.zeros(L, L); GTG.diag(0) += n2; glsum = sum(gl.t(), 1); Mat <CxT1> GTGtp(L, L); for (unsigned int ii = 0; ii < (L - 1); ii++) { GTGtp.zeros(); GTGtp.diag(-(T1) (ii+1)) += glsum(ii); GTGtp.diag((T1) (ii+1)) += std::conj(glsum(ii)); GTG = GTG+GTGtp; } T1 rcn = 1/cond(GTG); if (rcn>10*2e-16) { //condition number of GTG iGTGGT = inv(GTG)*G.t(); } else { iGTGGT = pinv(GTG)*G.t(); // pseudo inverse } Mat <CxT1> iGTGGTtp; Mat <CxT1> ftp; Col <CxT1> res, temp; for (unsigned int ii = 0; ii<NOneShot; ii++) { ftp = exp(i*fieldMap*timeVec(ii)); res = iGTGGT*ftp; tempAA.row(ii) = res.t(); } AA = repmat(tempAA, Nshots, 1); } } savemat("aamat.mat", "AA", vectorise(AA)); cout << "Exiting class constructor." << endl; }
void expectedColOnes() { cout << "- Compute expectedColOnes() ... "; Col<double> expected = _genColVec; save<double>("Col.ones", (expected.ones())); cout << "done." << endl; }
int DWIRecon(string dataPath, uword Nx, uword Ny, uword Nz, uword L, uword niter, uword nc) { string testPath = dataPath; typedef complex<T1> CxT1; //uword Nx =64; //uword Ny =64; //uword Nz =16; //Setup image space coordinates/trajectory Cube<T1> ix(Nx, Ny, Nz); Cube<T1> iy(Nx, Ny, Nz); Cube<T1> iz(Nx, Ny, Nz); Col < T1 > FM; Col < CxT1 > SMap; Col < T1 > PMap; ix.zeros(); iy.zeros(); iz.zeros(); //generate the image space coordinates of the voxels we want to reconstruct // after vectorizing ix and iy the image coordinates must match the Field and SENSe map image coordinates for (uword ii = 0; ii < Ny; ii++) { //y for (uword jj = 0; jj < Nx; jj++) { //x for (uword kk = 0; kk < Nz; kk++) { //z ix(ii, jj, kk) = ((T1) jj - (T1) Nx / 2.0) / ((T1) Nx); iy(ii, jj, kk) = ((T1) ii - (T1) Ny / 2.0) / ((T1) Ny); iz(ii, jj, kk) = ((T1) kk - (T1) Nz / 2.0) / ((T1) Nz); } } } Col < T1 > kx; loadmat(testPath + "kx.mat", "kx", &kx); Col < T1 > ky; loadmat(testPath + "ky.mat", "ky", &ky); Col < T1 > kz; loadmat(testPath + "kz.mat", "kz", &kz); uword nro; nro = kx.n_elem; Col < T1 > tvec; loadmat(testPath + "t.mat", "t", &tvec); loadmat(testPath + "FM.mat", "FM", &FM); //FM.zeros(); loadmat(testPath + "SMap.mat", "SMap", &SMap); //nonlinear motion correction for DWI loadmat(testPath + "PMap.mat", "PMap", &PMap); //The navigator phase is being referenced to zero pcSENSE<T1> S_DWI(kx, ky, kz, Nx, Ny, Nz, nc, tvec, SMap, vectorise(FM), 0 - PMap); cout << "loading data" << endl; Col < CxT1 > data; data = 1E-6 * data; loadmat(testPath + "data.mat", "data", &data); // Variables needed for the recon: Penalty object, num of iterations cout << "Iniitalizing QuadPenalty" << endl; QuadPenalty < T1 > R(Nx, Ny, Nz, 0.0); cout << "QuadPenalty setup successfull" << endl; //uword niter = 10; Col < CxT1 > xinit(Nx * Ny * Nz); // initial estimate of x xinit.zeros(); Col < T1 > W; //W = eye<sp_mat<T1>>(A.n1,A.n1); // Should be the size of k-space data: Is it right? //W=1.0; W.ones(nro * nc); cout << "Runing pwls with Gnufft" << endl; Col < CxT1 > test_DWI_img; test_DWI_img = solve_pwls_pcg<T1, pcSENSE<T1>, QuadPenalty<T1 >>(xinit, S_DWI, W, data, R, niter); savemat(testPath + "test_DWICGMC.mat", "img", test_DWI_img); return 0; }