Advanced Octave A32 — Nonlinear fitting and initialization

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

Advanced GNU Octave with GX-TXT · Module 06

In a non-linear fit, the initial values can influence research. Comparing more reasonable initializations is a useful control, although without guaranteeing by itself to have found the best possible solution.

Objectives and data

We repeat regression and callback from the introductory course and the A23 lesson. We adapt A exp(−k t) to 21 synthetic values generated with A=3, k=0,5 and a small deterministic sinusoidal disturbance. They are not measures and perturbation is not a statistical model of noise. The test uses GX-TXT dev112-P011-bis and GNU Octave 9.4.0.

Compare two initial points

Import fit_esponenziale.m, record it in the Session and start it in the Runner.

The program records a callback @(p,x) p(1)*exp(-p(2)*x) and calls NUMERIC_API_v1/nonlinear_fit with the same observations but two initial vectors: (2; 0,2) and (4; 1). The cleaning section releases the callback.

In the test both attempts report convergence and parameters about A=3,0081 and k=0,5009, which coincide with the accuracy displayed. They are close to the values used to generate the ideal signal, but the added disturbance explains why they should not coincide exactly.

What to control beyond convergence

The two initializations examined achieve similar results in this case; other functions or intervals may have minimum local, unidentified parameters or convergence failures. Diagnostic verification, residues, parameter scale and data hypotheses. If the solver does not converge, do not present the parameters as a successful fit.

In a physical application declares the units: if the time is in seconds, k is in s⁻¹; the amplitude has the response unit. The compatibility of the units is part of the model and is not automatically deducted from the formula.

Exercise

  1. Why are the estimated parameters not exactly 3 and 0,5?
  2. Two similar results show that every possible initialization will work?
  3. Which unit has k if the time is expressed in seconds?

Worked solution

  1. The synthetic signal includes a deterministic disturbance in addition to the ideal exponential model.
  2. No. It is a limited verification to the two initial points tested.
  3. Seconds at least one, s⁻¹.

Download the Module 06 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 *