Advanced Octave A73 — Optimization landscapes and 3D trajectories
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
- What is the exact minimum of the function?
- Does the point after 20 steps coincide exactly with the minimum?
- Why flank a 2D chart?
Worked solution
- Zero at
(0,5; -0,25)point. - No: it is close, but the objective value is still about 0,000532.
- To read the decrease for iteration without depending on the 3D perspective.
Other steps of this project
- Advanced Octave A75 — Dynamical systems in phase space
- Advanced Octave A81 — Geography of the waves and a 3D surface
- Advanced Octave A82 — Age, sex and demographic inequalities
- Advanced Octave A83 — All-cause mortality, certified COVID deaths and surveillance
- Advanced Octave A84 — A reproducible public account
- Advanced Octave A74 — RLC response surfaces