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

Seems like bounds are not respected #220

Closed BIackthorn closed 3 years ago

BIackthorn commented 3 years ago

I grabbed the python test file: libcmaes/python/ptest_bounds.py

If I modify the lower bounds to: lbounds = [0]*10

Running I get this output: best x= [-0.0499810245813009, -0.049984952431464294, -0.05000384317232943, -0.05001758520746221, -0.04997964822517451, -0.049981813653182904, -0.050022418111235284, -0.049990267407082206, -0.04999867943305543, -0.049984492061925366]

Clearly negative values and I try changing the bounds to other positive values and I get a similar problem. Am I doing something wrong or is this a bug?

nikohansen commented 3 years ago

Probably neither. What you see is probably a "genotype" solution that gives values very close to zero when transformed to the "phenotype". The phenotype is evaluated on the objective function and should be in bounds. I don't know specifically how to invoke the transformation on the best x in this library.

beniz commented 3 years ago

Thanks for the feedback @Blackthorn. @nikohansen is correct that the output values are in genotype space. It's been an issue with the Python bindings for a while I believe.

I've took a bit of time to look at it, and pushed PR https://github.com/CMA-ES/libcmaes/pull/221 that works for me.

Using your bounds [0,4], and retrieving the candidates with:

bcand_pheno = lcmaes.get_best_candidate_pheno(cmasols,gp)
print('best x in phenotype space=',bcand_pheno)

I correctly get:

est x= [-0.049994186928939886, -0.050010013649435435, -0.04999666855797151, -0.05000001115034218, -0.050014259812272456, -0.04999646070529928, -0.05000982318177387, -0.04998566368429318, -0.05000779835521939, -0.04999283416357773]
best x in phenotype space= [1.689589757498181e-10, 5.013658750786584e-10, 5.549252994602939e-11, 6.216506533607692e-16, 1.0167112302280438e-09, 6.263303489293389e-11, 4.824745008120535e-10, 1.0276497402288541e-09, 3.040717206385455e-10, 2.567460581540249e-10]

@BIackthorn let me know whether this works for you.