Advanced Octave A21 — Decompositions and effective rank

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

Advanced GNU Octave with GX-TXT · Module 04

The decomposition to singular values, or SVD, reveals how a matrix acts in different directions of intensity. It is particularly useful to understand why the numerical rank depends on the threshold adopted.

Objectives and prerequisites

We repeat the nearly singular matrix of the lesson A20 and the linear algebra of the introductory course. We calculate the SVD via NUMERIC_API_v1/linear_matrix and check the reconstruction. The test uses GX-TXT dev112-P011-bis and GNU Octave 9.4.0.

Calculate and rebuild

Import rango_svd.m, register it and run it in the Runner.

The API returns separate real and imaginary components for decomposition matrices. The script recomposes them with complex and controls the A = U*S*V' report, where ' indicates the transposition conjugated in Octave.

r = gxtxt_api_call('NUMERIC_API_v1','linear_matrix',{'svd',envelope,[]});
U = complex(r.u_real,r.u_imaginary);
S = complex(r.s_real,r.s_imaginary);
V = complex(r.v_real,r.v_imaginary);
s = diag(S);
fprintf('Framework rank=%d, tolerance=%.3e\n',r.rank,r.rank_tolerance);
fprintf('Rank with threshold 1e-5: %d\n',sum(s>1e-5));
fprintf('Reconstruction error: %.3e\n',norm(A-U*S*V','fro'));

In the test the singular values are about 2 and 5 × 10⁻⁷. With the default tolerance given by the framework, about 8,9 × 10⁻¹⁶, the numerical rank is 2. If we count only the higher values of the 10⁻⁵ teaching threshold, the actual rank becomes 1. The program does not change the internal tolerance of the API: it performs this second count separately.

The reconstruction error observed is about 1,2 × 10⁻¹⁵, small for the example scale. It is a complete decomposition control; it does not show that a subsequent solution is insensitive to noise.

Choose a threshold

The exact algebraic rank is a mathematical property; the numerical rank depends on the precision, scale and criterion chosen. A threshold connected to measuring noise or intended use may be more significant than an arbitrary threshold, but must be motivated and declared. Discarding a small direction can make the calculation more stable and at the same time delete information: it is a methodological choice.

Do not necessarily compare individual carriers U and V element by element between libraries: signs and conventions may vary. It controls rather reconstruction and relevant mathematical relationships.

Exercise

  1. Why does the 10⁻⁵ threshold lead here to a rank count one?
  2. Does the program change the internal tolerance of the framework?
  3. What does norm(A-U*S*V','fro') verify?

Worked solution

  1. The second singular value, about 5 × 10⁻⁷, is lower than the threshold.
  2. No. It reads the default rank and calculates apart an alternative count.
  3. As the reconstructed matrix differs from the original in the Frobenius rule.

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