diff --git a/edo/src/edo b/edo/src/edo index e6a03a1ed..030da23b0 100644 --- a/edo/src/edo +++ b/edo/src/edo @@ -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" diff --git a/edo/src/edoEstimatorAdaptiveEdit.h b/edo/src/edoEstimatorAdaptiveEdit.h new file mode 100644 index 000000000..dbf0d920b --- /dev/null +++ b/edo/src/edoEstimatorAdaptiveEdit.h @@ -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 +*/ + +#ifndef _edoEstimatorAdaptiveEdit_h +#define _edoEstimatorAdaptiveEdit_h + +#include + +#include "edoEstimatorAdaptive.h" + +/** An estimator that calls `reset` on the managed distribution. + * + * @ingroup Estimators + */ +template +class edoEstimatorAdaptiveEdit : public edoEstimatorAdaptive +{ +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 e(distrib, + * std::bind(&eoPop::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& distrib, + std::function getter, + std::function setter + ) : + edoEstimatorAdaptive(distrib), + _getter(getter), + _setter(setter) + {} + + virtual D operator()( eoPop& pop ) + { + _setter( _getter() ); + return this->_distrib; + } + +protected: + std::function< P ( )> _getter; + std::function _setter; + +}; + +#endif // !_edoEstimatorAdaptiveEdit_h diff --git a/edo/src/edoEstimatorAdaptiveReset.h b/edo/src/edoEstimatorAdaptiveReset.h new file mode 100644 index 000000000..012784a3d --- /dev/null +++ b/edo/src/edoEstimatorAdaptiveReset.h @@ -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 +*/ + +#ifndef _edoEstimatorAdaptiveReset_h +#define _edoEstimatorAdaptiveReset_h + +#include + +#include "edoEstimatorAdaptive.h" + +/** An estimator that calls `reset` on the managed distribution. + * + * @ingroup Estimators + */ +template +class edoEstimatorAdaptiveReset : public edoEstimatorAdaptive +{ +public: + typedef typename D::EOType EOType; + + edoEstimatorAdaptiveReset( D& distrib ) : edoEstimatorAdaptive(distrib) {} + + virtual D operator() ( eoPop& ) + { + this->_distrib.reset(); + return this->_distrib; + } + +}; + +#endif // !_edoEstimatorAdaptiveReset_h diff --git a/edo/src/edoEstimatorCombined.h b/edo/src/edoEstimatorCombined.h new file mode 100644 index 000000000..f884f38f1 --- /dev/null +++ b/edo/src/edoEstimatorCombined.h @@ -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 +*/ + +#ifndef _edoEstimatorAdaptiveCombined_h +#define _edoEstimatorAdaptiveCombined_h + +#include + +#include + +#include "edoEstimatorAdaptive.h" + +/** An estimator that calls several ordered estimators, stateful version. + * + * @ingroup Estimators + */ +template +class edoEstimatorCombinedAdaptive : public edoEstimatorAdaptive, public std::vector*> +{ +public: + typedef typename D::EOType EOType; + + edoEstimatorCombinedAdaptive( D& distrib, edoEstimator& estim) : + edoEstimatorAdaptive(distrib), + std::vector*>(1,&estim) + {} + + edoEstimatorCombinedAdaptive( D& distrib, std::vector*> estims) : + edoEstimatorAdaptive(distrib), + std::vector*>(estims) + {} + + void add( edoEstimator& estim ) + { + this->push_back(&estim); + } + + virtual D operator()( eoPop& pop ) + { + for(edoEstimator* pestim : *this) { + this->_distrib = (*pestim)( pop ); + } + return this->_distrib; + } + +}; + +/** An estimator that calls several ordered estimators, stateless version. + * + * @ingroup Estimators + */ +template +class edoEstimatorCombinedStateless : public edoEstimatorCombinedAdaptive +{ +public: + typedef typename D::EOType EOType; + + edoEstimatorCombinedStateless( edoEstimator& estim ) : + edoEstimatorCombinedAdaptive(*(new D), estim) + {} + + edoEstimatorCombinedStateless( std::vector*> estims) : + edoEstimatorCombinedAdaptive(*(new D), estims) + {} + + virtual D operator()( eoPop& pop ) + { + delete &(this->_distrib); + this->_distrib = *(new D); + return edoEstimatorCombinedAdaptive::operator()(pop); + } + + ~edoEstimatorCombinedStateless() + { + delete &(this->_distrib); + } + +}; + +#endif // !_edoEstimatorAdaptiveCombined_h