LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiPseudoInverseMP.h

00001 /*
00002  * Copyright (C) 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  * project ....: LTI Digital Image/Signal Processing Library
00026  * file .......: ltiPseudoInverseMP.h
00027  * authors ....: Peter Dörfler
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 6.10.2000
00030  * revisions ..: $Id: ltiPseudoInverseMP.h,v 1.9 2006/02/08 12:40:02 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_PSEUDO_INVERSE_M_P_H_
00034 #define _LTI_PSEUDO_INVERSE_M_P_H_
00035 
00036 #include "ltiLinearAlgebraFunctor.h"
00037 
00038 namespace lti {
00039   /**
00040    * This functor calculates the Moore-Penrose Pseudo-Inverse of a
00041    * matrix.  It is used for solving an over-determined linear
00042    * equation system according to LMS. The pseudo-inverse of \f$H\f$ is
00043    * defined as<p>
00044    * \f$ H^+= (H^t\dot H)^{-1}\dot H^t \f$<p>
00045    * For some applications smoothing of this solution is desired. This is
00046    * achieved through a smoothing Matrix \f$\tilde{H}\f$ and a (small)
00047    * factor \f$\lambda\f$:<p>
00048    * \f$ H^+= (H^t\dot H + \lambda\tilde{H})^{-1}\dot H^t \f$<p>
00049    *
00050    * @ingroup gLinearAlgebra
00051    */
00052   template<class T>
00053   class pseudoInverseMP : public linearAlgebraFunctor {
00054   public:
00055     /**
00056      * the parameters for the class pseudoInverseMP
00057      */
00058     class parameters : public linearAlgebraFunctor::parameters {
00059     public:
00060       // The code must be included here due to (once again)
00061       // another bug of the Visual C++
00062 
00063       /**
00064        * default constructor
00065        */
00066       parameters()
00067         : linearAlgebraFunctor::parameters(),lambda(0.01) {};
00068 
00069       /**
00070        * copy constructor
00071        * @param other the parameters object to be copied
00072        */
00073       parameters(const parameters& other) 
00074         : linearAlgebraFunctor::parameters() {copy(other);};
00075 
00076       /**
00077        * destructor
00078        */
00079       ~parameters() {};
00080 
00081       /**
00082        * returns name of this type
00083        */
00084       const char* getTypeName() const {
00085         return "pseudoInverseMP<T>::parameters";
00086       };
00087 
00088       /**
00089        * copy the contents of a parameters object
00090        * @param other the parameters object to be copied
00091        * @return a reference to this parameters object
00092        */
00093       parameters& copy(const parameters& other) {
00094 #     ifndef _LTI_MSC_6
00095         // MS Visual C++ 6 is not able to compile this ANSI C++...
00096         linearAlgebraFunctor::parameters::copy(other);
00097 #     else
00098         // ...so we have to use this workaround.
00099         // Conditional on that, copy may not be virtual.
00100         functor::parameters& (functor::parameters::* p_copy)
00101         (const functor::parameters&) =
00102         functor::parameters::copy;
00103         (this->*p_copy)(other);
00104 #     endif
00105         lambda = other.lambda;
00106         return *this;
00107       };
00108 
00109       /**
00110        * returns a pointer to a clone of the parameters
00111        */
00112       virtual functor::parameters* clone() const {
00113         return new parameters(*this);
00114       };
00115 
00116       /**
00117        * the smoothing factor
00118        */
00119       double lambda;
00120     };
00121 
00122     /**
00123      * default constructor
00124      */
00125     pseudoInverseMP();
00126 
00127     /**
00128      * Creates a new PseudoInverse %functor with a smoothing factor
00129      * given as the argument
00130      */
00131     pseudoInverseMP(const double& lambda);
00132 
00133     /**
00134      * copy constructor
00135      * @param other the object to be copied
00136      */
00137     pseudoInverseMP(const pseudoInverseMP<T>& other);
00138 
00139     /**
00140      * destructor
00141      */
00142     virtual ~pseudoInverseMP();
00143 
00144     /**
00145      * returns the name of this type ("pseudoInverseMP")
00146      */
00147     virtual const char* getTypeName() const;
00148 
00149     /**
00150      * Calculates the Moore-Penrose pseudo-inverse <b>without</b> smoothing.
00151      * @param src matrix<T> to be inverted
00152      * @param dest Moore-Penrose pseudo-inverse of src
00153      * @result a reference to <code>dest</code>.
00154      */
00155     matrix<T>& apply(const matrix<T>& src,matrix<T>& dest) const;
00156 
00157     matrix<T>& applyS(const matrix<T>& src,matrix<T>& dest) const;
00158 
00159     /**
00160      * Calculates the Moore-Penrose pseudo-inverse <b>with</b> smoothing.
00161      * Do not forget to set parameters::lambda to the desired value.
00162      * @param src matrix<T> to be inverted
00163      * @param smooth matrix<T> used for smoothing
00164      * @param dest Moore-Penrose pseudo-inverse of src
00165      * @result a reference to <code>dest</code>.
00166      */
00167     matrix<T>& apply(const matrix<T>& src,
00168                      const matrix<T>& smooth,
00169                      matrix<T>& dest) const;
00170 
00171     /**
00172      * copy data of "other" functor.
00173      * @param other the functor to be copied
00174      * @return a reference to this functor object
00175      */
00176     pseudoInverseMP<T>& copy(const pseudoInverseMP<T>& other);
00177 
00178     /**
00179      * returns a pointer to a clone of this functor.
00180      */
00181     virtual functor* clone() const;
00182 
00183     /**
00184      * returns used parameters
00185      */
00186     const parameters& getParameters() const;
00187   };
00188 }
00189 
00190 #include "ltiPseudoInverseMP_template.h"
00191 
00192 #endif

Generated on Sat Apr 10 15:26:00 2010 for LTI-Lib by Doxygen 1.6.1