| 20 # The function `step` should take as its argument a function that itself |
20 # The function `step` should take as its argument a function that itself |
| 21 # takes as its argument a function that calculates the objective value |
21 # takes as its argument a function that calculates the objective value |
| 22 # on demand. |
22 # on demand. |
| 23 ######################################################################## |
23 ######################################################################## |
| 24 |
24 |
| |
25 function simple_verbosity(iter, params, calc_objective) |
| |
26 if params.verbose_iter!=0 && mod(iter, params.verbose_iter) == 0 |
| |
27 v, extra₀ = calc_objective() |
| |
28 if isa(extra₀, AbstractString) |
| |
29 extra = " [$extra₀]" |
| |
30 else |
| |
31 extra = "" |
| |
32 end |
| |
33 @printf("%d/%d J=%f%s\n", iter, params.maxiter, v, extra) |
| |
34 return true |
| |
35 end |
| |
36 end |
| |
37 |
| 25 function simple_iterate(step :: Function, |
38 function simple_iterate(step :: Function, |
| 26 params::NamedTuple) |
39 params :: NamedTuple) |
| 27 for iter=1:params.maxiter |
40 for iter=1:params.maxiter |
| 28 step() do calc_objective |
41 step() do calc_objective |
| 29 if params.verbose_iter!=0 && mod(iter, params.verbose_iter) == 0 |
42 simple_verbosity(iter, params, calc_objective) |
| 30 v, _ = calc_objective() |
|
| 31 @printf("%d/%d J=%f\n", iter, params.maxiter, v) |
|
| 32 return true |
|
| 33 end |
|
| 34 end |
43 end |
| 35 end |
44 end |
| 36 end |
45 end |
| 37 |
46 |
| 38 function simple_iterate(step :: Function, |
47 function simple_iterate(step :: Function, |
| 39 datachannel::Channel{T}, |
48 datachannel :: Channel{T}, |
| 40 params::NamedTuple) where T |
49 params :: NamedTuple) where T |
| 41 for iter=1:params.maxiter |
50 for iter=1:params.maxiter |
| 42 d = take!(datachannel) |
51 d = take!(datachannel) |
| 43 step(d) do calc_objective |
52 step(d) do calc_objective |
| 44 if params.verbose_iter!=0 && mod(iter, params.verbose_iter) == 0 |
53 simple_verbosity(iter, params, calc_objective) |
| 45 v, _ = calc_objective() |
|
| 46 @printf("%d/%d J=%f\n", iter, params.maxiter, v) |
|
| 47 return true |
|
| 48 end |
|
| 49 end |
54 end |
| 50 end |
55 end |
| 51 end |
56 end |
| 52 |
57 |
| 53 end |
58 end |