Interim values of Metaheuristics optimiziers

I’m interested in getting the interim population values for algorithms within Metaheuristics.jl at each timestep, for example Differential Evolution.

I’ve seen examples where the single member of the population with the best fitness can be retrieved at each iteration using convergence(), though I’d like to be able to interrogate each member of the population at a given timestep.

Is there a clean way to do this? I looked around but it doesn’t seem like Metaheuristics.optimize() provides the ability to give a callback function or similar pattern.

The hacky approach I’ve found thus far is to inspect status.population during internal calls to Metaheuristics.stop_criteria!, which is based off this example from modifying an existing metaheuristic.


global POPULATION [];

function Metaheuristics.stop_criteria!(
        status,
        parameters::DE
        problem,
        information,
        options,
        args...;
        kargs...
    )
    
    # Allow for traditional usage of DE algo to
    # set status and determine when to stop
    if status.stop
        return
    end

    # Record state of population
    push!(POPULATION, status.population)

end

Perhaps there are other lesser documented internal Metaheuristics functions that
would be more direct in what I’m looking for?

Hi @jcusick, welcome to the forum. I don’t know the answer to the question, but @jmejia8 should be able to help.

@jcusick - Below two approaches:

Using a logger

function logger(status)
    display(status.population)
    print(status.population[1])
end
optimize(f, bounds, DE; logger)

See this Printing progress to terminal when running optimization? · Issue #78 · jmejia8/Metaheuristics.jl · GitHub

Using optimize!

Example at:
API References · Metaheuristics.jl!

1 Like

Ahh those approaches look great – thanks both @jmejia8 and @odow!

1 Like