/************************************************************************* Copyright Rice University, 2011. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, provided that the above copyright notice(s) and this permission notice appear in all copies of the Software and that both the above copyright notice(s) and this permission notice appear in supporting documentation. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Except as contained in this notice, the name of a copyright holder shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization of the copyright holder. **************************************************************************/ #include "rnmat.hh" #include "adjtest.hh" #include "cgnealg.hh" using namespace RVL; using namespace RVLAlg; using namespace RVLUmin; /** Umin Unit Test 1 Purpose: basic CG alg - scalar type = float */ template void CGNEDiagTest(int rows, int cols, typename ScalarFieldTraits::AbsType _nlvl, // noise level int maxit, typename ScalarFieldTraits::AbsType minsig, // max singular val typename ScalarFieldTraits::AbsType maxsig, // max singular val typename ScalarFieldTraits::AbsType epsilon,// nr error reduction string testno, string datatype, string output, ostream & str) { typedef typename ScalarFieldTraits::AbsType atype; try { str< dom(cols); RnSpace rng(rows); str< A(dom,rng); RVLRandomize rnd; int n = min(cols,rows); atype one = ScalarFieldTraits::One(); for (int i=0;i(A,rnd,strout)) { str<<"*** adjoint test passed - result in "< sol(dom); Vector est(dom); // initialize exact solution to random vector sol.eval(rnd); // initialize estimated solution to zero est.zero(); // create rhs, initialize to noisy version of exact sol image Vector rhs(rng); A.applyOp(sol,rhs); atype rhsnorm = rhs.norm(); Vector err(rng); err.eval(rnd); T nlvl = _nlvl*rhs.norm()/err.norm(); rhs.linComb(nlvl,err); Vector nrhs(rng); A.applyAdjOp(rhs,nrhs); atype nrhsnorm = nrhs.norm(); str<::max(); atype nrnorm = numeric_limits::max(); CGNEAlg iter(est,A,rhs,rnorm,nrnorm,ScalarFieldTraits::Zero(),epsilon,maxit,numeric_limits::max(),strout); // run it iter.run(); // display results atype snorm = sol.norm(); atype enorm = est.norm(); sol.linComb(-ScalarFieldTraits::One(),est); atype relerr=ScalarFieldTraits::One(); if (ProtectedDivision(sol.norm(),snorm,relerr)) { RVLException e; e<<"a-oo-ga! a-oo-ga! solution was zero!!!\n"; throw e; } Vector ATb(A.getDomain()); A.applyAdjOp(rhs,ATb); rhsnorm = ATb.norm(); strout<<"*******************************************************"<(cols,cols,0.0,1000,0.1,1.0,0.001, "0.0","double","./CGNEDiagdbl0.rpt",cout); CGNEDiagTest(cols,cols,0.0,1000,0.1,1.0,0.001, "0.1","double","./CGNEDiagdbl1.rpt",cout); CGNEDiagTest(cols,cols,0.0,1000,0.01,1.0,0.001, "0.2","double","./CGNEDiagdbl2.rpt",cout); CGNEDiagTest(cols,cols,0.0,1000,0.01,1.0,0.001, "0.3","double","./CGNEDiagdbl3.rpt",cout); CGNEDiagTest(cols,cols,0.0,1000,0.0,1.0,0.001, "0.4","double","./CGNEDiagdbl4.rpt",cout); CGNEDiagTest(cols,cols,0.0,1000,0.0,1.0,0.001, "0.5","double","./CGNEDiagdbl5.rpt",cout); } catch (RVLException & e) { e.write(cerr); exit(1); } }