Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] cmaes & xnes do not honor bounds #494

Open
jschueller opened this issue Dec 7, 2021 · 2 comments
Open

[BUG] cmaes & xnes do not honor bounds #494

jschueller opened this issue Dec 7, 2021 · 2 comments
Labels

Comments

@jschueller
Copy link
Contributor

jschueller commented Dec 7, 2021

it seems cmaes (and xnes) does not care about the bounds of the problem as the final population ends up way outside eventhough the initial population is inside the bounds:

#include <pagmo/algorithms/cmaes.hpp>
#include <pagmo/population.hpp>
#include <pagmo/problems/rosenbrock.hpp>

using namespace pagmo;

struct problem1 {
    vector_double fitness(const vector_double &x) const
    {
        double x1=x[0];
        double x2=x[1];
        return {x2};
//         return {1.+100.*(x2-x1*x1)*(x2-x1*x1)+(1.-x1)*(1.-x1)};
    }
    std::pair<vector_double, vector_double> get_bounds() const
    {
        return {{-1.5, -1.5}, {1.5, 1.5}};
    }
    vector_double::size_type get_nobj() const
    {
        return 1;
    }
};

int main()
{
  try {
    problem prob{problem1{}};

    population pop1{prob, 0, 0};
    int size = 100;
    std::uniform_real_distribution<double> unif(-1.5, 1.5);
    std::default_random_engine re;
    for (int i=0; i<size; ++i)
    {
      vector_double x(2);
      x[0] = unif(re);
      x[1] = unif(re);
      pop1.push_back(x);
    }

    cmaes user_algo1{10u};
    pop1 = user_algo1.evolve(pop1);
    for (int i=0; i<size; ++i)
    {
      vector_double x = pop1.get_x()[i];
      std::cout << "x1="<<x[0]<<" x2="<<x[1] <<std::endl;
    }

	}
	catch(const std::exception & exc) {
		std::cout << "ex="<<exc.what() <<std::endl;
		return 2;
	}
	return 0;
}

...
x1=-1495.25 x2=-8833.04
x1=-731.242 x2=-4187.9
x1=-1317.33 x2=-8026.68
x1=-5534.71 x2=-34318.1
x1=1402.88 x2=8971.83
x1=970.03 x2=5018.52
@jschueller jschueller added the bug label Dec 7, 2021
@bluescarni
Copy link
Member

I am going to ping @darioizzo about this.

But as far as I remember, in pagmo it is unspecified at this time if the bounds are always honoured strictly (i.e., it is algorithm-dependent). Some algorithms benefit from being able to explore the search space slightly outside the bounds, but I do not know if that is the case for cmaes/xnes.

@jschueller
Copy link
Contributor Author

it seems force_bounds make take the bounds into account
but the behavior is inconsistent with the other algorithms if it defaults to false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants