an intermediate commit to keep updates
This commit is contained in:
parent
1070ec8a32
commit
963d59e706
21 changed files with 649 additions and 556 deletions
109
src/doEstimatorNormalMulti.h
Normal file
109
src/doEstimatorNormalMulti.h
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
#ifndef _doEstimatorNormalMulti_h
|
||||
#define _doEstimatorNormalMulti_h
|
||||
|
||||
#include "doEstimator.h"
|
||||
#include "doUniform.h"
|
||||
#include "doStats.h"
|
||||
|
||||
template < typename EOT >
|
||||
class doEstimatorNormalMulti : public doEstimator< doNormalMulti< EOT > >
|
||||
{
|
||||
public:
|
||||
class CovMatrix
|
||||
{
|
||||
public:
|
||||
typedef typename EOT::AtomType AtomType;
|
||||
|
||||
void update( const eoPop< EOT >& pop )
|
||||
{
|
||||
unsigned int p_size = pop.size(); // population size
|
||||
|
||||
assert(p_size > 0);
|
||||
|
||||
unsigned int s_size = pop[0].size(); // solution size
|
||||
|
||||
assert(s_size > 0);
|
||||
|
||||
ublas::matrix< AtomType > sample( p_size, s_size );
|
||||
|
||||
for (unsigned int i = 0; i < p_size; ++i)
|
||||
{
|
||||
for (unsigned int j = 0; j < s_size; ++j)
|
||||
{
|
||||
sample(i, j) = pop[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
_varcovar.resize(s_size, s_size);
|
||||
|
||||
|
||||
//-------------------------------------------------------------
|
||||
// variance-covariance matrix are symmetric (and semi-definite
|
||||
// positive), thus a triangular storage is sufficient
|
||||
//-------------------------------------------------------------
|
||||
|
||||
ublas::symmetric_matrix< AtomType, ublas::lower > var(s_size, s_size);
|
||||
|
||||
//-------------------------------------------------------------
|
||||
|
||||
|
||||
//-------------------------------------------------------------
|
||||
// variance-covariance matrix computation : A * transpose(A)
|
||||
//-------------------------------------------------------------
|
||||
|
||||
var = ublas::prod( sample, ublas::trans( sample ) );
|
||||
|
||||
//-------------------------------------------------------------
|
||||
|
||||
|
||||
for (unsigned int i = 0; i < s_size; ++i)
|
||||
{
|
||||
// triangular LOWER matrix, thus j is not going further than i
|
||||
for (unsigned int j = 0; j <= i; ++j)
|
||||
{
|
||||
// we want a reducted covariance matrix
|
||||
_varcovar(i, j) = var(i, j) / p_size;
|
||||
}
|
||||
}
|
||||
|
||||
_mean.resize(s_size);
|
||||
|
||||
// unit vector
|
||||
ublas::scalar_vector< AtomType > u( p_size, 1 );
|
||||
|
||||
// sum over columns
|
||||
_mean = ublas::prod( ublas::trans( sample ), u );
|
||||
|
||||
// division by n
|
||||
_mean /= p_size;
|
||||
}
|
||||
|
||||
const ublas::symmetric_matrix< AtomType, ublas::lower >& get_varcovar() const {return _varcovar;}
|
||||
|
||||
const ublas::vector< AtomType >& get_mean() const {return _mean;}
|
||||
|
||||
private:
|
||||
ublas::symmetric_matrix< AtomType, ublas::lower > _varcovar;
|
||||
ublas::vector< AtomType > _mean;
|
||||
};
|
||||
|
||||
public:
|
||||
typedef typename EOT::AtomType AtomType;
|
||||
|
||||
doNormalMulti< EOT > operator()(eoPop<EOT>& pop)
|
||||
{
|
||||
unsigned int popsize = pop.size();
|
||||
assert(popsize > 0);
|
||||
|
||||
unsigned int dimsize = pop[0].size();
|
||||
assert(dimsize > 0);
|
||||
|
||||
CovMatrix cov;
|
||||
|
||||
cov.update(pop);
|
||||
|
||||
return doNormalMulti< EOT >( cov.get_mean(), cov.get_varcovar() );
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !_doEstimatorNormalMulti_h
|
||||
Reference in a new issue