123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #include "LemmaObject.h"
-
-
- #include <ctime>
-
- #ifdef HAVEBOOSTRANDOM
- #include <boost/random.hpp>
- #include <boost/random/normal_distribution.hpp>
- #endif
-
- using namespace std;
- using namespace Lemma;
-
- MatrixXr BuildG(const Real& T2, const Real& Larmor, const Real& T,
- const Real& dt, const VectorXr& nT2Bins, const Real& scale);
-
- MatrixXr BuildGw(const Real& T2, const Real& Larmor, const Real& T,
- const Real& dt, const VectorXr& nT2Bins, const Real& scale,
- const VectorXr& freqs);
-
-
- int main() {
- return 0;
- }
-
- #ifdef AA
-
- Real T2(.200);
- Real Larmor(2000);
- Real wL = 2.*PI * Larmor;
- Real T(.6);
- Real dt(1e-4);
- int nT2(20);
- Real T2Low(.020);
- Real T2Hi(.220);
-
-
- VectorXr T2Bins = VectorXr::LinSpaced(nT2, T2Low, T2Hi);
-
-
- VectorXr m = VectorXr::Zero(T2Bins.size());
-
-
-
- m[7] = .15;
- m[8] = .15;
- m[11] = .15;
- m[12] = .15;
- m[13] = .15;
- m[14] = .15;
-
-
- srand ( std::time(NULL) );
- Real scale = 1e-4*std::abs(VectorXr::Random(1)[0]);
- MatrixXr G = BuildG(T2, wL, T, dt, T2Bins, scale);
-
- #ifdef HAVEBOOSTRANDOM
- Real mean = 0;
- Real variance = scale*.05*(.5+.15);
- boost::mt19937 randgen(static_cast<unsigned int> (std::time(0)));
- boost::normal_distribution<Real> noise(mean, variance);
- boost::variate_generator<boost::mt19937, boost::normal_distribution<Real> > nD(randgen, noise);
- VectorXr noisy = G*m;
-
-
-
- #else
- VectorXr d = G * m;
- VectorXr noisy = d.array();
- #endif
-
-
- VectorXr RefMod = VectorXr::Zero(m.size());
-
-
- Real alpha_s = .0;
- Real alpha_t2 = 1.0;
- Eigen::SparseMatrix<Real> Wd (G.rows(), G.rows());
- Eigen::SparseMatrix<Real> Wm (G.cols(), G.cols());
-
-
-
- int ii = 0;
- for (int iT2=0; iT2<nT2; ++iT2) {
- Wm.coeffRef(ii, ii) += alpha_s - alpha_t2;
- if (iT2 < nT2-1) {
- Wm.coeffRef(ii, ii+1) += alpha_t2;
- }
- ++ii;
- }
- Wm.finalize();
- std::fstream WmOut( "wmMatrix.dat" , std::ios::out);
- WmOut << Wm << std::endl;
- WmOut.close();
-
-
-
- for (int id=0; id<G.rows(); ++id) {
- Wd.coeffRef(id, id) = 1.;
- }
- Wd.finalize();
-
-
-
- return EXIT_SUCCESS;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
- #endif
-
- MatrixXr BuildG(const Real& T2, const Real& wL, const Real& T,
- const Real& dt, const VectorXr& T2Bins, const Real& scale) {
- std::cout << "scale " << scale << std::endl;
- int nt = T/dt;
- int nT2 = T2Bins.size();
- MatrixXr G = MatrixXr::Zero(nt,nT2);
- for (int iT2=0; iT2<nT2; ++iT2) {
- Real t=0;
- for (int it=0; it<nt; ++it) {
- G(it, iT2) = scale * exp(-t/T2Bins(iT2)) * sin(wL * t);
- t += dt;
- }
- }
- return G;
- }
-
-
- MatrixXr BuildGw(const Real& T2, const Real& wL, const Real& T,
- const Real& dt, const VectorXr& T2Bins, const Real& scale,
- const VectorXr &freqs) {
- VectorXr omegas = freqs.array() * 2.*PI;
- std::cout << "scale " << scale << std::endl;
- int nT2 = T2Bins.size();
- MatrixXr Gw = MatrixXr::Zero(2*freqs.size(), nT2);
- int nW = freqs.size();
- Real sc = 1./dt;
- for (int iT2=0; iT2<nT2; ++iT2) {
- for (int iw=0; iw<freqs.size(); ++iw) {
- Real a = 1./T2Bins(iT2);
- Complex T = wL / ( wL*wL + (a+Complex(0, omegas[iw]))*(a+Complex(0,omegas[iw])) ) ;
- Gw(iw, iT2) = sc * scale * std::real(T);
- Gw(iw+nW, iT2) = sc * scale * std::imag(T);
- }
- }
- return Gw;
- }
|