latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 00025 /*---------------------------------------------------------------- 00026 * project ....: LTI Digital Image/Signal Processing Library 00027 * file .......: ltiMatrixDecomposition.h 00028 * authors ....: Thomas Rusert 00029 * organization: LTI, RWTH Aachen 00030 * creation ...: 23.06.99 00031 * revisions ..: $Id: ltiMatrixDecomposition.h,v 1.5 2006/02/08 12:35:00 ltilib Exp $ 00032 */ 00033 00034 #ifndef _LTI_MATRIX_DECOMPOSITON_H_ 00035 #define _LTI_MATRIX_DECOMPOSITON_H_ 00036 00037 #include "ltiLinearAlgebraFunctor.h" 00038 #include "ltiMatrix.h" 00039 #include "ltiVector.h" 00040 00041 namespace lti { 00042 /** 00043 * LU decomposition functor. 00044 * Computes the LU decomposition of a square matrix. 00045 * 00046 * The decomposition will fail if the matrix is singular or close to 00047 * being singular. 00048 * 00049 * @ingroup gLinearAlgebra 00050 */ 00051 template<class T> 00052 class luDecomposition : public linearAlgebraFunctor { 00053 // store the last result 00054 matrix<T> luRef; 00055 vector<int> permRef; 00056 // this is true if there is some valid LU decomposition. 00057 bool haveLU; 00058 int pivsign; 00059 public: 00060 00061 static const T my_epsilon; 00062 00063 /// default constructor 00064 luDecomposition(); 00065 00066 /** 00067 * Constructs a LU decomposition for the given matrix The functor 00068 * internally stores the decomposition, so you can get the derived 00069 * parts with getL, getU and det. The matrix itself is not 00070 * changed, so if you need the LU decomposition in the given 00071 * matrix itself, you will have to use one of the apply methods. 00072 * @param m the matrix that gets decomposed. 00073 */ 00074 luDecomposition(const matrix<T> &m); 00075 00076 /// destructor 00077 virtual ~luDecomposition(); 00078 00079 /** onPlace version of apply. 00080 Given a matrix theMatrix[0..n-1][0..n-1], this routine replaces it by 00081 the LU decomposition of a rowwise permutation of itself. 00082 permutation[0..n-1] is an output vector that records the row 00083 permutation effected by the partial pivoting. The function returns 00084 +/-1 depending on whether the number of row interchanges was even or 00085 odd, respectively. The functor internally stores a copy of the 00086 last decomposition, so you can use it for det and getL and getU. 00087 @return true, if the decomposition could be computed, false 00088 otherwise (typically, the matrix was singular). 00089 */ 00090 bool apply(matrix<T>& theMatrix,vector<int>& permutation, bool store=true); 00091 00092 /** onCopy version of apply. 00093 Given a matrix theMatrix[0..n-1][0..n-1], this routine returns a matrix 00094 decomposition[0..n-1][0..n-1] which contains the LU decomposition of a 00095 rowwise permutation of theMatrix. permutation[0..n-1] is an output 00096 vector that records the row permutation effected by the partial 00097 pivoting. The function returns +/-1 depending on whether the number of 00098 row interchanges was even or odd, respectively. The functor internally 00099 stores a copy of the 00100 last decomposition, so you can use it for det and getL and getU. 00101 @return true, if the decomposition could be computed, false 00102 otherwise (typically, the matrix was singular). 00103 */ 00104 bool apply(const matrix<T>& theMatrix, matrix<T>& decompositon, 00105 vector<int>& permutation); 00106 00107 /// copy data of "other" functor. 00108 luDecomposition<T>& copy(const luDecomposition<T>& other); 00109 00110 /// returns a pointer to a clone of the functor. 00111 virtual functor* clone() const { return (new luDecomposition<T>(*this));}; 00112 /// returns the name of this type 00113 virtual const char* getTypeName() const {return "luDecompositon";}; 00114 00115 /** 00116 returns a new Matrix which contains the "L" part of the last 00117 performed decomposition. 00118 */ 00119 matrix<T> getL() const; 00120 00121 /** 00122 returns a new Matrix which contains the "U" part of the last 00123 performed decomposition. 00124 */ 00125 matrix<T> getU() const; 00126 00127 /** 00128 * returns a new Matrix which contains the "L" part of the last 00129 * performed decomposition. This is much faster than the on 00130 * copy version. 00131 */ 00132 void getL(matrix<T>& l) const; 00133 00134 /** 00135 * returns a new Matrix which contains the "L" part of the last 00136 * performed decomposition. This is much faster than the on 00137 * copy version 00138 */ 00139 void getU(matrix<T>& u) const; 00140 00141 /// returns the determinant of the last given matrix 00142 T det() const; 00143 00144 /// returns the determinant of the given matrix 00145 T det(const matrix<T> &theMatrix); 00146 00147 /// returns true if the last given matrix was regular, i.e. non-singular 00148 bool isRegular() const; 00149 00150 /// returns true if the given matrix was regular, i.e. non-singular 00151 bool isRegular(const matrix<T> &theMatrix); 00152 00153 }; 00154 } 00155 00156 #endif