Type: Package
Title: Fast Non-Negative Least Squares
Version: 0.0.1
Date: 2026-03-11
Description: Provides a fast algorithm for solving non-negative least squares problems. It implements the Fast Non-Negative Least Squares algorithm of Bro and de Jong (1997) <doi:10.1002/(SICI)1099-128X(199709/10)11:5%3C393::AID-CEM483%3E3.0.CO;2-L>.
License: GPL-2 | GPL-3 [expanded from: GPL (≥ 2)]
Imports: Rcpp (≥ 1.1.1)
LinkingTo: Rcpp, RcppEigen
RoxygenNote: 7.3.3
Encoding: UTF-8
Suggests: testthat (≥ 3.0.0)
Config/testthat/edition: 3
NeedsCompilation: yes
Packaged: 2026-03-19 16:24:30 UTC; nikolask
Author: Nikolaos Kontemeniotis [aut, cre], Michail Tsagris [aut]
Maintainer: Nikolaos Kontemeniotis <kontemeniotisn@gmail.com>
Repository: CRAN
Date/Publication: 2026-03-24 08:50:02 UTC

nnsolve: Fast Non-Negative Least Squares

Description

Provides a fast algorithm for solving non-negative least squares problems. It implements the Fast Non-Negative Least Squares algorithm of Bro and de Jong (1997) doi:10.1002/(SICI)1099-128X(199709/10)11:5<393::AID-CEM483>3.0.CO;2-L.

Author(s)

Maintainer: Nikolaos Kontemeniotis kontemeniotisn@gmail.com

Authors:


Fast Non-Negative Least Squares

Description

Solves the NNLS problem min ||Xty - XtX * w||^2 subject to w >= 0 using the Fast Non-Negative Least Squares algorithm of Bro & de Jong (1997).

Usage

fnnls(
  XtX,
  Xty,
  tol = 1e-06,
  max_iter = 1000,
  sum_to_constant = FALSE,
  constant = 1,
  lower_bound = FALSE,
  lb = 0
)

Arguments

XtX

symmetric positive definite matrix of dimensions k x k

Xty

numeric vector of length k

tol

convergence tolerance. Default 1e-6

max_iter

maximum number of iterations. Default 1000

sum_to_constant

if TRUE all entries sum to 'constant'.Default FALSE

constant

if sum_to_constant is TRUE, all entries sum to this number. Default 1

lower_bound

if TRUE all entries bounded below by 'lb', otherwise they are nonnegative. Default FALSE

lb

if lower_bound is TRUE all entries are bounded below by 'lb'. Default 0

Value

non-negative numeric vector of length k

References

Bro, Rasmus & Jong, Sijmen. (1997). A Fast Non-negativity-constrained Least Squares Algorithm. Journal of Chemometrics. 11. 393-401. 10.1002/(SICI)1099-128X(199709/10)11:53.0.CO;2-L.

Examples

k <- 10
D <- 100
H   <- matrix(rnorm(k * D), nrow = k, ncol = D)
x   <- rnorm(D)
XtX <- H %*% t(H) + diag(1e-8, k)
Xty <- as.vector(H %*% x)
w   <- fnnls(XtX, Xty)