fix: better dimension management in edo/adaptive operators

This commit is contained in:
Johann Dreo 2020-04-27 22:00:10 +02:00
commit 4110534122
5 changed files with 50 additions and 8 deletions

View file

@ -39,16 +39,31 @@ class edoDistribReset : public eoAlgoReset<typename D::EOType>
{
public:
using EOType = typename D::EOType;
edoDistribReset( D& distrib ) :
_has_dim(false),
_dim(0),
_distrib(distrib)
{ }
edoDistribReset( D& distrib, size_t dim ) :
_has_dim(true),
_dim(dim),
_distrib(distrib)
{ }
virtual void operator()( eoPop<EOType>& pop )
{
_distrib.reset();
if(_has_dim) {
_distrib.reset(_dim);
} else {
_distrib.reset();
}
}
protected:
bool _has_dim;
size_t _dim;
D& _distrib;
};

View file

@ -31,7 +31,7 @@ Authors:
#include "edoEstimatorAdaptive.h"
/** An estimator that calls `reset` on the managed distribution.
/** An estimator that change the parameters on the managed distribution.
*
* @ingroup Estimators
*/

View file

@ -41,14 +41,24 @@ class edoEstimatorAdaptiveReset : public edoEstimatorAdaptive<D>
public:
typedef typename D::EOType EOType;
edoEstimatorAdaptiveReset<D>( D& distrib ) : edoEstimatorAdaptive<D>(distrib) {}
edoEstimatorAdaptiveReset<D>( D& distrib ) :
edoEstimatorAdaptive<D>(distrib),
_dim(0)
{ }
virtual D operator() ( eoPop<EOType>& )
edoEstimatorAdaptiveReset<D>( D& distrib, size_t dim ) :
edoEstimatorAdaptive<D>(distrib),
_dim(dim)
{ }
virtual D operator()( eoPop<EOType>& )
{
this->_distrib.reset();
this->_distrib.reset(_dim);
return this->_distrib;
}
protected:
size_t _dim;
};
#endif // !_edoEstimatorAdaptiveReset_h

View file

@ -90,7 +90,8 @@ public:
* INITIALIZATION
*********************************************************************/
unsigned int N = pop[0].size(); // FIXME expliciter la dimension du pb ?
unsigned int N = this->distribution().size();
assert(this->distribution().size() == pop[0].size());
unsigned int lambda = pop.size();
// number of calls to the operator == number of generations

View file

@ -119,7 +119,13 @@ public:
unsigned int size()
{
return _mean.innerSize();
assert( _mean.innerSize() == _dim );
assert( _C.innerSize() == _dim && _C.outerSize() == _dim );
assert( _B.innerSize() == _dim && _B.outerSize() == _dim );
assert( _D.innerSize() == _dim );
assert( _p_c.innerSize() == _dim );
assert( _p_s.innerSize() == _dim );
return _dim;
}
Vector mean() const {return _mean;}
@ -139,6 +145,7 @@ public:
*/
void mean( EOT m )
{
assert(m.size() == _dim);
Vector center( m.size() );
for( unsigned int i=0, end=m.size(); i<end; ++i) {
center[i] = m[i];
@ -153,8 +160,17 @@ public:
void path_covar( Vector p ) { _p_c = p; assert( p.size() == _dim ); }
void path_sigma( Vector p ) { _p_s = p; assert( p.size() == _dim ); }
void reset()
/** Reset the distribution, like it was just instanciated.
*
* @param dim Dimension of the space, if set to 0 (the default), use the dimension that was lastly set.
*/
void reset(size_t dim = 0)
{
if(dim == 0) {
dim = _dim;
}
_dim = dim;
_mean = Vector::Zero(_dim);
_C = Matrix::Identity(_dim,_dim);
_B = Matrix::Identity(_dim,_dim);