CMA-ES / libcmaes

libcmaes is a multithreaded C++11 library with Python bindings for high performance blackbox stochastic optimization using the CMA-ES algorithm for Covariance Matrix Adaptation Evolution Strategy
Other
321 stars 78 forks source link

Don't assume Eigen's storage layout #224

Closed intractabilis closed 3 years ago

intractabilis commented 3 years ago

I recently experience issue #135. The reason of not respected boundaries turned out to be here:

if (phenocandidates.size())
    _solutions._candidates.at(r).set_fvalue(
        _func(phenocandidates.col(r).data(), candidates.rows()));

The expression phenocandidates.col(r).data() assumes that the column data is adjacent in memory, which in fact depends on the defaults of the Eigen library. Suggested fix (in eo_matrix.h):

typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor> dMat;
typedef Eigen::Matrix<double, Eigen::Dynamic, 1, Eigen::ColMajor> dVec;
beniz commented 3 years ago

Good catch, can you PR the improvement ? Thanks!