Navigation

Operators and Keywords

Function List:

C++ API

Function File: so_explore_descent (file, init)

Interactively explore a descent file saved by so_save_descent. This opens a shell where the user can navigate through the replay.

The arguments are the same as for so_replay_descent. In order to allow backwards navigation, file must either be a file name or a file descriptor that allows seeking.

On the initial call, the initialised handler is called. Then, before_step, direction and after_step will be called for the currently active data at each navigation of the user. Note that the descent steps on which they are called may be out-of-order and may skip intermediate iterations. The finished handler will be called with the data that is active when the user closes the interactive session.

Note that data.log.steps and data.log.costs will always contain all steps and costs that have been loaded during the replay so far, which may not correspond to the currently active step. These fields will be present in all calls to handlers except initialised, not just for the call to finished.

In addition to the default handlers in handler of the data struct, also extra handlers can be defined in data.onFirst. They will be called in order and on each iteration when it is first loaded from the descent log. The finished handler will be called on the last iteration data that has been loaded before the session is terminated. This may not be the active data at that point in time, if the user has navigated backwards. The onFirst handlers (if present) will be called before the corresponding handler functions.

No on-the-fly computation of extra steps (as it is done by so_replay_descent when not enough steps are saved in the log) is supported by this routine. Instead, it is simply not possible to step beyond EOF of the log file.

This routine requires fload from the parallel package to be available.

See also: so_replay_descent, so_run_descent, so_save_descent, fload.

Demonstration 1

The following code

  pkg load parallel;

  data = struct ();
  data.p = so_init_params (false);
  data.p.vol = 10;
  data.p.weight = 50;

  data.p.nSteps = 10;
  data.figs = struct ();
  data.figs.speed = figure ();
  data.figs.exploreCosts = figure ();

  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");
  f = tmpfile ();
  d = data;
  d.handler = struct ();
  d = so_save_descent (f, struct (), d);
  s = so_run_descent (data.p.nSteps, phi0, d);
  printf ("Final cost: %.6d\n", s.cost);

  printf ("\nNow replaying...\n");
  init = @() data;
  frewind (f);
  so_explore_descent (f, init);
  fclose (f);

Produces the following output

Computing descent...
Final cost: 6.03673e-05

Now replaying...
@ step 1>

and the following figures

Figure 1 Figure 2

Package: level-set