bug fixed

This commit is contained in:
Caner Candan 2010-08-17 17:44:53 +02:00
commit fd41360304
2 changed files with 29 additions and 19 deletions

View file

@ -13,7 +13,7 @@ public:
public: public:
typedef typename EOT::AtomType AtomType; typedef typename EOT::AtomType AtomType;
void update( const eoPop< EOT >& pop ) CovMatrix( const eoPop< EOT >& pop )
{ {
unsigned int p_size = pop.size(); // population size unsigned int p_size = pop.size(); // population size
@ -41,7 +41,7 @@ public:
// positive), thus a triangular storage is sufficient // positive), thus a triangular storage is sufficient
//------------------------------------------------------------- //-------------------------------------------------------------
ublas::symmetric_matrix< AtomType, ublas::lower > var(s_size, s_size); //ublas::symmetric_matrix< AtomType, ublas::lower > var; //(s_size, s_size);
//------------------------------------------------------------- //-------------------------------------------------------------
@ -50,20 +50,33 @@ public:
// variance-covariance matrix computation : A * transpose(A) // variance-covariance matrix computation : A * transpose(A)
//------------------------------------------------------------- //-------------------------------------------------------------
var = ublas::prod( sample, ublas::trans( sample ) ); //ublas::matrix< AtomType > var = ublas::prod( sample, ublas::trans( sample ) );
//ublas::symmetric_matrix< AtomType, ublas::lower > var = ublas::prod( sample, ublas::trans( sample ) );
ublas::symmetric_matrix< AtomType, ublas::lower > var = ublas::prod( ublas::trans( sample ), sample );
assert(var.size1() == s_size);
assert(var.size2() == s_size);
assert(var.size1() == _varcovar.size1());
assert(var.size2() == _varcovar.size2());
std::cout << "_varcovar: " << _varcovar << std::endl;
std::cout << "var: " << var << std::endl;
//------------------------------------------------------------- //-------------------------------------------------------------
for (unsigned int i = 0; i < s_size; ++i) // for (unsigned int i = 0; i < s_size; ++i)
{ // {
// triangular LOWER matrix, thus j is not going further than i // // triangular LOWER matrix, thus j is not going further than i
for (unsigned int j = 0; j <= i; ++j) // for (unsigned int j = 0; j <= i; ++j)
{ // {
// we want a reducted covariance matrix // // we want a reducted covariance matrix
_varcovar(i, j) = var(i, j) / p_size; // std::cout << "i " << i << " j " << j << std::endl;
} // _varcovar(i, j) = var(i, j) / p_size;
} // }
// }
_varcovar = var / p_size;
_mean.resize(s_size); _mean.resize(s_size);
@ -97,9 +110,7 @@ public:
unsigned int dimsize = pop[0].size(); unsigned int dimsize = pop[0].size();
assert(dimsize > 0); assert(dimsize > 0);
CovMatrix cov; CovMatrix cov( pop );
cov.update(pop);
return doNormalMulti< EOT >( cov.get_mean(), cov.get_varcovar() ); return doNormalMulti< EOT >( cov.get_mean(), cov.get_varcovar() );
} }

View file

@ -25,7 +25,7 @@ public:
class Cholesky class Cholesky
{ {
public: public:
void update( const ublas::symmetric_matrix< AtomType, ublas::lower >& V) Cholesky( const ublas::symmetric_matrix< AtomType, ublas::lower >& V)
{ {
unsigned int Vl = V.size1(); unsigned int Vl = V.size1();
@ -66,7 +66,7 @@ public:
sum += _L(i, k) * _L(i, k); sum += _L(i, k) * _L(i, k);
} }
assert( ( V(i, i) - sum ) > 0 ); // assert( ( V(i, i) - sum ) > 0 );
//_L(i, i) = sqrt( V(i, i) - sum ); //_L(i, i) = sqrt( V(i, i) - sum );
@ -112,8 +112,7 @@ public:
// L = cholesky decomposition of varcovar // L = cholesky decomposition of varcovar
//------------------------------------------------------------- //-------------------------------------------------------------
Cholesky cholesky; Cholesky cholesky( distrib.varcovar() );
cholesky.update( distrib.varcovar() );
ublas::symmetric_matrix< AtomType, ublas::lower > L = cholesky.get_L(); ublas::symmetric_matrix< AtomType, ublas::lower > L = cholesky.get_L();
//------------------------------------------------------------- //-------------------------------------------------------------