// =========================================================================== // // Filename: utlogbarriercg.cpp // // Created: 12/29/2010 09:40:23 AM // Compiler: Tested with g++, icpc, and MSVC 2010 // // Author: Trevor Irons (ti) // // Organisation: Colorado School of Mines (CSM) // United States Geological Survey (USGS) // // Email: tirons@mines.edu, tirons@usgs.gov // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // =========================================================================== /** @file @author Trevor Irons @date 12/29/2010 @version 0.0 **/ #include "LemmaObject.h" //#include "logbarriercg.h" //#include "datasnmr.h" #include #ifdef HAVEBOOSTRANDOM #include #include #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); /// test driver program for log-barrier optimization algorithm int main() { return 0; } #ifdef AA // Parameters Real T2(.200); Real Larmor(2000); // Hz Real wL = 2.*PI * Larmor; Real T(.6); Real dt(1e-4); int nT2(20); Real T2Low(.020); Real T2Hi(.220); // T2 bins VectorXr T2Bins = VectorXr::LinSpaced(nT2, T2Low, T2Hi); // Build true model VectorXr m = VectorXr::Zero(T2Bins.size()); //m[4] = .15; //m[5] = .15; //m[6] = .15; m[7] = .15; m[8] = .15; m[11] = .15; m[12] = .15; m[13] = .15; m[14] = .15; // Build G 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 (std::time(0))); boost::normal_distribution noise(mean, variance); boost::variate_generator > nD(randgen, noise); VectorXr noisy = G*m; // for (int i=0; i < noisy.size(); ++i) { // noisy(i) += nD(); // } #else VectorXr d = G * m; VectorXr noisy = d.array();// + .05*( .5 + .15 ) *Eigen::ArrayXd::Random(d.size()); #endif // Clean Data, and 10% random noise data VectorXr RefMod = VectorXr::Zero(m.size()); // todo let alpha's be set. Real alpha_s = .0; Real alpha_t2 = 1.0; Eigen::SparseMatrix Wd (G.rows(), G.rows()); Eigen::SparseMatrix Wm (G.cols(), G.cols()); ///////////////// // Model objective function int ii = 0; for (int iT2=0; iT2 fft; // fft.SetFlag(fft.HalfSpectrum); // VectorXcr dw; // fft.fwd(dw, noisy); // // // Compute freqs Hz // VectorXr freqs = DataSNMR::GetNMRSampledFrequencies(T/dt, dt); // Real df = freqs[1]; // Real window = 300; // Hz // int iL = (int)(Larmor/df); // MatrixXr Gw = BuildGw(T2, wL, T, dt, T2Bins, scale, freqs.segment(iL-window/2, window)); // // VectorXr dwu = VectorXr::Zero(2.*window); // dwu.head(window) = dw.segment(iL-window/2, window).real(); // dwu.tail(window) = dw.segment(iL-window/2, window).imag(); // // Eigen::DynamicSparseMatrix Wdw (Gw.rows(), Gw.rows()); // for (int id=0; id