wildart / Evolutionary.jl

Evolutionary & genetic algorithms for Julia
Other
324 stars 60 forks source link

Advices to make interfaces extensible #27

Closed GiggleLiu closed 4 years ago

GiggleLiu commented 5 years ago

This is a very neat repo for evolutionary algorithms! I really like it, but please allow me to give two advices to make the interface better

  1. split body of functions into multiple shorter functions, this is always plausible in Julia.
  2. provide iterator interface to algorithms, like
    for (count, runtime_info) in enumerate(optimize(objfunc, individual, args...))
    # inspect your program
    @show runtime_info.best
    # exit condition
    (count > 100 || runtime_info.precision < 1e-10) && break
    end

these changes have practical importances

  1. making functions shorter allows us dispatch and overload specific functionality. e.g. let populate! be a function like in PR #26 can help people implement parallelism (e.g. MPI) much easier. Let functions short is helpful to open issues #15 and #2 , so that people can overload shorter functions like select(::ProblemType, current_population, current_fitness) to custom the strategies of selecting parents, or generate(::ProblemType, parents) to generate new generation in bounds.
  2. Iterator interfaces can be regarded as a clean version of call_back function, many people want to inspect their program during optimization, and iterator provides full access to the runtime information.
  3. Also, iterator interface requires less input parameters, like iterations, tol and verbose, because people can decide when to break the program intuitively inside a loop.

See this PR for detail (this is a demo, not a real PR, a PR requires more discussion) https://github.com/wildart/Evolutionary.jl/pull/26

wildart commented 5 years ago

I like the idea to isolate algorithm step as a separate function. It is long overdue and pave the way to a parallel implementation. The iterator interface is logical continuation of this idea, but I still would prefer one optimization call to a loop.

GiggleLiu commented 5 years ago

It would be appreciated if both interfaces are implemented. ‘One call’ is simple, and ‘iterator’ is flexible enough to support call back supports and complex break condition. Both interfaces are straightforward if an isolated step function is available.

wildart commented 4 years ago

See version 0.4.0, and some dev notes in docs