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

ltiCosinusSimilarity.h

00001 /*
00002  * Copyright (C) 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 .......: ltiCosinusSimilarity.h
00027  * authors ....: Stefan Syberichs, Jochen Wickel
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 30.1.2001
00030  * revisions ..: $Id: ltiCosinusSimilarity.h,v 1.4 2006/02/08 12:15:30 ltilib Exp $
00031  */
00032 
00033 #ifndef _COSINUS_SIMILARITY_H_
00034 #define _COSINUS_SIMILARITY_H_
00035 
00036 #include "ltiSimilarityFunctor.h"
00037 
00038 namespace lti {
00039 
00040   /**
00041    * Quadratic Cosinus Similarity
00042    *
00043    * This class computes the similarity of two vectors or matrices
00044    * by means of the quadratic cosinus of the angle between the two vectors.
00045    *
00046    */
00047   template <class T>
00048   class cosinus2Similarity : public similarityFunctor<T> {
00049   public:
00050     /**
00051      * default constructor
00052      */
00053     cosinus2Similarity();
00054 
00055     /**
00056      * copy constructor
00057      * @param other the object to be copied
00058      */
00059     cosinus2Similarity(const cosinus2Similarity<T>& other);
00060 
00061     /**
00062      * destructor
00063      */
00064     virtual ~cosinus2Similarity();
00065 
00066     /**
00067      * returns the name of this type ("cosinus2Similarity")
00068      */
00069     virtual const char* getTypeName() const;
00070 
00071     /**
00072      * calculates the quadratic cosinus-type of similarity of the
00073      * vectors a and b.
00074      *
00075      * If both vectors have different sizes, the returned value will
00076      * be negative!
00077      *
00078      * @param a the first vector<T>
00079      * @param b the second vector<T>
00080      * @return the cos2-type similarity of a and b
00081      */
00082     T apply(const vector<T>& a, const vector<T>& b) const;
00083 
00084     /**
00085      * Take the matrices as vectors and compute the similarity of
00086      * them.
00087      * @return the cos2-type of similarity of a and b
00088      */
00089     T apply(const matrix<T>& a, const matrix<T>& b) const;
00090 
00091     /**
00092      * Compute the similarity for each row-vector in the matrix a
00093      * and b.
00094      *
00095      * If b.size() != a.columns() an empty vector will be returned.
00096      * Otherwise, the element i of the vector dest will contain the
00097      * cos2 similarity between the i-th row of a and b.
00098      * @return always null
00099      */
00100     vector<T>& apply(const matrix<T>& a,
00101                      const vector<T>& b,
00102                            vector<T>& dest) const;
00103 
00104     /**
00105      * copy data of "other" functor.
00106      * @param other the functor to be copied
00107      * @return a reference to this functor object
00108      */
00109     cosinus2Similarity& copy(const cosinus2Similarity& other);
00110 
00111     /**
00112      * returns a pointer to a clone of this functor.
00113      */
00114     virtual functor* clone() const;
00115 
00116   };
00117 
00118 
00119 }
00120 
00121 #include "ltiCosinusSimilarity_template.h"
00122 
00123 #endif

Generated on Sat Apr 10 15:25:18 2010 for LTI-Lib by Doxygen 1.6.1