Skip to content

Commit 46629d8

Browse files
committed
improve docstring
1 parent 376fa68 commit 46629d8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/CMAEvolutionStrategy.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,32 @@ of `n` rows (`n = length(x0)`) and `popsize` columns and should return a vector
8484
length `popsize`. To use multi-threaded parallel evaluation of the objective function,
8585
set `multi_threading = true` and start julia with multiple threads
8686
(c.f. julia manual for the multi-threading setup).
87+
88+
### Example 1
89+
```
90+
using CMAEvolutionStrategy
91+
92+
function rosenbrock(x)
93+
n = length(x)
94+
sum(100 * (x[2i-1]^2 - x[2i])^2 + (x[2i-1] - 1)^2 for i in 1:div(n, 2))
95+
end
96+
97+
result = minimize(rosenbrock, zeros(6), 1.)
98+
99+
xbest(result) # show best input x
100+
101+
fbest(result) # show best function value
102+
103+
population_mean(result) # show mean of final population
104+
```
105+
### Example 2
106+
```
107+
# continuation of Example 1 with parallel evaluation
108+
109+
rosenbrock_parallel(x) = [rosenbrock(xi) for xi in eachcol(x)]
110+
111+
result = minimize(rosenbrock_parallel, zeros(6), 1., parallel_evaluation = true)
112+
```
87113
"""
88114
function minimize(f, x0, s0;
89115
kwargs...)

0 commit comments

Comments
 (0)