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

can't store iters, fitness, and best minimizer via callback #62

Open
jpp46 opened this issue Jul 10, 2020 · 1 comment
Open

can't store iters, fitness, and best minimizer via callback #62

jpp46 opened this issue Jul 10, 2020 · 1 comment

Comments

@jpp46
Copy link

jpp46 commented Jul 10, 2020

I have been trying to store

  1. the current number of iterations
  2. the best fitness found so far
  3. the genome of the individual with that value
    Through a callback function and have been trying to work with trace to get there right information into the callback.

When I don't override the trace function can call I get:
fieldnames(typeof(oc)) = (:iteration, :value, :metadata)
for the value of os

If I override the trace! function and set store_trace to true, no matter what I add to the dictionary I get
fieldnames(typeof(tr)) = ()
for the value of tr that I can see gets passed in in this case

I feel like this should be possible.

Maybe one solution would be to give the callback function an intermediate state of the results such that this would work:

function callback(intermediate_res)
items = Evolutionary.iterations(intermediate_res)
best_indv = Evolutionary.minimizer(intermediate_res)
best_fit = minimum(intermediate_res)
.
.

Code to save values

.
return false
end

@wildart
Copy link
Owner

wildart commented Jul 13, 2020

Here is a docs page about traces: Look here: https://wildart.github.io/Evolutionary.jl/dev/tutorial/#Trace-1

This is an example of using it

function Evolutionary.trace!(record::Dict{String,Any}, objfun, state, population, method::GA, options)
idx = sortperm(state.fitpop)
record["fitpop"] = state.fitpop[idx[1:5]]
end

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