Compare commits
4 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e31c1e72fb | ||
|
|
cfd0579a4a | ||
|
|
9725d5efd1 | ||
|
|
1475e2a743 |
3 changed files with 26 additions and 8 deletions
|
|
@ -9,8 +9,11 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
|
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
|
||||||
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
|
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
|
||||||
|
|
||||||
|
INCLUDE_DIRECTORIES("/usr/include/")
|
||||||
|
LINK_DIRECTORIES("/usr/lib/")
|
||||||
|
|
||||||
ADD_DEFINITIONS( -Wall -W -Wextra )
|
ADD_DEFINITIONS( -Wall -W -Wextra )
|
||||||
|
|
||||||
ADD_EXECUTABLE(test test.cpp)
|
ADD_EXECUTABLE(test test.cpp)
|
||||||
TARGET_LINK_LIBRARIES(test ${Boost_LIBRARIES})
|
TARGET_LINK_LIBRARIES(test ${Boost_LIBRARIES} gmpxx)
|
||||||
|
|
||||||
|
|
|
||||||
14
cholesky.h
14
cholesky.h
|
|
@ -55,6 +55,9 @@ public:
|
||||||
// FIXME check if triangular types behaviour is like having 0
|
// FIXME check if triangular types behaviour is like having 0
|
||||||
typedef ublas::matrix< T > FactorMat;
|
typedef ublas::matrix< T > FactorMat;
|
||||||
|
|
||||||
|
//! The type of the scalars
|
||||||
|
typedef T AtomType;
|
||||||
|
|
||||||
/** Instanciate without computing anything, you are responsible of
|
/** Instanciate without computing anything, you are responsible of
|
||||||
* calling the algorithm and getting the result with operator()
|
* calling the algorithm and getting the result with operator()
|
||||||
* */
|
* */
|
||||||
|
|
@ -205,7 +208,8 @@ public:
|
||||||
inline virtual T L_i_i( const typename Cholesky<T>::CovarMat& V, const unsigned int& i, const T& sum ) const
|
inline virtual T L_i_i( const typename Cholesky<T>::CovarMat& V, const unsigned int& i, const T& sum ) const
|
||||||
{
|
{
|
||||||
/***** ugly hack *****/
|
/***** ugly hack *****/
|
||||||
return sqrt( fabs( V(i,i) - sum) );
|
//return sqrt( fabs( V(i,i) - sum) );
|
||||||
|
return sqrt( abs( V(i,i) - sum) );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -322,8 +326,8 @@ public:
|
||||||
T sum = 0.0;
|
T sum = 0.0;
|
||||||
// for( unsigned int k=1; k<i-1; ++k) {
|
// for( unsigned int k=1; k<i-1; ++k) {
|
||||||
// for( unsigned int k=1; k<i; ++k) {
|
// for( unsigned int k=1; k<i; ++k) {
|
||||||
for( unsigned int k=0; k<i; ++k) {
|
// for( unsigned int k=0; k<i; ++k) {
|
||||||
// for( unsigned int k=0; k<i-1; ++k) {
|
for( unsigned int k=0; k<i-1; ++k) {
|
||||||
sum += this->_L(i, k) * this->_L(i, k);
|
sum += this->_L(i, k) * this->_L(i, k);
|
||||||
}
|
}
|
||||||
this->_L(i,i) = this->_L(i,i) - sum;
|
this->_L(i,i) = this->_L(i,i) - sum;
|
||||||
|
|
@ -338,8 +342,8 @@ public:
|
||||||
sum = 0.0;
|
sum = 0.0;
|
||||||
// for( unsigned int k = 1; k < i-1; ++k ) {
|
// for( unsigned int k = 1; k < i-1; ++k ) {
|
||||||
// for( unsigned int k = 1; k < i; ++k ) {
|
// for( unsigned int k = 1; k < i; ++k ) {
|
||||||
for( unsigned int k = 0; k < i; ++k ) {
|
// for( unsigned int k = 0; k < i; ++k ) {
|
||||||
// for( unsigned int k = 0; k < i-1; ++k ) {
|
for( unsigned int k = 0; k < i-1; ++k ) {
|
||||||
sum += this->_L(j, k) * this->_L(i, k);
|
sum += this->_L(j, k) * this->_L(i, k);
|
||||||
}
|
}
|
||||||
this->_L(j,i) = this->_L(j,i) - sum;
|
this->_L(j,i) = this->_L(j,i) - sum;
|
||||||
|
|
|
||||||
15
test.cpp
15
test.cpp
|
|
@ -28,6 +28,8 @@ Authors:
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <gmpxx.h>
|
||||||
|
|
||||||
#include "cholesky.h"
|
#include "cholesky.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -112,7 +114,8 @@ T trigsum( const MT& M )
|
||||||
T sum = 0;
|
T sum = 0;
|
||||||
for( unsigned int i=0; i<M.size1(); ++i ) {
|
for( unsigned int i=0; i<M.size1(); ++i ) {
|
||||||
for( unsigned int j=i; j<M.size2(); ++j ) { // triangular browsing
|
for( unsigned int j=i; j<M.size2(); ++j ) { // triangular browsing
|
||||||
sum += fabs( M(i,j) ); // absolute deviation
|
//sum += fabs( M(i,j) ); // absolute deviation
|
||||||
|
sum += abs( M(i,j) ); // absolute deviation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
|
|
@ -165,7 +168,9 @@ void test( unsigned int M, unsigned int N, unsigned int F, unsigned int R, unsig
|
||||||
// a variance-covariance matrix of size N*N
|
// a variance-covariance matrix of size N*N
|
||||||
// Note: a covariance matrix is necessarily semi-positive definite
|
// Note: a covariance matrix is necessarily semi-positive definite
|
||||||
// thus, any failure in the Cholesky factorization is due to round-off errors
|
// thus, any failure in the Cholesky factorization is due to round-off errors
|
||||||
CovarMat V = ublas::prod( ublas::trans(S), S );
|
//CovarMat V = ublas::prod( ublas::trans(S), S );
|
||||||
|
CovarMat ST = ublas::trans(S);
|
||||||
|
CovarMat V = ublas::prod( ST, S );
|
||||||
assert( V.size1() == N && V.size2() == N );
|
assert( V.size1() == N && V.size2() == N );
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if( R == 1 ) {
|
if( R == 1 ) {
|
||||||
|
|
@ -238,6 +243,7 @@ int main(int argc, char** argv)
|
||||||
std::clog << "Legend:" << std::endl;
|
std::clog << "Legend:" << std::endl;
|
||||||
std::clog << "\tAlgo: (failures/runs)\tAverage error" << std::endl;
|
std::clog << "\tAlgo: (failures/runs)\tAverage error" << std::endl;
|
||||||
|
|
||||||
|
/*
|
||||||
std::cout << std::endl << "FLOAT" << std::endl;
|
std::cout << std::endl << "FLOAT" << std::endl;
|
||||||
test<float>(M,N,F,R,seed);
|
test<float>(M,N,F,R,seed);
|
||||||
|
|
||||||
|
|
@ -246,5 +252,10 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
std::cout << std::endl << "LONG DOUBLE" << std::endl;
|
std::cout << std::endl << "LONG DOUBLE" << std::endl;
|
||||||
test<long double>(M,N,F,R,seed);
|
test<long double>(M,N,F,R,seed);
|
||||||
|
*/
|
||||||
|
|
||||||
|
std::cout << std::endl << "MPF 128" << std::endl;
|
||||||
|
mpf_set_default_prec(128);
|
||||||
|
test<mpf_class>(M,N,F,R,seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue