# Optimizer in Evolutionary.jl returns initial conditions as minimizer with default setting

**URL:** https://discourse.julialang.org/t/optimizer-in-evolutionary-jl-returns-initial-conditions-as-minimizer-with-default-setting/89902
**Category:** General Usage
**Created:** [November 7, 2022, 6:28pm UTC](https://discourse.julialang.org/t/optimizer-in-evolutionary-jl-returns-initial-conditions-as-minimizer-with-default-setting/89902 "2022-11-07T18:28:24Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mylo19](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mylo19/32/43957_2.png) [@mylo19](https://discourse.julialang.org/u/mylo19)
#### Post date: [November 7, 2022, 6:28pm UTC](https://discourse.julialang.org/t/optimizer-in-evolutionary-jl-returns-initial-conditions-as-minimizer-with-default-setting/89902/1 "2022-11-07T18:28:25Z")

</div>

I want to use a genetic algorithm to minimize a function. After searching, I read that the best available option is `Evolutionary.jl`. Hence, I started reading the [documentation](https://wildart.github.io/Evolutionary.jl/dev/tutorial/). I tried running the examples found in the tutorial but came across some issues.

Running the example:

```julia
res = Evolutionary.optimize(x->-sum(x), BitVector(zeros(3)), GA())

```

indeed returns the correct solution. However, the same piece of code with different initial conditions (that are not the final results) produce wrong results (at least in my PC). For instance:

```julia
res = Evolutionary.optimize(x->-sum(x), [11,19,-1], GA())

```

returns:

```julia
 * Status: success

 * Candidate solution
    Minimizer: [11, 19, -1]
    Minimum: -29
    Iterations: 12

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

 * Convergence measures
    |f(x) - f(x')| = 0.0 ≤ 1.0e-12

 * Work counters
    Seconds run: 0.0001 (vs limit Inf)
    Iterations: 12
    f(x) calls: 650

```

which is clearly wrong. In similar cases, the results I get are the initial conditions, and not the min point.

When running the example found [here](https://wildart.github.io/Evolutionary.jl/dev/constraints/), I get the correct results though. Hence, if I try to alter the settings of the GA(), and use these ones:

```julia
ga = GA(populationSize=100,selection=uniformranking(3),
        mutation=gaussian(),crossover=uniformbin())

```

I get results that seem ok.

To dig into that, I also tried defining a custom sum function, and print the results to see what is going on:

```julia
function sumTest(x)
    println((x))
    return sum(x)
end

```

and then define a test:

```julia
initialParameters = [1.0, -1.0, 10.0]
results = Evolutionary.optimize(sumTest, initialParameters, GA())

```

as expected, the argument passed in function `sumTest` is always the initialParameters.

This is also fixed when using custom ga parameters.

---

<div class="post-metadata">

### Author: ![mylo19](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mylo19/32/43957_2.png) [@mylo19](https://discourse.julialang.org/u/mylo19)
#### Post date: [November 7, 2022, 7:33pm UTC](https://discourse.julialang.org/t/optimizer-in-evolutionary-jl-returns-initial-conditions-as-minimizer-with-default-setting/89902/2 "2022-11-07T19:33:57Z")

</div>

Found relevant [issue](https://github.com/wildart/Evolutionary.jl/issues/98) in the GitHub repository.

> You are correct, default parameters are useless.
