La descomposición en valores singulares consiste en descomponer una matriz \(\mathbf{A}\) de dimensiones \(m\times n\), no necesariamente cuadrada en tres matrices de la forma siguiente: \[ \mathbf{A}=\mathbf{U}\mathbf{D}\mathbf{V}^\top, \] donde
La descomposición de valores singulares de una matriz es una herramienta fundamental en análisis de datos y aprendizaje estadístico.
Las aplicaciones que se derivan de dicha descomposición van desde desde regresión a predicción, hasta encontrar soluciones aproximadas a problemas de optimización.
Veamos cómo funciona dicha aplicación en análisis de datos.
Consideremos una matriz \(\mathbf{A}\) no necesariamente cuadrada de dimensiones \(m\times n\) donde las \(m\) filas serían los individuos y las \(n\) columnas representarían las variables que consideramos sobre dichos individuos.
Cada individuo sería un vector en el espacio \(\mathbb{R}^n\).
Imaginemos que queremos representar dichos individuos en un espacio de dimensión menor \(k<n\).
Para hacerlo, podemos considerar una aproximación de la descomposición en valores singulares de la matriz \(\mathbf{A}\), de la forma siguiente: \[ \tilde{\mathbf{A}}=\mathbf{U}_{m\times m}\tilde{\mathbf{D}}_{m\times k}\tilde{\mathbf{V}}_{k\times k}^\top, \] donde
De esta forma, obtenemos una matriz \(\tilde{\mathbf{A}}\) de dimensiones \(m\times k\) con \(k\) variables que sería una aproximación o una proyección de los datos origionales sobre un espacio menor de dimensión menor \(\mathbb{R}^k\).
Para entender el algoritmo de descomposición en valores singulares y trabajar con matrices no necesariamente cuadradas, necesitamos los conceptos previos siguientes:
Sea \(\mathbf{A}\) una matriz \(m\times n\), entonces:
La dimensión del núcleo de una matriz \(\mathbf{A}\) vale \(\mathrm{dim}(\mathrm{Ker}(\mathbf{A}))=n-\mathrm{Rango}(\mathbf{A}).\)
Recordemos los resultados siguientes de álgebra lineal:
Sea \(\mathbf{A}\) una matriz \(m\times n\). Entonces:
La matriz \(\mathbf{A}^\top\mathbf{A}\) es simétrica porque coincide con su traspuesta: \((\mathbf{A}^\top\mathbf{A})^\top =\mathbf{A}^\top(\mathbf{A}^\top)^\top =\mathbf{A}^\top\mathbf{A}\).
La simetría de la matriz \(\mathbf{A}\mathbf{A}^\top\) se demuestra de forma idéntica.
Veamos primero que \(\mathrm{Ker}(\mathbf{A})\subseteq\mathrm{Ker}(\mathbf{A}^\top\mathbf{A})\): sea \(\mathbf{x}\in\mathrm{Ker}(\mathbf{A})\), entonces \(\mathbf{A}\mathbf{x}=\mathbf{0}\).
Por tanto, \(\mathbf{A}^\top\mathbf{A}\mathbf{x}=\mathbf{A}^\top(\mathbf{A}\mathbf{x})=\mathbf{A}^\top\mathbf{0}=\mathbf{0}\), lo que significa que \(\mathbf{x}\in\mathrm{Ker}(\mathbf{A}^\top\mathbf{A})\).
Veamos ahora que \(\mathrm{Ker}(\mathbf{A}^\top\mathbf{A})\subseteq\mathrm{Ker}(\mathbf{A})\). Sea \(\mathbf{x}\in \mathrm{Ker}(\mathbf{A}^\top\mathbf{A})\), es decir \(\mathbf{A}^\top\mathbf{A}\mathbf{x}=\mathbf{0}\).
En este caso \(\mathbf{x}^\top\mathbf{A}^\top\mathbf{A}\mathbf{x}=\mathbf{x}^\top\mathbf{0}=0=\|\mathbf{A}\mathbf{x}\|_2^2\).
Por tanto, \(\mathbf{A}\mathbf{x}=\mathbf{0}\) al ser \(\|\cdot\|_2\) norma vectorial, lo que significa que \(\mathbf{x}\in\mathrm{Ker}(\mathbf{A})\).
\(\mathrm{Rango}(\mathbf{A})=n-\mathrm{dim}(\mathrm{Ker}(\mathbf{A}))=n-\mathrm{dim}(\mathrm{Ker}(\mathbf{A}^\top\mathbf{A}))=\mathrm{Rango}(\mathbf{A}^\top\mathbf{A})\).
Al ser la matriz \(\mathbf{A}^\top\mathbf{A}\) simétrica, sus valores propios serán reales.
Además, dado un vector \(\mathbf{x}\in\mathbb{R}^n\), tenemos que \(\mathbf{x}^\top\mathbf{A}^\top\mathbf{A}\mathbf{x}=\|\mathbf{A}\mathbf{x}\|_2^2\geq 0\). Es decir, la matriz \(\mathbf{A}^\top\mathbf{A}\) es definida positiva.
Sea \(\lambda\neq 0\) un valor propio no nulo de la matriz \(\mathbf{A}^\top\mathbf{A}\).
Entonces, existe un vector propio \(\mathbf{x}\in\mathbb{R}^n\) tal que \(\mathbf{A}^\top\mathbf{A}\mathbf{x}=\lambda\mathbf{x}\).
Multiplicando por \(\mathbf{A}\) la igualdad anterior tenemos que \(\mathbf{A}\mathbf{A}^\top\mathbf{A}\mathbf{x}=\lambda\mathbf{A}\mathbf{x}\), es decir, el vector \(\mathbf{A}\mathbf{x}\) es un vector propio de valor propio \(\lambda\) de la matriz \(\mathbf{A}\mathbf{A}^\top\).
El valor \(\mathbf{A}\mathbf{x}\neq\mathbf{0}\) ya que en caso contrario, \(\mathbf{A}\mathbf{x}=\mathbf{0}\), y por tanto, \(\mathbf{x}\) sería un vector propio de \(\mathbf{A}\) de valor propio \(\lambda=0\) y habíamos supuesto \(\lambda\neq 0\).
Supongamos ahora que \(\lambda\neq 0\) es un valor propio no nulo de la matriz \(\mathbf{A}\mathbf{A}^\top =(\mathbf{A}^\top)^\top\mathbf{A}^\top\). Aplicando el razonamiento anterior cambiando los papeles de las matrices \(\mathbf{A}^\top\) y \(\mathbf{A}\), tendremos que \(\lambda\) será un valor propio no nulo de la matriz \(\mathbf{A}^\top(\mathbf{A}^\top)^\top =\mathbf{A}^\top\mathbf{A}\), tal como queríamos ver.
Dada una matriz \(\mathbf{A}\) de dimensiones \(m\times n\), es decir, con \(m\) filas y \(n\) columnas, veamos cómo hallar las matrices \(\mathbf{U}\), \(m\times m\), \(\mathbf{D}\), \(m\times n\) y \(\mathbf{V}\), \(n\times n\), tal que \(\mathbf{A}=\mathbf{U}\mathbf{D}\mathbf{V}^\top\):
\[ \mathbf{D}=\begin{bmatrix}\sqrt{\lambda_{1}}&0&\ldots&0&0&\ldots&0 \\0&\sqrt{\lambda_{2}}&\ldots&0&0&\ldots&0 \\\vdots&\vdots&\ddots&\vdots&\vdots&\vdots&\vdots \\0&\ldots&0&\sqrt{\lambda_{k}}&0&\ldots&0 \\0&\ldots&0&0&0&\ldots&0 \\\vdots&\vdots&\vdots&\vdots&\vdots&\ddots&\vdots \\0&\ldots&0&0&0&\ldots&0 \\\end{bmatrix}. \]
Los vectores anteriores son ortogonales ya que: \[ \begin{align*} (\mathbf{u}^{(i)})^\top \mathbf{u}^{(j)} & =\left(\frac{1}{\sqrt{\lambda_i}}\mathbf{A}\mathbf{v}^{(i)}\right)^\top \frac{1}{\sqrt{\lambda_j}}\mathbf{A}\mathbf{v}^{(j)}=\frac{1}{\sqrt{\lambda_i\lambda_j}}(\mathbf{v}^{(i)})^\top\mathbf{A}^\top\mathbf{A}\mathbf{v}^{(j)}\\ & =\frac{1}{\sqrt{\lambda_i\lambda_j}}(\mathbf{v}^{(i)})^\top\lambda_j\mathbf{v}^{(j)}=\frac{\lambda_j}{\sqrt{\lambda_i\lambda_j}}(\mathbf{v}^{(i)})^\top \mathbf{v}^{(j)}=\begin{cases}0, & \mathrm{si\ }i\neq j,\\ 1,&\mathrm{si\ }i=j.\end{cases} \end{align*} \]
Veamos que si aplicamos el algoritmo anterior, se cumple la descomposición de la matriz \(\mathbf{A}\) en valores singulares.
Sea \(k\) el número de valores propios no nulos de la matriz \(\mathbf{A}^\top\mathbf{A}\). Las raíces cuadradas de dichos valores propios se denominan valores singulares de la matriz \(\mathbf{A}\).
Recordemos que:
\(\lambda_1 \geq \lambda_2\geq\cdots\geq \lambda_k > 0=\lambda_{k+1}=\cdots = \lambda_n.\)
\(\mathbf{A}\mathbf{v}^{(i)}=\sqrt{\lambda_i}\mathbf{u}^{(i)}\), para \(i=1,\ldots,k\), y \(\mathbf{A}\mathbf{v}^{(i)}=0\), para \(i=k+1,\ldots,n\).
Entonces: \[ \begin{align*} \mathbf{A}\mathbf{V} & =\mathbf{A}\begin{bmatrix}\mathbf{v}^{(1)}&\cdots &\mathbf{v}^{(k)}&\mathbf{v}^{(k+1)}&\cdots &\mathbf{v}^{(n)}\end{bmatrix} \\ & = \begin{bmatrix}\mathbf{A}\mathbf{v}^{(1)}&\cdots &\mathbf{A}\mathbf{v}^{(k)}&\mathbf{0}&\cdots &\mathbf{0}\end{bmatrix}=\begin{bmatrix}\sqrt{\lambda_1}\mathbf{u}^{(1)}&\cdots &\sqrt{\lambda_k}\mathbf{u}^{(k)}&\mathbf{0}&\cdots &\mathbf{0}\end{bmatrix}\\ & = \begin{bmatrix}\mathbf{u}^{(1)}&\cdots &\mathbf{u}^{(k)}&\mathbf{0}&\cdots &\mathbf{0}\end{bmatrix} \begin{bmatrix}\sqrt{\lambda_{1}}&0&\ldots&0&0&\ldots&0 \\0&\sqrt{\lambda_{2}}&\ldots&0&0&\ldots&0 \\\vdots&\vdots&\ddots&\vdots&\vdots&\vdots&\vdots \\0&\ldots&0&\sqrt{\lambda_{k}}&0&\ldots&0 \\0&\ldots&0&0&0&\ldots&0 \\\vdots&\vdots&\vdots&\vdots&\vdots&\ddots&\vdots \\0&\ldots&0&0&0&\ldots&0 \\\end{bmatrix}. \end{align*} \]
Fijémonos que la igualdad anterior sigue siendo cierta si cambiamos las columnas nulas de la matriz \(\begin{bmatrix}\mathbf{u}^{(1)}&\cdots &\mathbf{u}^{(k)}&\mathbf{0}&\cdots &\mathbf{0}\end{bmatrix}\) por la matriz \(\mathbf{U}=\begin{bmatrix}\mathbf{u}^{(1)}&\cdots &\mathbf{u}^{(k)}&\mathbf{u}^{(k+1)}&\cdots &\mathbf{u}^{(m)}\end{bmatrix}\): \[ \mathbf{A}\mathbf{V}=\begin{bmatrix}\mathbf{u}^{(1)}&\cdots &\mathbf{u}^{(k)}&\mathbf{u}^{(k+1)}&\cdots &\mathbf{u}^{(m)}\end{bmatrix}\begin{bmatrix}\sqrt{\lambda_{1}}&0&\ldots&0&0&\ldots&0 \\0&\sqrt{\lambda_{2}}&\ldots&0&0&\ldots&0 \\\vdots&\vdots&\ddots&\vdots&\vdots&\vdots&\vdots \\0&\ldots&0&\sqrt{\lambda_{k}}&0&\ldots&0 \\0&\ldots&0&0&0&\ldots&0 \\\vdots&\vdots&\vdots&\vdots&\vdots&\ddots&\vdots \\0&\ldots&0&0&0&\ldots&0 \\\end{bmatrix}=\mathbf{U}\mathbf{D}. \] Multiplicando por \(\mathbf{V}^{-1}=\mathbf{V}^\top\), tenemos la descomposición en valores singulares de la matriz \(\mathbf{A}\): \[ \mathbf{A}=\mathbf{U}\mathbf{D}\mathbf{V}^\top. \]
INPUT matriz del sistema
\(\mathbf{A}\) (\(m\times n\)).Calculamos
\(\mathbf{B}=\mathbf{A}^\top\mathbf{A}\).Calculamos
\(\lambda_1 \geq \lambda_2\geq\cdots\geq \lambda_k >0=\lambda_{k+1}=\cdots =\lambda_n\) los valores propios de la matriz
\(\mathbf{B}\) con base de vectores propios ortogonal
\(\mathbf{v}^{(1)},\mathbf{v}^{(2)},\ldots,\mathbf{v}^{(k)},\mathbf{v}^{(k+1)},\ldots,\mathbf{v}^{(n)}\).Set
\(\mathbf{D}=\mathbf{0}\). (\(m\times n\)) (Inicializamos la matriz \(\mathbf{D}\))For i=1,...,k
Set
\(d_{ii}=\sqrt{\lambda_i}\). (construimos la matriz \(\mathbf{D}\))Set
\(\mathbf{V}=\mathbf{0}\). (\(n\times n\)) (Inicializamos la matriz \(\mathbf{V}\))For i=1,...,n
Set
\(\mathbf{V}[,i]=\mathbf{v}^{(i)}\). (construimos la matriz \(\mathbf{V}\))Set
\(\mathbf{U}=\mathbf{0}\). (\(m\times m\)) (Inicializamos la matriz \(\mathbf{U}\))For i=1,...,k
Set
\(\mathbf{U}[,i]=\frac{1}{\sqrt{\lambda_i}}\mathbf{A}\mathbf{v}^{(i)}\) (construimos la matriz \(\mathbf{U}\))Consideremos la matriz siguiente formada por \(m=6\) filas y \(n=4\) columnas: \[ \mathbf{A}=\begin{bmatrix}5&6&5&7 \\6&4&5&4 \\6&6&6&6 \\5&8&4&13 \\6&2&5&0 \\6&7&7&6 \\\end{bmatrix}. \]
\[ \mathbf{u}^{(3)} =\frac{1}{\sqrt{\lambda_3}}\mathbf{A}\mathbf{v}^{(3)}=\frac{1}{1.806754}\begin{bmatrix}5&6&5&7 \\6&4&5&4 \\6&6&6&6 \\5&8&4&13 \\6&2&5&0 \\6&7&7&6 \\\end{bmatrix}\begin{bmatrix}0.652776 \\-0.581879 \\-0.395746 \\0.280509 \\\end{bmatrix}=\begin{bmatrix}-0.134255 \\0.405391 \\-0.14725 \\0.3722 \\0.428484 \\-0.688345 \\\end{bmatrix}. \] Las tres primeras columnas de la matriz \(\mathbf{U}\) serían las siguientes: \[ \begin{bmatrix}-0.407584&0.057794&-0.134255 \\-0.327593&-0.285263&0.405391 \\-0.419074&-0.150305&-0.14725 \\-0.549528&0.655029&0.3722 \\-0.210881&-0.65136&0.428484 \\-0.452198&-0.198396&-0.688345 \\\end{bmatrix}. \]
La matriz \(\mathbf{U}\) sería por tanto: \[ \mathbf{U}=\begin{bmatrix}-0.407584&0.057794&-0.134255&*&*&* \\-0.327593&-0.285263&0.405391&*&*&* \\-0.419074&-0.150305&-0.14725&*&*&* \\-0.549528&0.655029&0.3722&*&*&* \\-0.210881&-0.65136&0.428484&*&*&* \\-0.452198&-0.198396&-0.688345&*&*&* \\\end{bmatrix}. \] donde las tres últimas columnas de asteriscos se puede substituir por tres vectores que hagan que la matriz \(\mathbf{U}\) sea ortogonal pero de cara a la descomposición en valores singulares \(\mathbf{A}=\mathbf{U}\mathbf{D}\mathbf{V}^\top\) podemos substituir dichas columnas por los valores que queramos, la igualdad anterior siempre se mantendría.
Eso sí, si escribimos valores cualesquiera, la matriz \(\mathbf{U}\) ya no sería ortogonal pero se mantrendría la igualdad de descomposición en valores singulares. Basta saber que existen tres vectores \(\mathbf{u}^{(4)},\mathbf{u}^{(5)},\mathbf{u}^{(6)}\) que hacen que la matriz \(\mathbf{U}\) es ortogonal pero saber qué valen dichos vectores es irrevelante.