libtpcmodel
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines
Functions
lss_lib.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include "include/lss_lib.h"
Include dependency graph for lss_lib.c:

Go to the source code of this file.

Functions

void _lss_print_matrix (const double *M, int m, int n)
void _lss_print_matrix2 (const double *M, int m, int n, int ice, int icv)
double _lss_compare_matrix (const double *A, const double *B, int m, int n)
void _lss_matrix_times_vector (const double *M, int m, int n, int m_t, int n_t, const double *v, int ie, double *x)
int _lss_h12 (int mode, int lpivot, int l1, int m, double *u, int u_dim1, double *up, double *cm, int ice, int icv, int ncv)
void _lss_g1 (double a, double b, double *cterm, double *sterm, double *sig)
int _lss_hfti (double *A, int m_a, int m, int n_a, int n, double *B, int m_b, int n_b, double tau, int *krank, double *rnorm, double *w1, double *w2, int *ip)

Function Documentation

double _lss_compare_matrix ( const double *  A,
const double *  B,
int  m,
int  n 
)

Compares two m * n sized matrix and calculates

sum{i = 0...m}{ sum{j = 0...n } { (a_i,j - b_i,j)^2 } }

Returns:
sum of squared element differenses
Parameters:
AInput matrix A size: mxn
BInput matrix B size: mxn
mmatrix height
nmatrix width

Definition at line 124 of file lss_lib.c.

Referenced by do_ldp(), do_lse(), do_lsi(), do_lss_hfti(), and do_nnls().

void _lss_g1 ( double  a,
double  b,
double *  cterm,
double *  sterm,
double *  sig 
)

Compute orthogonal rotation matrix: (C, S) so that (C, S)(A) = (sqrt(A**2+B**2)) (-S,C) (-S,C)(B) ( 0 ) Compute sig = sqrt(A**2+B**2): sig is computed last to allow for the possibility that sig may be in the same location as A or B.

Definition at line 390 of file lss_lib.c.

Referenced by nnls().

int _lss_h12 ( int  mode,
int  lpivot,
int  l1,
int  m,
double *  u,
int  u_dim1,
double *  up,
double *  cm,
int  ice,
int  icv,
int  ncv 
)

Construction and/or application of a single Householder transformation: Q = I + U*(U**T)/B

Function returns 0 if succesful, or >0 in case of erroneous parameters.

Parameters:
modemode=1 to construct and apply a Householder transformation, or mode=2 to apply a previously constructed transformation
lpivotIndex of the pivot element, on pivot vector
l1Transformation is constructed to zero elements indexed from l1 to M
mTransformation is constructed to zero elements indexed from l1 to M
uWith mode=1: On entry, u[] must contain the pivot vector. On exit, u[] and up contain quantities defining the vector u[] of the Householder transformation. With mode=2: On entry, u[] and up should contain quantities previously computed with mode=1. These will not be modified.
u_dim1u_dim1 is the storage increment between elements.
upwith mode=1, here is stored an element defining housholder vector scalar, on mode=2 it's only used, and is not modified
cmOn entry, cm[] must contain the matrix (set of vectors) to which the Householder transformation is to be applied. On exit, cm[] will contain the set of transformed vectors
iceStorage increment between elements of vectors in cm[]
icvStorage increment between vectors in cm[]
ncvNr of vectors in cm[] to be transformed; if ncv<=0, then no operations will be done on cm[]

Definition at line 191 of file lss_lib.c.

References ABS, LSS_TEST, and MAX.

Referenced by _lss_hfti(), do_lss_h12(), lse(), lsi(), and nnls().

int _lss_hfti ( double *  A,
int  m_a,
int  m,
int  n_a,
int  n,
double *  B,
int  m_b,
int  n_b,
double  tau,
int *  krank,
double *  rnorm,
double *  w1,
double *  w2,
int *  ip 
)

Solve least squares problem by housholder transformations

Solves Ax = b, but B can be matrix when it's columns are considered as distinct solutions

On successfull exit matrix B will contain the corresponding solution vectors

Returns:
0 on success 1 on failure ( dimension error, out of memory )
Parameters:
AA is a m_a * n_a matrix, defining the A'x = b, where A' is first m columns of A
m_amatrix A dimension (true size)
mmatrix A dimension, dimension that will be user to solve the eq
n_amatrix A dimension (true size)
nmatrix A dimension, dimension that will be used to solve the eq
BB is a m_b * n_b size matrix defining the right hand side vectors b_i
m_bmatrix B dimension
n_bmatrix B dimension
tausmallest number that is considered to be non-zero
krankwill contain pseudorank of the matrix on succesfull calculation
rnormvector of size n_b * 1, will containt residual norm of the solutin after successfull calculation, can be NULL
w1working space 1, n_a * 1 sized vector (array), if NULL then it will be allocated (and deleted) by the routine
w2working space 2, n_a * 1 sized vector (array), if NULL then it will be allocated (and deleted) by the routine
ipn_a * 1 vector where routine records indices describing the permutation of column vectors, can be NULL

Definition at line 422 of file lss_lib.c.

References _lss_h12(), _lss_print_matrix(), _lss_print_matrix2(), ABS, LSS_TEST, and MIN.

Referenced by do_lss_hfti(), and lse().

Here is the call graph for this function:

void _lss_matrix_times_vector ( const double *  M,
int  m,
int  n,
int  m_t,
int  n_t,
const double *  v,
int  ie,
double *  x 
)

Calculates x = M*v, where M is m * n matrix

actually matrix M is size m_t * n_t, but only first m * n values are used.

Parameters:
MThe input matrix, true size m_t * n_t
mDimension used in multiply
nDimension used in multiply
m_tThe matrix true dimension
n_tThe matrix true dimension
vVector that is multiplied with
ieIncrement between element of vector
xresulting vector

Definition at line 154 of file lss_lib.c.

Referenced by lsi().

void _lss_print_matrix ( const double *  M,
int  m,
int  n 
)

Prints matrix M of m * n sized matrix to stdout

See also:
_lss_print_matrix2
Parameters:
Mmatrix to print
mM dimension is m x n
nM dimension is m x n

Definition at line 68 of file lss_lib.c.

Referenced by _lss_hfti(), do_ldp(), do_lse(), do_lsi(), do_lss_h12(), do_lss_hfti(), do_nnls(), ldp(), lse(), lsi(), and nnls().

void _lss_print_matrix2 ( const double *  M,
int  m,
int  n,
int  ice,
int  icv 
)

Prints matrix M of m * n sized matrix to stdout, with increment between element being ice and increament between vector icv

See also:
_lss_print_matrix
Parameters:
Mmatrix to print
mM dimension is m x n
nM dimension is m x n
iceIncrement between elements on matrix
icvIncrement between vectors on matrix

Definition at line 94 of file lss_lib.c.

Referenced by _lss_hfti().