/* The Evolving Distribution Objects framework (EDO) is a template-based, ANSI-C++ evolutionary computation library which helps you to write your own estimation of distribution algorithms. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Copyright (C) 2010 Thales group */ /* Authors: Johann Dréo */ //#include #include #include #include #include #include #include #include #include #include typedef eoReal< eoMinimizingFitness > EOT; typedef edoNormalMulti EOD; void setformat( std::ostream& out ) { out << std::right; out << std::setfill(' '); out << std::setw( 5 + std::numeric_limits::digits10); out << std::setprecision(std::numeric_limits::digits10); out << std::setiosflags(std::ios_base::showpoint); } template std::string format(const MT& mat ) { std::ostringstream out; setformat(out); for( unsigned int i=0; i T round( T val, T prec = 1.0 ) { return (val > 0.0) ? floor(val * prec + 0.5) / prec : ceil(val * prec - 0.5) / prec ; } template bool equal( const MT& M1, const MT& M2, double prec /* = 1/std::numeric_limits::digits10 ???*/ ) { if( M1.size1() != M2.size1() || M1.size2() != M2.size2() ) { return false; } for( unsigned int i=0; i= 4 ) { // precision = std::atof(argv[3]); // } // std::cout << "precision = " << precision << std::endl; // std::cout << "usage: t-cholesky [N] [precision]" << std::endl; // std::cout << "N = " << N << std::endl; // std::cout << "precision = " << precision << std::endl; // std::string linesep = "--------------------------------------------------------------------------------------------"; // std::cout << linesep << std::endl; // // setformat(std::cout); // // std::cout << "Covariance matrix" << std::endl << format(V) << std::endl; // std::cout << linesep << std::endl; // // edoSamplerNormalMulti::Cholesky LLT( edoSamplerNormalMulti::Cholesky::standard ); // FactorMat L0 = LLT(V); // CovarMat V0 = ublas::prod( L0, ublas::trans(L0) ); // CovarMat E0 = error(V,V0); // std::cout << "LLT" << std::endl << format(E0) << std::endl; // std::cout << trigsum(E0) << std::endl; // std::cout << "LLT" << std::endl << format(L0) << std::endl; // std::cout << "LLT covar" << std::endl << format(V0) << std::endl; // assert( equal(V0,V,precision) ); // std::cout << linesep << std::endl; // // edoSamplerNormalMulti::Cholesky LLTa( edoSamplerNormalMulti::Cholesky::absolute ); // FactorMat L1 = LLTa(V); // CovarMat V1 = ublas::prod( L1, ublas::trans(L1) ); // CovarMat E1 = error(V,V1); // std::cout << "LLT abs" << std::endl << format(E1) << std::endl; // std::cout << trigsum(E1) << std::endl; // std::cout << "LLT abs" << std::endl << format(L1) << std::endl; // std::cout << "LLT covar" << std::endl << format(V1) << std::endl; // assert( equal(V1,V,precision) ); // std::cout << linesep << std::endl; // // edoSamplerNormalMulti::Cholesky LDLT( edoSamplerNormalMulti::Cholesky::robust ); // FactorMat L2 = LDLT(V); // CovarMat V2 = ublas::prod( L2, ublas::trans(L2) ); // CovarMat E2 = error(V,V2); // std::cout << "LDLT" << std::endl << format(E2) << std::endl; // std::cout << trigsum(E2) << std::endl; // std::cout << "LDLT" << std::endl << format(L2) << std::endl; // std::cout << "LDLT covar" << std::endl << format(V2) << std::endl; // assert( equal(V2,V,precision) ); // std::cout << linesep << std::endl; }