Add "extra" string output to simple_iterate.

Sat, 20 Feb 2021 16:26:31 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sat, 20 Feb 2021 16:26:31 -0500
changeset 22
d5e10d963303
parent 21
3b7fcc651585
child 23
4399bf266660

Add "extra" string output to simple_iterate.

src/Iterate.jl file | annotate | diff | comparison | revisions
--- a/src/Iterate.jl	Sat Feb 20 16:26:02 2021 -0500
+++ b/src/Iterate.jl	Sat Feb 20 16:26:31 2021 -0500
@@ -22,30 +22,35 @@
 # on demand.
 ########################################################################
 
+function simple_verbosity(iter, params, calc_objective)
+    if params.verbose_iter!=0 && mod(iter, params.verbose_iter) == 0
+        v, extra₀ = calc_objective()
+        if isa(extra₀, AbstractString)
+            extra = " [$extra₀]"
+        else
+            extra = ""
+        end
+        @printf("%d/%d J=%f%s\n", iter, params.maxiter, v, extra)
+        return true
+    end
+end
+
 function simple_iterate(step :: Function,
-                        params::NamedTuple)
+                        params :: NamedTuple)
     for iter=1:params.maxiter
         step() do calc_objective
-            if params.verbose_iter!=0 && mod(iter, params.verbose_iter) == 0
-                v, _ = calc_objective()
-                @printf("%d/%d J=%f\n", iter, params.maxiter, v)
-                return true
-            end
+            simple_verbosity(iter, params, calc_objective)
         end
     end
 end
 
 function simple_iterate(step :: Function,
-                        datachannel::Channel{T},
-                        params::NamedTuple) where T
+                        datachannel :: Channel{T},
+                        params :: NamedTuple) where T
     for iter=1:params.maxiter
         d = take!(datachannel)
         step(d) do calc_objective
-            if params.verbose_iter!=0 && mod(iter, params.verbose_iter) == 0
-                v, _ = calc_objective()
-                @printf("%d/%d J=%f\n", iter, params.maxiter, v)
-                return true
-            end
+            simple_verbosity(iter, params, calc_objective)
         end
     end
 end

mercurial