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

How to use NOMAD with a function that depends on both the parameters to be optimized (x) and fixed parameters (p)? #71

Open
martinmestre opened this issue Aug 11, 2023 · 2 comments

Comments

@martinmestre
Copy link

Hi, I would really appreciate an example on this. Thanks.

@ctribes
Copy link

ctribes commented Aug 11, 2023

We have a parameter called FIXED_VARIABLES for that.
https://nomad-4-user-guide.readthedocs.io/en/latest/AdvancedFunctionalities.html

And we have an example for Nomad in batch mode.
https://github.com/bbopt/nomad/blob/master/examples/advanced/batch/FixedVariable/param.txt

@salomonl
Copy link
Collaborator

@martinmestre The interface of the NOMAD software in Julia does not include the parameter FIXED_VARIABLES, because it is difficult to test it when combined with linear equality constraints (between others). You need to launch it only on non-fixed variables. However, the following example should do the deal:

import NOMAD

function bb1(x, p)
    sum1 = sum(cos.(x) .^ 4)
    sum2 = sum(x)
    sum3 = (1:length(x)) .* x
    prod1 = prod(cos.(x) .^ 2)
    prod2 = prod(x)
    g1 = -prod2 + 0.75
    g2 = sum2 - 7.5 * length(x)
    f = 10 * g1 + 10 * g2
    if (sum3  0.0)
        f -= abs((sum1 - 2 * prod1) / sqrt(3))
    end

    # scaling
    f *= 10^(-5) + p
    c2000 = -f - 2000 + p
    return (true, true, [g1; g2; f; c2000])
end

for param in [1.0, 2.0, 2.0, 3.0] #include two times 2.0 for reproducibility
    println("parameter = ", param, "\n")

    pb = NOMAD.NomadProblem(5, 4, ["PB"; "PB"; "OBJ"; "EB"],
                            x -> bb1(x, param))
    pb.options.max_bb_eval = 1000

    result = NOMAD.solve(pb, 7.0 * ones(Float64, 5))
end

On my machine, it returns:

parameter = 1.0

BBE OBJ
1 -168090.044939
A termination criterion is reached: No termination (all). Mesh minimum precision reached (Algo)

Best feasible solution:     Undefined.

Best infeasible solution:   #102716 ( 2.00166e-08 -222.807 6.07192 -97.4832 151.656 )	Evaluation OK	 f = -1999                     	 h =   0.122258619025000001

Blackbox evaluations:         851
Total model evaluations:      97312
Cache hits:                   78
Total number of evaluations:  929
parameter = 2.0

1 -336178.408995
324   -1994.428007
326   -1997.180223
351   -1997.953221
395   -1997.977435
462   -1997.999186
615   -1997.999481
636   -1997.999555
637   -1997.999774
659   -1997.999975
798   -1997.999977
816   -1997.999981
817   -1997.999995
909   -1997.999998
981   -1998
A termination criterion is reached: Maximum number of blackbox evaluations (Eval Global) 1000

Best feasible solution:     #177805 ( -3.75106e-06 -34.3587 -5.3168 27.9054 -50.2317 )	Evaluation OK	 f = -1998                     	 h =   0

Best infeasible solution:   #165855 ( -2.92766e-06 -34.3587 -5.31716 27.9054 -50.2499 )	Evaluation OK	 f = -1994.1627410000000964    	 h =   0.000000000001

Blackbox evaluations:         1000
Total model evaluations:      156157
Cache hits:                   98
Total number of evaluations:  1098
parameter = 2.0

1 -336178.408995
324   -1994.428007
326   -1997.180223
351   -1997.953221
395   -1997.977435
462   -1997.999186
615   -1997.999481
636   -1997.999555
637   -1997.999774
659   -1997.999975
798   -1997.999977
816   -1997.999981
817   -1997.999995
909   -1997.999998
981   -1998
A termination criterion is reached: Maximum number of blackbox evaluations (Eval Global) 1000

Best feasible solution:     #177805 ( -3.75106e-06 -34.3587 -5.3168 27.9054 -50.2317 )	Evaluation OK	 f = -1998                     	 h =   0

Best infeasible solution:   #165855 ( -2.92766e-06 -34.3587 -5.31716 27.9054 -50.2499 )	Evaluation OK	 f = -1994.1627410000000964    	 h =   0.000000000001

Blackbox evaluations:         1000
Total model evaluations:      156157
Cache hits:                   98
Total number of evaluations:  1098
parameter = 3.0

1 -504266.773051
332   -1996.036238
379   -1996.699164
457   -1996.744346
471   -1996.919412
535   -1996.98619
540   -1996.988497
589   -1996.999198
758   -1996.999977

BBE OBJ
891   -1996.999982
915   -1996.999996
A termination criterion is reached: Maximum number of blackbox evaluations (Eval Global) 1000

Best feasible solution:     #183997 ( -42.5891 8.98381 6.27354 0.000322763 -1.31333 )	Evaluation OK	 f = -1996.9999960000000101    	 h =   0

Best infeasible solution:   #189937 ( -42.6005 8.97419 6.27395 0.000233275 -1.3404 )	Evaluation OK	 f = -1990.3838189999999031    	 h =   0.000000000169

Blackbox evaluations:         1000
Total model evaluations:      174204
Cache hits:                   90
Total number of evaluations:  1090

Hope it helps ! We will add a remark in the documentation.

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