Evolutionary.jl icon indicating copy to clipboard operation
Evolutionary.jl copied to clipboard

Cannot get tutorial example to work

Open itsdfish opened this issue 5 years ago • 2 comments
trafficstars

Hello-

Thank you for putting this package together. Unfortunately, I am having trouble getting the tutorial example to work. The algorithm seems to be stuck at the initial values.

res = Evolutionary.optimize(x -> -sum(x),
                            BitVector(zeros(3)),
                            GA(),
                            Evolutionary.Options(iterations=10, show_trace=true))

Here are the results:

Iter     Function value
     0                0
 * time: 8.416175842285156e-5
     1                0
 * time: 0.0001971721649169922
     2                0
 * time: 0.00025010108947753906
     3                0
 * time: 0.00028705596923828125
     4                0
 * time: 0.0003161430358886719
     5                0
 * time: 0.0003452301025390625
     6                0
 * time: 0.00038123130798339844
     7                0
 * time: 0.000408172607421875
     8                0
 * time: 0.0004360675811767578
     9                0
 * time: 0.0004742145538330078
    10                0
 * time: 0.0005102157592773438
    11                0
 * time: 0.0005371570587158203

 * Status: success

 * Candidate solution
    Minimizer:  [false, false, false]
    Minimum:    0
    Iterations: 11

 * Found with
    Algorithm: GA[P=50,x=0.8,μ=0.1,ɛ=0]

If I understand correctly, the minimizer should be [true,true,true] with a minimum of -3. I tried changing parameters of GA and in Options, but to no avail. Am I doing something incorrectly?

itsdfish avatar Aug 10 '20 18:08 itsdfish

By default, GA doesn't mutate nor perform selection.

help?> GA
  Implementation of Genetic Algorithm

  The constructor takes following keyword arguments:

    •    populationSize: The size of the population

    •    crossoverRate: The fraction of the population at the next generation, not including elite children, that
        is created by the crossover function.

    •    mutationRate: Probability of chromosome to be mutated

    •    ɛ/epsilon: Positive integer specifies how many individuals in the current generation are guaranteed to
        survive to the next generation. Floating number specifies fraction of population.

    •    selection: Selection function

    •    crossover: Crossover function (default: identity)

    •    mutation: Mutation function (default: identity)

So, you need to specify appropriate genetic operators for the individuals, in your case some binary ops. See docs for more info: https://wildart.github.io/Evolutionary.jl/stable/

julia> res = Evolutionary.optimize(x -> -sum(x),
                                   BitVector(zeros(3)),
                                   GA(mutation=flip, crossover=singlepoint, selection=sus),
                                   Evolutionary.Options(iterations=5, show_trace=true))
Iter     Function value
     0                0
 * time: 5.0067901611328125e-5
     1               -2
 * time: 0.00019598007202148438
     2               -3
 * time: 0.00030493736267089844
     3               -3
 * time: 0.0003979206085205078
     4               -3
 * time: 0.0004858970642089844
     5               -3
 * time: 0.0005910396575927734

 * Status: failure (reached maximum number of iterations)

 * Candidate solution
    Minimizer:  [true, true, true]
    Minimum:    -3
    Iterations: 5

 * Found with
    Algorithm: GA[P=50,x=0.8,μ=0.1,ɛ=0]

wildart avatar Aug 11 '20 19:08 wildart

Thank you for taking the time to explain the problem. Before closing this issue, I want to ask whether there might be a default configuration that might work OK in most situations? This might prevent some confusion in the future. If that is not advisable, I wonder whether it would be helpful to include the configuration above in the documentation example?

itsdfish avatar Aug 11 '20 21:08 itsdfish