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

New features coming in next release #79

Open
jmejia8 opened this issue Apr 12, 2023 · 3 comments
Open

New features coming in next release #79

jmejia8 opened this issue Apr 12, 2023 · 3 comments

Comments

@jmejia8
Copy link
Owner

jmejia8 commented Apr 12, 2023

Install the unstable version hosted in the develop branch.

 pkg> add Metaheuristics#develop

Optimizers with default parameters

f, bounds, pareto_solutions = Metaheuristics.TestProblems.get_problem(:sphere);
optimize(f, bounds, ECA)

Pass parameters and Options via as kargs...

optimize(f, bounds, ECA, N = 20, iterations = 10, seed = 1)

is similar to

optimize(f, bounds, ECA(N = 20, options=Options(iterations = 10, seed = 1))

Using the SearchSpaces module to define search spaces.

fn(x) = abs(sum(diff(x)))
space = boxconstraints(zeros(10), 100ones(10)) # float
optimize(fn, space, ECA)

# bounds
space = boxconstraints(zeros(10), 100ones(10), rigid = false) # float
optimize(fn, space, ECA)

space = boxconstraints(zeros(Int, 10), 100ones(Int, 10)) # integers
optimize(fn, space, ECA)

# discrete
space = BitArraySpace(10) # 10D array of booleans
optimize(fn, space, GA)

space = PermutationSpace(10) # 10-permutation
optimize(fn, space, GA)

Termination criteria based on convergence

Other performance improvements

Clear message errors (#65)

ff(x) = "abcd"
optimize(ff, [zeros(2) ones(2)] , ECA )

output:

ERROR: Objective function should return either a numerical value or a Tuple depending on the problem.
Current output:  abcd of type String
Examples at https://jmejia8.github.io/Metaheuristics.jl/stable/examples
Stacktrace:
  [1] error(s::String)
@jmejia8 jmejia8 changed the title New features comming in next release New features coming in next release Apr 18, 2023
@jmejia8
Copy link
Owner Author

jmejia8 commented Apr 18, 2023

New verbose field in Options

f(x) = sum(x.^2)
optimize(f, [zeros(3) ones(3)], ECA, iterations=5, seed=1, verbose=true)

output

+-----------+------------+------------+------------+------------+
| Iteration | Num. Evals |   Minimum  |    Time    | Converged  |
+-----------+------------+------------+------------+------------+
|         1 |         21 | 2.3077e-01 |   0.0441 s |         No | 
|         2 |         42 | 3.0642e-02 |   0.0442 s |         No | 
|         3 |         63 | 3.0642e-02 |   0.0443 s |         No | 
|         4 |         84 | 1.0031e-02 |   0.0444 s |         No | 
|         5 |        105 | 2.4834e-03 |   0.0444 s |         No | 

Due to #78

@jmejia8
Copy link
Owner Author

jmejia8 commented Apr 18, 2023

User-defined RNG (#24):

f(x) = sum(x.^2)
optimize(f, [zeros(3) ones(3)], ECA, rng = Random.Xoshiro(9))

output:

Optimization Result
===================
  Iteration:       137
  Minimum:         3.60251e-49
  Minimizer:       [5.43105e-25, 2.00561e-25, 1.58314e-25]
  Function calls:  2877
  Total time:      0.0808 s
  Stop reason:     Due to Convergence Termination criterion.
optimize(f, [zeros(3) ones(3)], ECA, rng = Random.MersenneTwister(9))
Optimization Result
===================
  Iteration:       142
  Minimum:         2.72803e-49
  Minimizer:       [4.09988e-25, 2.84557e-25, 1.54078e-25]
  Function calls:  2982
  Total time:      0.0115 s
  Stop reason:     Due to Convergence Termination criterion.

@jmejia8
Copy link
Owner Author

jmejia8 commented Apr 18, 2023

User defined termination criteria:

algo = ECA(termination = Metaheuristics.AbsoluteFunctionConvergence(ftol=1e-4) )
optimize(f, [zeros(3) ones(3)], algo)

Output:

Optimization Result
===================
  Iteration:       14
  Minimum:         9.07196e-06
  Minimizer:       [8.84653e-5, 0.000478301, 0.00297243]
  Function calls:  294
  Total time:      0.0010 s
  Stop reason:     Due to Convergence Termination criterion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant