add EDO continuator checking matrices of adaptive distribution
This commit is contained in:
parent
c8121c788d
commit
08bbf69f44
5 changed files with 263 additions and 10 deletions
|
|
@ -78,6 +78,9 @@ Authors:
|
||||||
#include "edoBounderUniform.h"
|
#include "edoBounderUniform.h"
|
||||||
|
|
||||||
#include "edoContinue.h"
|
#include "edoContinue.h"
|
||||||
|
#include "edoCombinedContinue.h"
|
||||||
|
#include "edoContAdaptiveIllCond.h"
|
||||||
|
#include "edoContAdaptiveFinite.h"
|
||||||
#include "utils/edoCheckPoint.h"
|
#include "utils/edoCheckPoint.h"
|
||||||
|
|
||||||
#include "utils/edoStat.h"
|
#include "utils/edoStat.h"
|
||||||
|
|
|
||||||
74
edo/src/edoCombinedContinue.h
Normal file
74
edo/src/edoCombinedContinue.h
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
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 _edoCombinedContinue_h
|
||||||
|
#define _edoCombinedContinue_h
|
||||||
|
|
||||||
|
#include <eoFunctor.h>
|
||||||
|
#include <eoPersistent.h>
|
||||||
|
|
||||||
|
/** Combine several EDO continuators in a single one.
|
||||||
|
*
|
||||||
|
* Return true if any of the managed continuator ask for a stop.
|
||||||
|
*
|
||||||
|
* @see edoContinue
|
||||||
|
*
|
||||||
|
* @ingroup Continuators
|
||||||
|
* @ingroup Core
|
||||||
|
*/
|
||||||
|
template<class D>
|
||||||
|
class edoCombinedContinue : public edoContinue<D>, public std::vector<edoContinue<D>*>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
edoCombinedContinue( edoContinue<D>& cont ) :
|
||||||
|
edoContinue<D>(),
|
||||||
|
std::vector<edoContinue<D>*>(1,&cont)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
edoCombinedContinue( std::vector<edoContinue<D>*> conts ) :
|
||||||
|
edoContinue<D>(),
|
||||||
|
std::vector<edoContinue<D>*>(conts)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void add( edoContinue<D>& cont)
|
||||||
|
{
|
||||||
|
this->push_back(&cont);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator()(const D& distrib)
|
||||||
|
{
|
||||||
|
for(const auto cont : *this) {
|
||||||
|
if( not (*cont)(distrib)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual std::string className() const { return "edoCombinedContinue"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // !_edoCombinedContinue_h
|
||||||
95
edo/src/edoContAdaptiveFinite.h
Normal file
95
edo/src/edoContAdaptiveFinite.h
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
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 _edoContAdaptiveFinite_h
|
||||||
|
#define _edoContAdaptiveFinite_h
|
||||||
|
|
||||||
|
#include "edoContinue.h"
|
||||||
|
|
||||||
|
/** A continuator that check if any element in the parameters
|
||||||
|
* of an edoNormalAdaptive distribution are finite
|
||||||
|
*
|
||||||
|
* If any element of any parameter is infinity or NaN (Not A Number),
|
||||||
|
* it will ask for a stop.
|
||||||
|
*
|
||||||
|
* @ingroup Continuators
|
||||||
|
*/
|
||||||
|
template<class D>
|
||||||
|
class edoContAdaptiveFinite : public edoContinue<D>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using EOType = typename D::EOType;
|
||||||
|
using Matrix = typename D::Matrix;
|
||||||
|
using Vector = typename D::Vector;
|
||||||
|
|
||||||
|
bool operator()(const D& d)
|
||||||
|
{
|
||||||
|
// Try to finite_check in most probably ill-conditioned order.
|
||||||
|
return finite_check(d.covar())
|
||||||
|
and finite_check(d.path_covar())
|
||||||
|
and finite_check(d.coord_sys())
|
||||||
|
and finite_check(d.scaling())
|
||||||
|
and finite_check(d.path_sigma())
|
||||||
|
and finite_check(d.sigma())
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual std::string className() const { return "edoContAdaptiveFinite"; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool finite_check(const Matrix& mat) const
|
||||||
|
{
|
||||||
|
for(long i=0; i<mat.rows(); ++i) {
|
||||||
|
for(long j=0; j<mat.cols(); ++j) {
|
||||||
|
if(not finite_check(mat(i,j))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool finite_check(const Vector& vec) const
|
||||||
|
{
|
||||||
|
for(long i=0; i<vec.size(); ++i) {
|
||||||
|
if(not finite_check(vec[i])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool finite_check(const typename EOType::AtomType& x) const
|
||||||
|
{
|
||||||
|
if(not std::isfinite(x)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
83
edo/src/edoContAdaptiveIllCond.h
Normal file
83
edo/src/edoContAdaptiveIllCond.h
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
/*
|
||||||
|
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 _edoContAdaptiveIllCond_h
|
||||||
|
#define _edoContAdaptiveIllCond_h
|
||||||
|
|
||||||
|
#ifdef WITH_EIGEN
|
||||||
|
|
||||||
|
#include<Eigen/Dense>
|
||||||
|
|
||||||
|
#include "edoContinue.h"
|
||||||
|
|
||||||
|
/** A continuator that check if any matrix among the parameters
|
||||||
|
* of an edoNormalAdaptive distribution are ill-conditioned.
|
||||||
|
*
|
||||||
|
* If the condition number of the covariance matrix
|
||||||
|
* or the coordinate system matrix are strictly greater
|
||||||
|
* than the threshold given at construction, it will ask for a stop.
|
||||||
|
*
|
||||||
|
* @ingroup Continuators
|
||||||
|
*/
|
||||||
|
template<class D>
|
||||||
|
class edoContAdaptiveIllCond : public edoContinue<D>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using EOType = typename D::EOType;
|
||||||
|
using Matrix = typename D::Matrix;
|
||||||
|
using Vector = typename D::Vector;
|
||||||
|
|
||||||
|
edoContAdaptiveIllCond( double threshold = 1e6) :
|
||||||
|
_threshold(threshold)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
bool operator()(const D& d)
|
||||||
|
{
|
||||||
|
if( condition(d.covar()) > _threshold
|
||||||
|
or condition(d.coord_sys()) > _threshold ) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual std::string className() const { return "edoContAdaptiveIllCond"; }
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Public function in case someone would want to dimensionate the condition threshold.
|
||||||
|
//! Returns the condition number
|
||||||
|
bool condition(const Matrix& mat) const
|
||||||
|
{
|
||||||
|
Eigen::JacobiSVD<Matrix> svd(mat);
|
||||||
|
return svd.singularValues()(0) / svd.singularValues()(svd.singularValues().size()-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const double _threshold;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // WITH_EIGEN
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -25,8 +25,8 @@ Authors:
|
||||||
Caner Candan <caner.candan@thalesgroup.com>
|
Caner Candan <caner.candan@thalesgroup.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _doContinue_h
|
#ifndef _edoContinue_h
|
||||||
#define _doContinue_h
|
#define _edoContinue_h
|
||||||
|
|
||||||
#include <eoFunctor.h>
|
#include <eoFunctor.h>
|
||||||
#include <eoPersistent.h>
|
#include <eoPersistent.h>
|
||||||
|
|
@ -44,20 +44,18 @@ class edoContinue : public eoUF< const D&, bool >, public eoPersistent
|
||||||
public:
|
public:
|
||||||
virtual std::string className(void) const { return "edoContinue"; }
|
virtual std::string className(void) const { return "edoContinue"; }
|
||||||
|
|
||||||
void readFrom(std::istream&)
|
// May be implemented by subclasses if persistent interface needed
|
||||||
{
|
virtual void readFrom(std::istream&)
|
||||||
/* It should be implemented by subclasses ! */
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
void printOn(std::ostream&) const
|
virtual void printOn(std::ostream&) const
|
||||||
{
|
{ }
|
||||||
/* It should be implemented by subclasses ! */
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template < typename D >
|
template < typename D >
|
||||||
class edoDummyContinue : public edoContinue< D >
|
class edoDummyContinue : public edoContinue< D >
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
bool operator()(const D&){ return true; }
|
bool operator()(const D&){ return true; }
|
||||||
|
|
||||||
virtual std::string className() const { return "edoDummyContinue"; }
|
virtual std::string className() const { return "edoDummyContinue"; }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue