Replay a descent file saved by so_save_descent
. file should
be either an already open file descriptor or a file name to be opened
in "rb"
mode.
init must be a function that can be called with the “header”
saved in the descent log. It should return the data structure
to use for the descent run. The handlers defined in
data.handler
will be called in the same way as they
would by so_run_descent
. Also similar log chatter will be printed
if data.p.verbose
is true
.
If the state structs were compressed when saving with so_save_descent
,
a routine should be provided to “uncompress” them as necessary. This
function should be defined in data.compress.load.state
and should return the uncompressed state struct when called
with the arguments (s, data)
where s
is the compressed struct.
If nSteps is not given, the file is read until EOF is encountered.
If nSteps is present, the descent will be run until either
this number is reached or data.cb.check_stop
returns true.
If the descent log does not contain enough data for this condition to be
fulfilled, more steps will be performed according to so_run_descent
.
In this case, the callbacks in data.cb
must be set in the
same way as for so_run_descent
.
Returned are the final state and the produced log structure,
in the same way as by so_run_descent
.
This routine requires fload
from the parallel
package
to be available.
See also: so_explore_descent, so_run_descent, so_save_descent, fload.
The following code
pkg load parallel; data = struct (); data.p = so_init_params (false); data.p.vol = 10; data.p.weight = 50; n = 100; x = linspace (-10, 10, n); h = x(2) - x(1); data.g = struct ("x", x, "h", h); data = so_example_problem (data); phi0 = ls_genbasic (data.g.x, "box", -3, 7); printf ("Computing descent...\n"); [pr, pw] = pipe (); d = data; d.handler = struct (); d = so_save_descent (pw, struct (), d); s = so_run_descent (5, phi0, d); fclose (pw); printf ("Final cost: %.6d\n", s.cost); printf ("\nNow replaying...\n"); d = data; d.p.verbose = true; init = @() d; s = so_replay_descent (pr, init); fclose (pr); printf ("Final cost: %.6d\n", s.cost);
Produces the following output
Computing descent... Final cost: 2.3182 Now replaying... Descent iteration 1... Starting cost: 416.408142 Directional derivative: -96606.689008 Armijo step 0.018447: cost = 185.337024 Descent iteration 2... Starting cost: 185.337024 Directional derivative: -58978.562061 Armijo step 0.009671: cost = 69.072101 Descent iteration 3... Starting cost: 69.072101 Directional derivative: -25964.019228 Armijo step 0.007923: cost = 19.832117 Descent iteration 4... Starting cost: 19.832117 Directional derivative: -7932.846879 Armijo step 0.008113: cost = 6.402183 Descent iteration 5... Starting cost: 6.402183 Directional derivative: -2368.400639 Armijo step 0.008308: cost = 2.318204 Final cost: 2.3182
and the following figures
Figure 1 | Figure 2 | Figure 3 | Figure 4 | Figure 5 |
---|---|---|---|---|
Package: level-set