feat: EDO add combinable estimators

Useful to edit the distribution during init, restart or even search.
This commit is contained in:
Johann Dreo 2020-03-24 16:35:49 +01:00
commit e389294cbb
4 changed files with 239 additions and 0 deletions

View file

@ -46,9 +46,12 @@ Authors:
#include "edoEstimatorNormalMono.h"
#include "edoEstimatorNormalMulti.h"
#include "edoEstimatorAdaptive.h"
#include "edoEstimatorAdaptiveReset.h"
#include "edoEstimatorAdaptiveEdit.h"
#include "edoEstimatorNormalAdaptive.h"
#include "edoEstimatorBinomial.h"
#include "edoEstimatorBinomialMulti.h"
#include "edoEstimatorCombined.h"
#include "edoModifier.h"
#include "edoModifierDispersion.h"

View file

@ -0,0 +1,79 @@
/*
The Evolving Distribution Objects framework (EDO) is a template-based,
ANSI-C++ evolutionary computation library which helps you to write your
own estimation of distribution algorithms.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Copyright (C) 2020 Thales group
*/
/*
Authors:
Johann Dréo <johann.dreo@thalesgroup.com>
*/
#ifndef _edoEstimatorAdaptiveEdit_h
#define _edoEstimatorAdaptiveEdit_h
#include <eoPop.h>
#include "edoEstimatorAdaptive.h"
/** An estimator that calls `reset` on the managed distribution.
*
* @ingroup Estimators
*/
template<class D, class P = typename D::EOType>
class edoEstimatorAdaptiveEdit : public edoEstimatorAdaptive<D>
{
public:
typedef typename D::EOType EOType;
/** Edit the given distribution's members with the given accessors.
*
* For example, to shift the distribution's mean toward pop's best element
* (note the lack of parenthesis):
* @code
* edoEstimatorAdaptiveEdit<D> e(distrib,
* std::bind(&eoPop<S>::best_element, &pop),
* // std::bind(&D::mean, &distrib, std::placeholders::_1) // Fail to deduce templates
* // but you can use lambdas (even more readable):
* [&distrib](S center){distrib.mean(center);}
* distrib.mean, pop.best_element);
* @endcode
*/
edoEstimatorAdaptiveEdit<D>(
D& distrib,
std::function<P()> getter,
std::function<void(P)> setter
) :
edoEstimatorAdaptive<D>(distrib),
_getter(getter),
_setter(setter)
{}
virtual D operator()( eoPop<EOType>& pop )
{
_setter( _getter() );
return this->_distrib;
}
protected:
std::function< P ( )> _getter;
std::function<void(P)> _setter;
};
#endif // !_edoEstimatorAdaptiveEdit_h

View file

@ -0,0 +1,54 @@
/*
The Evolving Distribution Objects framework (EDO) is a template-based,
ANSI-C++ evolutionary computation library which helps you to write your
own estimation of distribution algorithms.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Copyright (C) 2020 Thales group
*/
/*
Authors:
Johann Dréo <johann.dreo@thalesgroup.com>
*/
#ifndef _edoEstimatorAdaptiveReset_h
#define _edoEstimatorAdaptiveReset_h
#include <eoPop.h>
#include "edoEstimatorAdaptive.h"
/** An estimator that calls `reset` on the managed distribution.
*
* @ingroup Estimators
*/
template<class D>
class edoEstimatorAdaptiveReset : public edoEstimatorAdaptive<D>
{
public:
typedef typename D::EOType EOType;
edoEstimatorAdaptiveReset<D>( D& distrib ) : edoEstimatorAdaptive<D>(distrib) {}
virtual D operator() ( eoPop<EOType>& )
{
this->_distrib.reset();
return this->_distrib;
}
};
#endif // !_edoEstimatorAdaptiveReset_h

View file

@ -0,0 +1,103 @@
/*
The Evolving Distribution Objects framework (EDO) is a template-based,
ANSI-C++ evolutionary computation library which helps you to write your
own estimation of distribution algorithms.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Copyright (C) 2020 Thales group
*/
/*
Authors:
Johann Dréo <johann.dreo@thalesgroup.com>
*/
#ifndef _edoEstimatorAdaptiveCombined_h
#define _edoEstimatorAdaptiveCombined_h
#include <vector>
#include <eoPop.h>
#include "edoEstimatorAdaptive.h"
/** An estimator that calls several ordered estimators, stateful version.
*
* @ingroup Estimators
*/
template<class D>
class edoEstimatorCombinedAdaptive : public edoEstimatorAdaptive<D>, public std::vector<edoEstimator<D>*>
{
public:
typedef typename D::EOType EOType;
edoEstimatorCombinedAdaptive<D>( D& distrib, edoEstimator<D>& estim) :
edoEstimatorAdaptive<D>(distrib),
std::vector<edoEstimator<D>*>(1,&estim)
{}
edoEstimatorCombinedAdaptive<D>( D& distrib, std::vector<edoEstimator<D>*> estims) :
edoEstimatorAdaptive<D>(distrib),
std::vector<edoEstimator<D>*>(estims)
{}
void add( edoEstimator<D>& estim )
{
this->push_back(&estim);
}
virtual D operator()( eoPop<EOType>& pop )
{
for(edoEstimator<D>* pestim : *this) {
this->_distrib = (*pestim)( pop );
}
return this->_distrib;
}
};
/** An estimator that calls several ordered estimators, stateless version.
*
* @ingroup Estimators
*/
template<class D>
class edoEstimatorCombinedStateless : public edoEstimatorCombinedAdaptive<D>
{
public:
typedef typename D::EOType EOType;
edoEstimatorCombinedStateless<D>( edoEstimator<D>& estim ) :
edoEstimatorCombinedAdaptive<D>(*(new D), estim)
{}
edoEstimatorCombinedStateless<D>( std::vector<edoEstimator<D>*> estims) :
edoEstimatorCombinedAdaptive<D>(*(new D), estims)
{}
virtual D operator()( eoPop<EOType>& pop )
{
delete &(this->_distrib);
this->_distrib = *(new D);
return edoEstimatorCombinedAdaptive<D>::operator()(pop);
}
~edoEstimatorCombinedStateless()
{
delete &(this->_distrib);
}
};
#endif // !_edoEstimatorAdaptiveCombined_h