psSparse.h

Go to the documentation of this file.
00001 /* @file  psSparse.h
00002  * @brief functions to manipulate sparse matrices equations
00003  *
00004  * $Revision: 1.8 $ $Name:  $
00005  * $Date: 2007/01/23 22:47:23 $
00006  * Copyright 2004-2005 IfA, University of Hawaii
00007  */
00008 
00009 #ifndef PS_SPARSE_H
00010 #define PS_SPARSE_H
00011 
00012 /// @addtogroup MathOps Mathematical Operations
00013 /// @{
00014 
00015 // constraints to limit the range of the matrix equation solution
00016 typedef struct
00017 {
00018     double paramDelta;
00019     double paramMin;
00020     double paramMax;
00021 }
00022 psSparseConstraint;
00023 
00024 // A sparse matrix equation: A x = Bf
00025 typedef struct
00026 {
00027     psVector *Aij;                      // Aij contains the populated elements of the matrix
00028     psVector *Bfj;                      // Bfj contains the elements of the vector Bf
00029     psVector *Qii;                      // Qii contains the diagonal elements of Aij
00030     psVector *Si;                       // Si contains the i-index values of Aij
00031     psVector *Sj;                       // Sj contains the j-index values of Aij
00032     int Nelem;                         // Number of elements
00033     int Nrows;                         // Number of rows
00034 }
00035 psSparse;
00036 
00037 // The border elements of a sparse matrix equation:
00038 // A = |S B'| where T is a low-rank square matrix (N<20)
00039 //     |B T | and B is a rectangular band (B' is B transpose)
00040 typedef struct
00041 {
00042     psSparse *sparse;   // corresponding sparse matrix equation
00043     psImage *Bij;   // Bij contains the border band (Nrow x Nborder)
00044     psImage *Tjj;   // Tjj contains the square border matrix (Nborder x Nborder)
00045     psVector *Gj;   // XXX lower dependent var drop??
00046     int Nrows;    // Number of rows (long dimension of Bij, 0-j)
00047     int Nborder;   // Number of border elements (size of Qii)
00048 }
00049 psSparseBorder;
00050 
00051 // allocate a sparse matrix structure
00052 psSparse *psSparseAlloc(int Nrows, int Nelem);
00053 
00054 // add a new matrix element
00055 // user should only add elements above the diagonal
00056 bool psSparseMatrixElement(psSparse *sparse, // Matrix to which to add
00057                            int i, int j, // Matrix indices at which to add
00058                            float value  // Value to add
00059                           );
00060 
00061 // define a new sparse matrix equation vector element
00062 void psSparseVectorElement(psSparse *sparse, // Matrix to which to add
00063                            int i,      // Index to add
00064                            float value  // Value to add
00065                           );
00066 
00067 // perform the operation matrix * vector on a sparse matrix and a vector
00068 psVector *psSparseMatrixTimesVector(psVector *output, // Output vector, or NULL
00069                                     const psSparse *matrix, // Sparse matrix
00070                                     const psVector *vector // Corresponding vector
00071                                    );
00072 
00073 // re-sort a sparse matrix to have all elements in index order rather than insertion order
00074 // call this before solving, but after populating matrix and vector
00075 bool psSparseResort(psSparse *sparse    // Matrix to re-sort
00076                    );
00077 
00078 // solve the equation A x = Bf for the value of x
00079 // a good starting guess is the vector Bf
00080 psVector *psSparseSolve(psVector *output,// The output vector, or NULL
00081                         psSparseConstraint constraint, // Constraint to limit the range of the solution
00082                         const psSparse *sparse, // Sparse matrix
00083                         int Niter       // Number of iterations
00084                        );
00085 
00086 // allocate a sparse matrix structure
00087 psSparseBorder *psSparseBorderAlloc(psSparse *sparse, int Nborder);
00088 
00089 bool psSparseBorderElementT(psSparseBorder *border, int i, int j, float value);
00090 
00091 bool psSparseBorderElementB(psSparseBorder *border, int i, int j, float value);
00092 
00093 bool psSparseBorderElementG(psSparseBorder *border, int i, float value);
00094 
00095 psVector *psSparseBorderLowerProduct (psVector *dG, psSparseBorder *border, psVector *xVec);
00096 
00097 psVector *psSparseBorderUpperProduct (psVector *dF, psSparseBorder *border, psVector *yVec);
00098 
00099 psVector *psSparseBorderSquareProduct (psVector *dG, psSparseBorder *border, psVector *yVec);
00100 
00101 bool psSparseBorderUpperDelta (psSparseBorder *border, psVector *dF);
00102 
00103 psVector *psSparseBorderLowerDelta (psVector *Go, psSparseBorder *border, psVector *dG);
00104 
00105 bool psSparseBorderMultiply (psVector **fIn, psVector **gIn, psSparseBorder *border, psVector *xVec, psVector *yVec);
00106 
00107 bool psSparseBorderSolve(psVector **xFit, psVector **yFit, psSparseConstraint constraint, psSparseBorder *border, int Niter);
00108 
00109 /// @}
00110 #endif /* PS_SPARSE_H */

Generated on Fri Feb 2 22:24:35 2007 for pslib by  doxygen 1.5.1