RcdMathLib_doc
Open Source Library for Linear and Non-linear Algebra
svd.c File Reference

Algorithm for the Singular Value Decomposition (SVD). Provide necessary methods to compute the compact SVD of a matrix. A = U*S*V, where U is a (m x l) orthogonal matrix, S is a (l x l) diagonal matrix, V is a (l x n) orthogonal matrix, and l = min(m,n). The SVD is computed by using the Golub–Kahan–Reinsch algorithm that works in two phases: bidiagonalization and a reduction to the diagonal form phase. More...

#include <stdbool.h>
#include <inttypes.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include "svd.h"
#include "matrix.h"
#include "vector.h"

Go to the source code of this file.

Functions

void svd_get_U_dim (uint8_t m, uint8_t n, matrix_dim_t *u_dim)
 Calculate the dimension of the matrix U. More...
 
void svd_get_S_dim (uint8_t m, uint8_t n, matrix_dim_t *s_dim)
 Calculate the dimension of the matrix S. More...
 
void svd_get_V_dim (uint8_t m, uint8_t n, matrix_dim_t *v_dim)
 Calculate the dimension of the matrix V. More...
 
uint8_t svd_get_single_values_num (uint8_t m, uint8_t n)
 Calculate the number of the singular values. More...
 
void svd (uint8_t m, uint8_t n, matrix_t A[m][n], uint8_t u_m, uint8_t u_n, matrix_t U[u_m][u_n], matrix_t S[u_n][n], matrix_t V[n][n], uint8_t sing_vec_length, matrix_t singl_values_vec[])
 Compute the Singular-Value Decomposition (SVD) of a matrix. More...
 
void svd_get_reciproc_singular_values (uint8_t m, uint8_t n, uint8_t length, matrix_t singl_values_arr[], matrix_t recip_singl_values_arr[])
 Compute the reciprocal singular values. More...
 
void svd_compute_print_U_S_V_s (uint8_t m, uint8_t n, matrix_t matrix_arr[m][n], uint8_t i)
 Compute and print the SVD of a matrix. More...
 

Detailed Description

Algorithm for the Singular Value Decomposition (SVD). Provide necessary methods to compute the compact SVD of a matrix. A = U*S*V, where U is a (m x l) orthogonal matrix, S is a (l x l) diagonal matrix, V is a (l x n) orthogonal matrix, and l = min(m,n). The SVD is computed by using the Golub–Kahan–Reinsch algorithm that works in two phases: bidiagonalization and a reduction to the diagonal form phase.

Author
Zakaria Kasmi zkasm.nosp@m.i@in.nosp@m.f.fu-.nosp@m.berl.nosp@m.in.de

Definition in file svd.c.

Function Documentation

◆ svd()

void svd ( uint8_t  m,
uint8_t  n,
matrix_t  A[m][n],
uint8_t  u_m,
uint8_t  u_n,
matrix_t  U[u_m][u_n],
matrix_t  S[u_n][n],
matrix_t  V[n][n],
uint8_t  sing_vec_length,
matrix_t  singl_values_vec[] 
)

Compute the Singular-Value Decomposition (SVD) of a matrix.

Matrix A is transformed to A = U*S*V, where U and V are unitary matrices, and S is a diagonal matrix.

Parameters
[in]mrow number of the matrix A.
[in]ncolumn number of the matrix A.
[in,out]A[][]pointer to the matrix A.
[in]u_mrow number of the matrix U.
[in]u_ncolumn number of the matrix U.
[in,out]U[][]pointer to the matrix U.
[in,out]S[][]pointer to the matrix S.
[in,out]V[][]pointer to the matrix V.
[in]sing_vec_lengthlength of the singular vector.
[in,out]singl_values_vec[]pointer to the vector saving the singular values.

Definition at line 119 of file svd.c.

Referenced by matrix_get_two_norm(), svd_compute_print_U_S_V_s(), and trilateration_get_rank_and_homogeneous_solution().

◆ svd_compute_print_U_S_V_s()

void svd_compute_print_U_S_V_s ( uint8_t  m,
uint8_t  n,
matrix_t  matrix_arr[m][n],
uint8_t  i 
)

Compute and print the SVD of a matrix.

Parameters
[in]mrow number of the matrix to transform in SVD.
[in]ncolumn number of the matrix to transform in SVD.
[in]matrix_arr[][]pointer to the matrix.
[in]ilabel.

Definition at line 766 of file svd.c.

References matrix_dim_t::col_num, matrix_print(), matrix_t, matrix_dim_t::row_num, svd(), svd_get_single_values_num(), and svd_get_U_dim().

Referenced by svd_test().

◆ svd_get_reciproc_singular_values()

void svd_get_reciproc_singular_values ( uint8_t  m,
uint8_t  n,
uint8_t  length,
matrix_t  singl_values_arr[],
matrix_t  recip_singl_values_arr[] 
)

Compute the reciprocal singular values.

This method is based on the singular values.

Parameters
[in]mrow number of the matrix to transform in SVD.
[in]ncolumn number of the matrix to transform in SVD.
[in]lengthlength of the array of single values.
[in]singl_values_arrpointer to the array of single values.
[out]recip_singl_values_arrpointer to the array of the reciprocal singular values.

Definition at line 747 of file svd.c.

References matrix_t.

◆ svd_get_S_dim()

void svd_get_S_dim ( uint8_t  m,
uint8_t  n,
matrix_dim_t s_dim 
)

Calculate the dimension of the matrix S.

Parameters
[in]mrow number of the matrix to decompose.
[in]ncolumn number of the matrix to decompose.
[out]s_dimpointer to the dimension struct.

Definition at line 102 of file svd.c.

References matrix_dim_t::row_num.

◆ svd_get_single_values_num()

uint8_t svd_get_single_values_num ( uint8_t  m,
uint8_t  n 
)

Calculate the number of the singular values.

Parameters
[in]mrow number of the matrix to decompose.
[in]ncolumn number of the matrix to decompose.
Returns
the number of the singular values.

Definition at line 114 of file svd.c.

Referenced by matrix_get_two_norm(), moore_penrose_get_pinv(), svd_compute_print_U_S_V_s(), and trilateration_get_rank_and_homogeneous_solution().

◆ svd_get_U_dim()

void svd_get_U_dim ( uint8_t  m,
uint8_t  n,
matrix_dim_t u_dim 
)

Calculate the dimension of the matrix U.

Parameters
[in]mrow number of the matrix to decompose.
[in]ncolumn number of the matrix to decompose.
[out]u_dimpointer to the dimension struct.

Definition at line 96 of file svd.c.

References matrix_dim_t::col_num, and matrix_dim_t::row_num.

Referenced by matrix_get_two_norm(), moore_penrose_get_pinv(), svd_compute_print_U_S_V_s(), and trilateration_get_rank_and_homogeneous_solution().

◆ svd_get_V_dim()

void svd_get_V_dim ( uint8_t  m,
uint8_t  n,
matrix_dim_t v_dim 
)

Calculate the dimension of the matrix V.

Parameters
[in]mrow number of the matrix to decompose.
[in]ncolumn number of the matrix to decompose.
[out]v_dimpointer to the dimension struct.

Definition at line 108 of file svd.c.

References matrix_dim_t::col_num, and matrix_dim_t::row_num.