|
TPCCLIB
|
NNLS (non-negative least squares) and required subroutines. More...
#include "tpcclibConfig.h"#include <stdio.h>#include <stdlib.h>#include <math.h>#include "tpcextensions.h"#include "tpclinopt.h"Go to the source code of this file.
Functions | |
| int | nnlsq (NNLSQDATA *d, int verbose) |
| void | nnlsqDataInit (NNLSQDATA *d) |
| void | nnlsqDataFree (NNLSQDATA *d) |
| int | nnlsqDataAllocate (NNLSQDATA *d, const int n, const int m) |
| int | nnlsqWght (NNLSQDATA *d, double *weight) |
| int | nnlsqWghtSquared (NNLSQDATA *d, double *sweight) |
NNLS (non-negative least squares) and required subroutines.
This routine is based on the text and Fortran code in C.L. Lawson and R.J. Hanson, Solving Least Squares Problems, Prentice-Hall, Englewood Cliffs, New Jersey, 1974.
Definition in file nnlsq.c.
| int nnlsq | ( | NNLSQDATA * | d, |
| int | verbose ) |
Algorithm NNLS (Non-negative least-squares).
The same algorithm as nnls(), but this one gets its data in a struct, and max iteration number and dependence factor (previously fixed to 0.01) can be set as function parameters in the struct.
Given an m by n matrix A, and an m-vector B, computes an n-vector X, that solves the least squares problem A * X = B , subject to X>=0
Instead of pointers for working space, NULL can be given to let this function to allocate and free the required memory.
| d | Pointer to structure containing the data and place for the results. |
| verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 55 of file nnlsq.c.
| int nnlsqDataAllocate | ( | NNLSQDATA * | d, |
| const int | n, | ||
| const int | m ) |
Allocate memory for NNLSQDATA (and set data pointers inside the structure). Any previous contents are deleted. Contents are set to NaN or zero.
| d | Pointer to initiated structure; any old contents are deleted. |
| n | Number of parameters (columns of matrix A). |
| m | Number of samples (rows of matrix A). |
Definition at line 411 of file nnlsq.c.
| void nnlsqDataFree | ( | NNLSQDATA * | d | ) |
Free memory allocated for NNLSQDATA data. All contents are destroyed.
| d | Pointer to structure. |
Definition at line 378 of file nnlsq.c.
Referenced by nnlsqDataAllocate().
| void nnlsqDataInit | ( | NNLSQDATA * | d | ) |
Initiate the NNLSQDATA structure before any use.
| d | Pointer to structure to initiate before use. |
Definition at line 357 of file nnlsq.c.
Referenced by nnlsqDataFree().
| int nnlsqWght | ( | NNLSQDATA * | d, |
| double * | weight ) |
Algorithm for weighting the problem that is given to NNLS-algorithm.
Square roots of weights are used because in NNLS the difference w*A-w*b is squared.
| d | Pointer to filled data structure. |
| weight | Weights for each sample (array of length M). |
Definition at line 470 of file nnlsq.c.
| int nnlsqWghtSquared | ( | NNLSQDATA * | d, |
| double * | sweight ) |
Algorithm for weighting the problem that is given to NNLS-algorithm.
Square roots of weights are used because in NNLS the difference w*A-w*b is squared. Here user must give squared weights; this makes calculation faster, when this function needs to be called many times.
| d | Pointer to filled data structure. |
| sweight | Squared weights for each sample (array of length d->m). |