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

MWE not working #24

Open
MaAl13 opened this issue Jul 31, 2024 · 4 comments
Open

MWE not working #24

MaAl13 opened this issue Jul 31, 2024 · 4 comments

Comments

@MaAl13
Copy link

MaAl13 commented Jul 31, 2024

Helo, i am trying to run your optimization on a very simple Rosenbrock function problem, but it fails.Can you tell me what is wrong with my code?

import numpy as np
from scipy.optimize import Bounds
from fcmaes.optimizer import De_cpp
from fcmaes import retry


def test_fun(params):
    return np.sum(100.0 * ((params[1:]+1) - (params[:-1]+1)**2.0)**2.0 + (1 - (params[:-1]+1))**2.0)

# Main optimization function
def optimize_model():
    lb = np.ones(10) * -5  # Lower bound set to -5
    ub = np.ones(10) * 10  # Upper bound set to 10
    bounds = Bounds(lb, ub)
    result = retry.minimize(test_fun, bounds, num_retries=1, optimizer=De_cpp(1000))
    return result

# Run the optimization
if __name__ == "__main__":
    result = optimize_model()
    print(result)
    print(result.x)
    print(result.fun)

Returns:
'NoneType' object is not subscriptable
2024-07-31 14:14:28.382 | DEBUG | fcmaes.retry:dump:388 - 0.07 0 1 0 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000 0.00 0.00 [] [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
success: True
fun: 1.7976931348623157e+308
x: [ 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00
0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00]
nfev: 0
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
1.7976931348623157e+308

@ymLuo1214
Copy link

Meet the same problem, have you fixed that?

@MaAl13
Copy link
Author

MaAl13 commented Nov 12, 2024

Nope, i switched to another package, which works really well on my problem. It is called evosax if you want to try it out.

@dietmarwo
Copy link
Owner

dietmarwo commented Nov 12, 2024

Did you try "pip install fcmaes --upgrade" ?

I checked under Windows 10 and Linux Mint 21.3 using miniforge https://github.com/conda-forge/miniforge with python 10
and cannot reproduce the issue. If you can still can reproduce with 1.6.11 please provide more details about your environment.

I get:

2024-11-12 14:20:26.878 | DEBUG | fcmaes.retry:dump:400 - 0.07 14771 1 1034 6.584272 0.00 0.00 [] [-1.9525107036864022, -0.03372250053045583, -0.055189729344992514, -0.1215086779748337, -0.22202042973813602, -0.39903601766528296, -0.6439347055511802, -0.862776492275128, -0.9657059723528973, -0.9817403814273438]
2024-11-12 14:20:26.886 | DEBUG | fcmaes.retry:add_result:342 - 0.08 12925 1 1034 6.584272 6.584272 6.58 0.00
2024-11-12 14:20:26.933 | DEBUG | fcmaes.retry:dump:400 - 0.13 7953 1 1034 6.584272 6.58 0.00 [0.0] [-1.9525107036864022, -0.03372250053045583, -0.055189729344992514, -0.1215086779748337, -0.22202042973813602, -0.39903601766528296, -0.6439347055511802, -0.862776492275128, -0.9657059723528973, -0.9817403814273438]
success: True
fun: 6.584271797344801
x: [-1.953e+00 -3.372e-02 -5.519e-02 -1.215e-01 -2.220e-01
-3.990e-01 -6.439e-01 -8.628e-01 -9.657e-01 -9.817e-01]
nfev: 1034
[-1.9525107 -0.0337225 -0.05518973 -0.12150868 -0.22202043 -0.39903602
-0.64393471 -0.86277649 -0.96570597 -0.98174038]
6.584271797344801

@dietmarwo
Copy link
Owner

dietmarwo commented Nov 12, 2024

By the way, you can get rid of the debug messages using something like

logger.remove()
logger.add(sys.stdout, format="{time:HH:mm:ss.SS} | {process} | {level} | {message}", level="INFO")
logger.add("log_{time}.txt", format="{time:HH:mm:ss.SS} | {process} | {level} | {message}", level="INFO")

Regarding evosax: Really interesting. Uses Jax which even can utilize GPUs. Beautiful plotting. fcmaes is more focussed on fast parallelisation of the execution of the objective function. If you can utilize JAX for your specific problem (your objective function) evosax is probably the better choice.

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

3 participants