Description Usage Arguments Details Value References See Also Examples
Consider the linear system \bold{A} x = b where \bold{A} \in R\textsuperscript{m x n}, x \in R\textsuperscript{n}, and b \in R\textsuperscript{m}. The technique of least squares proposes to compute x so that the sum of squared residuals is minimized. NNLS
solves the least squares problem \min{||\bold{A} x = b||\textsuperscript{2}} subject to the constraint x ≥ 0. This implementation of the Sequential Coordinate-wise Algorithm uses a sparse input matrix \bold{A}, which makes it efficient for large sparse problems.
1 2 3 4 5 |
A |
List representing the sparse matrix with integer components i and j, numeric component x. The fourth component, dimnames, is a list of two components that contains the names for every row (component 1) and column (component 2). |
b |
Numeric matrix for the set of observed values. (See details section below.) |
precision |
The desired accuracy. |
processors |
The number of processors to use, or |
verbose |
Logical indicating whether to display progress. |
The input b can be either a matrix or a vector of numerics. If it is a matrix then it is assumed that each column contains a set of observations, and the output x will have the same number of columns. This allows multiple NNLS problems using the same \bold{A} matrix to be solved simultaneously, and greatly accelerates computation relative to solving each sequentially.
A list of two components:
x |
The matrix of non-negative values that best explains the observed values given by b. |
res |
A matrix of residuals given by \bold{A} x - b. |
Franc, V., et al. (2005). Sequential coordinate-wise algorithm for the non-negative least squares problem. Computer Analysis of Images and Patterns, 407-414.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # unconstrained least squares:
A <- matrix(c(1, -3, 2, -3, 10, -5, 2, -5, 6), ncol=3)
b <- matrix(c(27, -78, 64), ncol=1)
x <- solve(crossprod(A), crossprod(A, b))
# Non-negative least squares:
w <- which(A > 0, arr.ind=TRUE)
A <- list(i=w[,"row"], j=w[,"col"], x=A[w],
dimnames=list(1:dim(A)[1], 1:dim(A)[2]))
x_nonneg <- NNLS(A, b)
# compare the unconstrained and constrained solutions:
cbind(x, x_nonneg$x)
# the input value "b" can also be a matrix:
b2 <- matrix(b, nrow=length(b), ncol=2) # repeat b in two columns
x_nonneg <- NNLS(A, b2) # solution is repeated in two output columns
|
Loading required package: Biostrings
Loading required package: BiocGenerics
Loading required package: parallel
Attaching package: 'BiocGenerics'
The following objects are masked from 'package:parallel':
clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
clusterExport, clusterMap, parApply, parCapply, parLapply,
parLapplyLB, parRapply, parSapply, parSapplyLB
The following objects are masked from 'package:stats':
IQR, mad, sd, var, xtabs
The following objects are masked from 'package:base':
Filter, Find, Map, Position, Reduce, anyDuplicated, append,
as.data.frame, basename, cbind, colMeans, colSums, colnames,
dirname, do.call, duplicated, eval, evalq, get, grep, grepl,
intersect, is.unsorted, lapply, lengths, mapply, match, mget,
order, paste, pmax, pmax.int, pmin, pmin.int, rank, rbind,
rowMeans, rowSums, rownames, sapply, setdiff, sort, table, tapply,
union, unique, unsplit, which, which.max, which.min
Loading required package: S4Vectors
Loading required package: stats4
Attaching package: 'S4Vectors'
The following object is masked from 'package:base':
expand.grid
Loading required package: IRanges
Loading required package: XVector
Attaching package: 'Biostrings'
The following object is masked from 'package:base':
strsplit
Loading required package: RSQLite
|
| | 0%
|
|============== | 20%
|
|========================================== | 60%
|
|======================================================== | 80%
|
|======================================================================| 100%
Time difference of 0.01 secs
[,1] [,2]
1 1 17
2 -4 0
3 7 5
|
| | 0%
|
|============== | 20%
|
|========================================== | 60%
|
|======================================================== | 80%
|
|======================================================================| 100%
Time difference of 0.01 secs
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.