commit with an issue at runtime: Assertion failed in file /usr/include/boost/numeric/ublas/symmetric.hpp at line 163

This commit is contained in:
Caner Candan 2010-08-04 13:05:28 +02:00
commit 9ac22d7515
7 changed files with 58 additions and 28 deletions

View file

@ -24,7 +24,7 @@ public:
cov.update(pop);
return doNormal< EOT >(cov.get_mean(), cov.get_varcovar());
return doNormal< EOT >( cov.get_mean(), cov.get_varcovar() );
}
};

View file

@ -10,7 +10,7 @@ class doNormal : public doDistrib< EOT >, public doNormalParams< EOT >
public:
typedef typename EOT::AtomType AtomType;
doNormal( const EOT& mean, const ublas::symmetric_matrix< AtomType, ublas::lower >& varcovar )
doNormal( const ublas::vector< AtomType >& mean, const ublas::symmetric_matrix< AtomType, ublas::lower >& varcovar )
: doNormalParams< EOT >( mean, varcovar )
{}
};

View file

@ -12,7 +12,9 @@ public:
void operator() ( doNormal< EOT >& distrib, EOT& mass )
{
distrib.mean() = mass; // vive les references!!!
ublas::vector< AtomType > mean( distrib.size() );
std::copy( mass.begin(), mass.end(), mean.begin() );
distrib.mean() = mean;
}
};

View file

@ -12,7 +12,11 @@ class doNormalParams
public:
typedef typename EOT::AtomType AtomType;
doNormalParams(const EOT& mean, const ublas::symmetric_matrix< AtomType, ublas::lower >& varcovar)
doNormalParams
(
const ublas::vector< AtomType >& mean,
const ublas::symmetric_matrix< AtomType, ublas::lower >& varcovar
)
: _mean(mean), _varcovar(varcovar)
{
assert(_mean.size() > 0);
@ -20,7 +24,7 @@ public:
assert(_mean.size() == _varcovar.size2());
}
EOT& mean(){return _mean;}
ublas::vector< AtomType >& mean(){return _mean;}
ublas::symmetric_matrix< AtomType, ublas::lower >& varcovar(){return _varcovar;}
unsigned int size()
@ -31,7 +35,7 @@ public:
}
private:
EOT _mean;
ublas::vector< AtomType > _mean;
ublas::symmetric_matrix< AtomType, ublas::lower > _varcovar;
};

View file

@ -30,36 +30,61 @@ public:
assert(size > 0);
//-------------------------------------------------------------
// Point we want to sample to get higher a set of points
// (coordinates in n dimension)
// x = {x1, x2, ..., xn}
// Cholesky factorisation gererating matrix L from covariance
// matrix V.
// We must use cholesky.get_L() to get the resulting matrix.
//
// L = cholesky decomposition of varcovar
//-------------------------------------------------------------
EOT solution;
Cholesky< EOT > cholesky;
cholesky.update( distrib.varcovar() );
ublas::symmetric_matrix< AtomType, ublas::lower > L = cholesky.get_L();
//-------------------------------------------------------------
//-------------------------------------------------------------
// Sampling all dimensions
// T = vector of size elements drawn in N(0,1) rng.normal(1.0)
//-------------------------------------------------------------
for (unsigned int i = 0; i < size; ++i)
ublas::vector< AtomType > T( size );
for ( unsigned int i = 0; i < size; ++i )
{
Cholesky< EOT > cholesky;
cholesky.update( distrib.varcovar() );
// solution.push_back(
// rng.normal(distrib.mean()[i],
// distrib.varcovar()[i])
// );
//rng.normal() +
T( i ) = rng.normal( 1.0 );
}
//-------------------------------------------------------------
//-------------------------------------------------------------
// LT = prod( L, trans(T) ) ?
// LT = prod( L, T )
//-------------------------------------------------------------
//ublas::symmetric_matrix< AtomType, ublas::lower > LT = ublas::prod( L, ublas::trans( T ) );
ublas::vector< AtomType > LT = ublas::prod( L, T );
//-------------------------------------------------------------
//-------------------------------------------------------------
// solution = means + trans( LT ) ?
// solution = means + LT
//-------------------------------------------------------------
ublas::vector< AtomType > mean = distrib.mean();
ublas::vector< AtomType > ublas_solution = mean + LT;
//ublas::vector< AtomType > ublas_solution = mean + ublas::trans( LT );
EOT solution( size );
std::copy( ublas_solution.begin(), ublas_solution.end(), solution.begin() );
//-------------------------------------------------------------
return solution;
}
};

View file

@ -20,8 +20,10 @@ public:
unsigned int size = distrib.size();
assert(size > 0);
//-------------------------------------------------------------
// Point we want to sample to get higher a population
// Point we want to sample to get higher a set of points
// (coordinates in n dimension)
// x = {x1, x2, ..., xn}
//-------------------------------------------------------------

View file

@ -170,22 +170,19 @@ public:
ublas::scalar_vector< AtomType > u( p_size, 1 );
// sum over columns
ublas::vector< AtomType > mean = ublas::prod( ublas::trans( sample ), u );
_mean = ublas::prod( ublas::trans( sample ), u );
// division by n
mean /= p_size;
// copy results in the params std::vector
std::copy(mean.begin(), mean.end(), _mean.begin());
_mean /= p_size;
}
const ublas::symmetric_matrix< AtomType, ublas::lower >& get_varcovar() const {return _varcovar;}
const EOT& get_mean() const {return _mean;}
const ublas::vector< AtomType >& get_mean() const {return _mean;}
private:
ublas::symmetric_matrix< AtomType, ublas::lower > _varcovar;
EOT _mean;
ublas::vector< AtomType > _mean;
};
template < typename EOT >