SpectralUnmix: A Torch-Based Regularized Non-negative Matrix Factorization
Rafael S. de Souza, Paula Coelho, Niranjana P, Ana L. Chies-Santos, Rogério Riffel · 2026
Read SpectralUnmix: A Torch-Based Regularized Non-negative Matrix Factorization by Rafael S. de Souza, Paula Coelho, Niranjana P, Ana L. Chies-Santos, Rogério Riffel (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2603-11111.txt.
Introduction
Rafael de Souza and coauthors present SpectralUnmix, an R package. It factors spectra into low-rank non-negative components, using regularized non-negative matrix factorization built on the torch library. Proximal-gradient updates estimate the parts. Users can add graphics processor acceleration and smoothness regularization along the spectral axis. As a demo, they apply it to a subset of stellar spectra and compare the parts with principal-component directions and with real stellar spectra.
Catalog record
| CREATOR | Rafael S. de Souza, Paula Coelho, Niranjana P, Ana L. Chies-Santos, Rogério Riffel |
|---|---|
| YEAR | 2026 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 5665 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2603.11111
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
SpectralUnmix: A Torch-Based Regularized Non-negative Matrix Factorization
Rafael S. de Souza, Paula Coelho, Niranjana P, Ana L. Chies-Santos, Rogério Riffel
Abstract
We present SpectralUnmix , an R package for regularized non-negative matrix factorization (NMF), implemented in torch with optional GPU acceleration. The package estimates low-rank non-negative representations through proximal-gradient updates and allows smoothness regularization along the spectral axis. As a compact demonstration, we apply the method to a subset of stellar spectra and compare the recovered NMF components with principal-component directions and representative stellar spectra. The package is released under the MIT license at this repository .
I
Introduction
Many spectral datasets can be represented as matrices in which rows correspond to samples and columns correspond to wavelength channels. A common objective in exploratory analysis is to describe such data through a small number of latent components and their corresponding weights.
Principal component analysis
(
Jolliffe & Cadima 2016
, PCA;)
has long been used in astronomy for this purpose
(
Ronen et al. 1999
;
Steiner et al. 2009
;
Ishida & de Souza 2013
;
Joseph et al. 2014
;
de Souza et al. 2014
;
de Souza et al. 2022
, e.g.)
, providing an orthogonal basis that captures the dominant variance in spectral datasets.
Non-negative matrix factorization (NMF) offers an alternative decomposition in which both the components and their weights are constrained to be non-negative
(
Lee & Seung 1999
)
. Because astronomical spectra represent non-negative flux measurements, imposing non-negativity often yields components that are more directly interpretable in physical terms
(
Blanton & Roweis 2007
;
Hurley et al. 2013
;
Melchior et al. 2018
, e.g.)
. Such representations arise naturally in applications ranging from stellar libraries to spatially resolved spectroscopy.
Our
R
package provides a general-purpose implementation of regularized NMF with
torch
as the computational backend. It is designed for exploratory decomposition problems where smooth, non-negative spectral components are desirable.
II
Method
Let
\mathbf{X}
be a non-negative data matrix
\mathbf{X}\in\mathbb{R}_{+}^{N\times P}
,
where
N
denotes the number of samples and
P
the number of spectral channels. We seek a low-rank non-negative representation
\mathbf{X}\approx\mathbf{A}\mathbf{S}
,
with
\mathbf{A}\in\mathbb{R}_{+}^{N\times K}
, and
\mathbf{S}\in\mathbb{R}_{+}^{K\times P}
.
The rows of
\mathbf{S}
define
K
latent spectra, while the columns of
\mathbf{A}
contain the corresponding non-negative weights.
We estimate
\mathbf{A}
and
\mathbf{S}
by solving
\min_{\mathbf{A},\mathbf{S}\geq 0}\frac{1}{2}\left\|\mathbf{X}-\mathbf{A}\mathbf{S}\right\|_{F}^{2}+\lambda\left\|\mathbf{S}\mathbf{D}^{\top}\right\|_{F}^{2},
(1)
where
\mathbf{D}\in\mathbb{R}^{(P-1)\times P}
is the first-order finite-difference operator along the spectral axis,
\mathbf{D}=\begin{bmatrix}-1&1&0&\dots&0\\
0&-1&1&\dots&0\\
\vdots&&&\ddots&\\
0&0&0&-1&1\end{bmatrix},
(2)
so that the regularization penalizes large bin-to-bin variations and encourages smooth spectral components. In this case
\left\|\mathbf{S}\mathbf{D}^{\top}\right\|_{F}^{2}=\sum_{k=1}^{K}\sum_{j=1}^{P-1}\left(S_{k,j+1}-S_{k,j}\right)^{2}.
(3)
The first term in
Equation 1
measures reconstruction fidelity, while the second penalizes channel-to-channel roughness in the recovered spectra. The standard NMF is recovered when
\lambda=0
. The optimization is implemented in
torch
via alternating proximal-gradient updates
(
Xu & Yin 2013
)
.
III
Analysis
Here we apply
SpectralUnmix
to a subset of 80 representative stellar spectra from the spectral library of
Coelho 2014
, spanning four broad classes: hot stars, A/F stars, solar-like stars, and cool dwarfs, with 20 spectra per class. We fit a four-component NMF model and compare the recovered components with PCA obtained from the same data.
Figure 1
summarizes this toy experiment. Panel A shows the class prototype spectra; panels B and C display the PCA and NMF eigenspectra, respectively, with colors indicating their one-to-one assignment to the prototype classes. For each component–class pair we compute the
\chi^{2}
distance between the corresponding eigenspectrum and the class prototype. Finally, panel D summarizes the class–component distances. In this example, the recovered NMF components trace physically recognizable spectral shapes while remaining smooth and non-negative by construction.
Figure 1:
Panel A shows four representative normalized spectra out a sample of 80. Panels B and C compare PCA and NMF eigenspectra derived from the same data; colors indicate the stellar class assigned to each component through a one-to-one matching based on a simple
\chi^{2}
-like distance between normalized spectral shapes. Panel D summarizes the class–component distances for PCA and NMF.
IV
Conclusions
SpectralUnmix
provides an extensible implementation of regularized NMF for spectral data analysis using
torch
in
R
. The package supports GPU acceleration and optional smoothness constraints, making it suitable for exploratory decomposition of high-dimensional spectral datasets. Although demonstrated here on a simple stellar library example, the framework is general and can be readily applied to a wide range of astronomical problems, including stellar population studies, hyperspectral imaging, and integral-field spectroscopy.