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

Cannot get tutorial example to work #65

Open
itsdfish opened this issue Aug 10, 2020 · 2 comments
Open

Cannot get tutorial example to work #65

itsdfish opened this issue Aug 10, 2020 · 2 comments

Comments

@itsdfish
Copy link

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?

@wildart
Copy link
Owner

wildart commented Aug 11, 2020

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]

@itsdfish
Copy link
Author

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?

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