Advanced Octave A73 — Optimization landscapes and 3D trajectories

by Giux GX-TXT, octave-en, scripts-en 2 min read

Advanced GNU Octave with GX-TXT · Module 13

A goal function can be seen as a landscape: looking for a minimum means moving towards a lower area. We build a surface, a trajectory and a 2D view of the objective value.

Objectives and prerequisites

We repeat gradients and optimization of module 04 and the PlotSpec 3D of A41. The test uses GX-TXT dev112-P011-bis and GNU Octave 9.4.0. Import and run paesaggio.m, then convergenza.m. The first creates the octave_landscape IDs, octave_landscape_path and octave_landscape_objective, which are created-only: to repeat, use a new session or change the IDs in the two scripts.

A well known landscape

The dimensionless function is f(x,y) = (x-0,5)^2 + 2*(y+0,25)^2; the exact minimum is zero in (0,5; -0,25). The surface uses a 31×31 grid between −2 and 2 on both axes:

The valley shape illustrates the different curvature along the two directions. Axle margins are automatically chosen by the maker and can exceed the league lattice.

An explicit descent

The program starts from (-1,5; 1,5) and runs 20 p_next = p - 0,1*grad(f) steps. This is an explicit didactic implementation, not a call to the minimize solutor; optimization APIs were introduced in A23. The trajectory is shown in a separate 3D figure, with Z equal to the objective value:

In the test the value drops from 10,125 to about 0.000532; the final point is about (0,476942; -0,249936). The 2D chart created by the second script shows the value at each step:

The surface and the trajectory are seen separately, not an overlap. The perspective can hide distances and minimums; it always compares coordinates and numerical values. In more complex problems the initial point and step size can change convergence.

Exercise

  1. What is the exact minimum of the function?
  2. Does the point after 20 steps coincide exactly with the minimum?
  3. Why flank a 2D chart?

Worked solution

  1. Zero at (0,5; -0,25) point.
  2. No: it is close, but the objective value is still about 0,000532.
  3. To read the decrease for iteration without depending on the 3D perspective.

Download the Module 13 scripts (ZIP)

#GNU Octave #GX-TXT #GX-TXT public APIs

Other steps of this project

Leave a Reply

Your email address will not be published. Required fields are marked *