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

What to use instead of string for x0? #146

Closed
sergeyf opened this issue Sep 18, 2020 · 2 comments
Closed

What to use instead of string for x0? #146

sergeyf opened this issue Sep 18, 2020 · 2 comments

Comments

@sergeyf
Copy link

sergeyf commented Sep 18, 2020

Hello,

Before a recent version I used to call fmin as follows:

    lower_bounds = np.array([0, 0 ,0])
    upper_bounds = np.array([1, 1, 1])
    result = cma.fmin(
        loss_function,
        f'np.random.uniform({list(lower_bounds)}, {list(upper_bounds)})', 
        std,
        {
            'bounds': [lower_bounds, upper_bounds],
            'popsize': popsize,
            'verbose': -9,
            'CMA_stds': upper_bounds / 4
        },
        restarts=restarts,
        bipop=True
    )

Now, however I am getting errors that x0 can no longer be a string. What is the right way to get a random init for each restart? The documentation still says "use a string".

Thanks for the great package!

@nikohansen
Copy link
Contributor

nikohansen commented Sep 21, 2020

Damn, the documentation is wrong ;-)

The error message gives a hint though:

ValueError: x0 may be a callable, but a string is no longer permitted

Using

lambda : np.random.uniform(lower_bounds, upper_bounds)

in place of

f'np.random.uniform({list(lower_bounds)}, {list(upper_bounds)})'

seems to work for me. I am very sorry for the inconvenience, changing interfaces are a real annoyance...

@sergeyf
Copy link
Author

sergeyf commented Sep 21, 2020

Thank you :)

The inconvenience is truly minor compared to the hugely wonderful package itself!

@sergeyf sergeyf closed this as completed Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants