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 display the best fintess for each iteration #60

Closed
licheng0794 opened this issue Dec 12, 2022 · 4 comments
Closed

How to display the best fintess for each iteration #60

licheng0794 opened this issue Dec 12, 2022 · 4 comments

Comments

@licheng0794
Copy link

For any optimization algorithms, we expect to show the fitness value for each iteration. How could we do that for Metaheuristics.jl? I tried to find in Options but I cannot find it. Thank you.

@jmejia8
Copy link
Owner

jmejia8 commented Dec 12, 2022

Use debug in Options,

For custom formats, I suggest using the following:

logger(status) = println(status.iteration," ", minimum(status))

optimize(f, bounds, OPTIMIZER; logger = logger)

See also State.

@licheng0794
Copy link
Author

licheng0794 commented Dec 13, 2022

I tested debug in Options using the example from the API documents. It does work well.

However, I tested it for my own function, which includes an ODE solver. It did not work. Not sure what the problem is. The code is below.

function fitness_obj(X)
X = [round(x,digits=5) for x in X]
println(X)
outV = VHRSteady(X) # my own function
abs(outV[1] - targetoutflow[2]) + abs(outV[2] - targetoutflow[3]) + 10*abs(outV[3] - targetoutflow[4]) + abs(outV[5] -
targetoutflow[5])
end

using Metaheuristics
Metaoptimize = Metaheuristics.optimize
MetaOptions = Metaheuristics.Options
options = MetaOptions(f_calls_limit = 1000, debug=true);

Xrange = zeros(12,2)
Xrange[:,1] = [0.01, 0.26, 0.09, 0.5, 0.01, 0.01, 0.2, 0.2, 0.05, 2, 50, 500]
Xrange[:,2] = [0.03, 0.35, 0.13, 0.65, 0.21, 0.55, 1, 1.5, 0.5, 3.5, 100, 1000]

status = Metaoptimize(fitness_obj, Xrange, ECA(options = options))

image

No debug information was printed! Any suggestion?

@licheng0794
Copy link
Author

I found the reason. The debug information is only shown after one interation not one evaluation. Thank you.

@jmejia8
Copy link
Owner

jmejia8 commented Dec 14, 2022

Nice!

@jmejia8 jmejia8 closed this as completed Dec 14, 2022
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