fix: better dimension management in edo/adaptive operators
This commit is contained in:
parent
23f6e68d34
commit
4110534122
5 changed files with 50 additions and 8 deletions
|
|
@ -39,16 +39,31 @@ class edoDistribReset : public eoAlgoReset<typename D::EOType>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using EOType = typename D::EOType;
|
using EOType = typename D::EOType;
|
||||||
|
|
||||||
edoDistribReset( D& distrib ) :
|
edoDistribReset( D& distrib ) :
|
||||||
|
_has_dim(false),
|
||||||
|
_dim(0),
|
||||||
|
_distrib(distrib)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
edoDistribReset( D& distrib, size_t dim ) :
|
||||||
|
_has_dim(true),
|
||||||
|
_dim(dim),
|
||||||
_distrib(distrib)
|
_distrib(distrib)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual void operator()( eoPop<EOType>& pop )
|
virtual void operator()( eoPop<EOType>& pop )
|
||||||
{
|
{
|
||||||
|
if(_has_dim) {
|
||||||
|
_distrib.reset(_dim);
|
||||||
|
} else {
|
||||||
_distrib.reset();
|
_distrib.reset();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool _has_dim;
|
||||||
|
size_t _dim;
|
||||||
D& _distrib;
|
D& _distrib;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ Authors:
|
||||||
|
|
||||||
#include "edoEstimatorAdaptive.h"
|
#include "edoEstimatorAdaptive.h"
|
||||||
|
|
||||||
/** An estimator that calls `reset` on the managed distribution.
|
/** An estimator that change the parameters on the managed distribution.
|
||||||
*
|
*
|
||||||
* @ingroup Estimators
|
* @ingroup Estimators
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -41,14 +41,24 @@ class edoEstimatorAdaptiveReset : public edoEstimatorAdaptive<D>
|
||||||
public:
|
public:
|
||||||
typedef typename D::EOType EOType;
|
typedef typename D::EOType EOType;
|
||||||
|
|
||||||
edoEstimatorAdaptiveReset<D>( D& distrib ) : edoEstimatorAdaptive<D>(distrib) {}
|
edoEstimatorAdaptiveReset<D>( D& distrib ) :
|
||||||
|
edoEstimatorAdaptive<D>(distrib),
|
||||||
|
_dim(0)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
edoEstimatorAdaptiveReset<D>( D& distrib, size_t dim ) :
|
||||||
|
edoEstimatorAdaptive<D>(distrib),
|
||||||
|
_dim(dim)
|
||||||
|
{ }
|
||||||
|
|
||||||
virtual D operator()( eoPop<EOType>& )
|
virtual D operator()( eoPop<EOType>& )
|
||||||
{
|
{
|
||||||
this->_distrib.reset();
|
this->_distrib.reset(_dim);
|
||||||
return this->_distrib;
|
return this->_distrib;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
size_t _dim;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !_edoEstimatorAdaptiveReset_h
|
#endif // !_edoEstimatorAdaptiveReset_h
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,8 @@ public:
|
||||||
* INITIALIZATION
|
* 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();
|
unsigned int lambda = pop.size();
|
||||||
|
|
||||||
// number of calls to the operator == number of generations
|
// number of calls to the operator == number of generations
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,13 @@ public:
|
||||||
|
|
||||||
unsigned int size()
|
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;}
|
Vector mean() const {return _mean;}
|
||||||
|
|
@ -139,6 +145,7 @@ public:
|
||||||
*/
|
*/
|
||||||
void mean( EOT m )
|
void mean( EOT m )
|
||||||
{
|
{
|
||||||
|
assert(m.size() == _dim);
|
||||||
Vector center( m.size() );
|
Vector center( m.size() );
|
||||||
for( unsigned int i=0, end=m.size(); i<end; ++i) {
|
for( unsigned int i=0, end=m.size(); i<end; ++i) {
|
||||||
center[i] = m[i];
|
center[i] = m[i];
|
||||||
|
|
@ -153,8 +160,17 @@ public:
|
||||||
void path_covar( Vector p ) { _p_c = p; assert( p.size() == _dim ); }
|
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 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);
|
_mean = Vector::Zero(_dim);
|
||||||
_C = Matrix::Identity(_dim,_dim);
|
_C = Matrix::Identity(_dim,_dim);
|
||||||
_B = Matrix::Identity(_dim,_dim);
|
_B = Matrix::Identity(_dim,_dim);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue