latest version v1.9 - last update 10 Apr 2010 |
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 /*---------------------------------------------------------------- 00026 * project ....: LTI Digital Image/Signal Processing Library 00027 * file .......: ltiL2Distance.h 00028 * authors ....: Jochen Wickel 00029 * organization: LTI, RWTH Aachen 00030 * creation ...: 28.6.2000 00031 * revisions ..: $Id: ltiL2Distance.h,v 1.10 2006/02/08 12:29:29 ltilib Exp $ 00032 */ 00033 00034 #ifndef _LTI_L2_DISTANCE_H_ 00035 #define _LTI_L2_DISTANCE_H_ 00036 00037 #include "ltiPoint.h" 00038 #include "ltiRGBPixel.h" 00039 #include <vector> 00040 #include "ltiDistanceFunctor.h" 00041 #include "ltiDistanceType.h" 00042 00043 namespace lti { 00044 00045 /** 00046 * @name Square of Euclidian Distances Functions. 00047 * 00048 * Global functions to compute the distance between two n-dimensional 00049 * point representations 00050 * 00051 * @ingroup gLinearAlgebra 00052 */ 00053 //@{ 00054 00055 /** 00056 * distanceSqr computes the square of the euclidian distance between 00057 * the lti::vectors a and b. 00058 */ 00059 template<class T> 00060 typename distanceType<T>::square_distance_type 00061 distanceSqr(const vector<T>& a, const vector<T>& b) { 00062 typename vector<T>::const_iterator ita,itb,ite; 00063 assert(a.size()==b.size()); 00064 typename distanceType<T>::square_distance_type sum(0); 00065 T dif; 00066 for (ita=a.begin(),itb=b.begin(),ite=a.end(); 00067 ita!=ite; 00068 ++ita,++itb) { 00069 dif = (*ita)-(*itb); 00070 sum+=static_cast<typename distanceType<T>::square_distance_type> 00071 (dif*dif); 00072 } 00073 return sum; 00074 } 00075 00076 /** 00077 * distanceSqr computes the square of the euclidian distance between 00078 * the lti::matrix a and b. 00079 */ 00080 template<class T> 00081 typename distanceType<T>::square_distance_type 00082 distanceSqr(const matrix<T>& a, const matrix<T>& b) { 00083 typename matrix<T>::const_iterator ita,itb,ite; 00084 assert(a.size()==b.size()); 00085 typename distanceType<T>::square_distance_type sum(0); 00086 T dif; 00087 for (ita=a.begin(),itb=b.begin(),ite=a.end(); 00088 ita!=ite; 00089 ++ita,++itb) { 00090 dif = (*ita)-(*itb); 00091 sum+=static_cast<typename distanceType<T>::square_distance_type> 00092 (dif*dif); 00093 } 00094 return sum; 00095 } 00096 00097 /** 00098 * distanceSqr computes the square of the euclidian distance between 00099 * the std::vectors a and b. 00100 */ 00101 template<class T> 00102 typename distanceType<T>::square_distance_type 00103 distanceSqr(const std::vector<T>& a, const std::vector<T>& b) { 00104 typename std::vector<T>::const_iterator ita,itb,ite; 00105 assert(a.size()==b.size()); 00106 typename distanceType<T>::square_distance_type sum(0); 00107 T dif; 00108 for (ita=a.begin(),itb=b.begin(),ite=a.end(); 00109 ita!=ite; 00110 ++ita,++itb) { 00111 dif = (*ita)-(*itb); 00112 sum+=static_cast<typename distanceType<T>::square_distance_type> 00113 (dif*dif); 00114 } 00115 return sum; 00116 } 00117 00118 00119 /** 00120 * distanceSqr computes the square of the euclidian distance between 00121 * the points a and b. 00122 */ 00123 template<class T> 00124 inline typename distanceType<T>::square_distance_type 00125 distanceSqr(const tpoint<T>& a, const tpoint<T>& b) { 00126 return static_cast<typename distanceType<T>::square_distance_type> 00127 (a.distanceSqr(b)); 00128 } 00129 00130 /** 00131 * distanceSqr computes the square of the euclidian distance between 00132 * the points a and b. 00133 */ 00134 template<class T> 00135 inline typename distanceType<T>::square_distance_type 00136 distanceSqr(const tpoint3D<T>& a, const tpoint3D<T>& b) { 00137 return static_cast<typename distanceType<T>::square_distance_type> 00138 (a.distanceSqr(b)); 00139 } 00140 00141 /** 00142 * distanceSqr computes the square of the euclidian distance between 00143 * the RGB values a and b in the RGB color space. 00144 */ 00145 template<class T> 00146 inline typename distanceType<T>::square_distance_type 00147 distanceSqr(const trgbPixel<T>& a, const trgbPixel<T>& b) { 00148 return static_cast<typename distanceType<T>::square_distance_type> 00149 (a.distanceSqr(b)); 00150 } 00151 00152 /** 00153 * distanceSqr computes the square of the euclidian distance between 00154 * the RGB values a and b in the RGB color space. 00155 */ 00156 inline distanceType<rgbPixel>::square_distance_type 00157 distanceSqr(const rgbPixel& a, const rgbPixel& b) { 00158 return static_cast<distanceType<rgbPixel>::square_distance_type> 00159 (a.distanceSqr(b)); 00160 } 00161 //@} 00162 00163 /** 00164 * Policy class used by several classifiers/trees to measure the square 00165 * of the euclidian distance between two points of type T. 00166 * 00167 * The type T MUST define the \a value_type type, which exist for example 00168 * for vectors, (t)points and (t)rgbPixels. 00169 * 00170 * If you \e really want, you can use this class directly through the 00171 * operator(). 00172 * 00173 * \code 00174 * l2SquareDistantor< vector<double> > myDist; 00175 * dvector a,b; 00176 * ... // fill vectors with data 00177 * double dist = myDist(a,b); 00178 * \endcode 00179 * 00180 * But remember that there is also a global template function distanceSqr() 00181 * which is easier to use: 00182 * 00183 * \code 00184 * dvector a,b; 00185 * ... // fill vectors with data 00186 * double dist = distanceSqr(a,b); 00187 * \endcode 00188 * 00189 * You can of course also use the lti::l2Distance functor, as usual with its 00190 * apply() methods. 00191 */ 00192 #ifdef _LTI_MSC_6 00193 template <class T, class D=distanceType<T>::square_distance_type> 00194 #else 00195 template <class T, class D=typename distanceType<T>::square_distance_type> 00196 #endif 00197 class l2SquareDistantor { 00198 public: 00199 /** 00200 * type returned by the distantor 00201 */ 00202 typedef D distance_type; 00203 00204 /** 00205 * compute the distance between a and b 00206 */ 00207 inline distance_type operator()(const T& a,const T& b) const { 00208 return 00209 static_cast<distance_type>(distanceSqr(a,b)); 00210 }; 00211 00212 /** 00213 * @name Special methods for Minkowski distances 00214 */ 00215 //@{ 00216 00217 /** 00218 * This member accumulates in the given accumulator, the 00219 * given element. 00220 * 00221 * It can be used when the distance need to be computed manually, but 00222 * using a distantor to still allow the flexibility of changing distances. 00223 * 00224 * For the l2SquareDistantor this is just acc+=(elem*elem). 00225 * 00226 * @param element component of the difference between two points. 00227 * @param accumulator variable where the elements will be accumulated. 00228 */ 00229 inline void accumulate(const distance_type element, 00230 distance_type& accumulator) const { 00231 accumulator+=(element*element); 00232 } 00233 00234 /** 00235 * This member accumulates in the given accumulator, the difference 00236 * of the given elements. 00237 * 00238 * It can be used when the distance need to be computed manually, but 00239 * using a distantor to still allow the flexibility of changing distances. 00240 * 00241 * For the l2SquareDistantor this is just acc+=((elem1-elem2)^2). 00242 * 00243 * @param element1 component of the first point 00244 * @param element2 component of the second point 00245 * @param accumulator variable where the elements will be accumulated. 00246 */ 00247 inline void accumulate(const typename T::value_type element1, 00248 const typename T::value_type element2, 00249 distance_type& accumulator) const { 00250 const distance_type tmp = static_cast<distance_type>(element2-element1); 00251 accumulator+=(tmp*tmp); 00252 } 00253 00254 /** 00255 * Compute from the given accumulator the desired distance 00256 */ 00257 inline distance_type 00258 computeDistance(const distance_type& accumulator) const { 00259 return accumulator; 00260 } 00261 00262 /** 00263 * return the distance between two components, which is in some way 00264 * a component of the total distance (that is the reason for the name). 00265 * 00266 * For this distantor it return (element2-element1)^2 00267 */ 00268 inline distance_type 00269 component(const typename T::value_type element1, 00270 const typename T::value_type element2) const { 00271 const distance_type tmp = static_cast<distance_type>(element2-element1); 00272 return tmp*tmp; 00273 } 00274 00275 /** 00276 * Return true if the given partial computed from accumulator is less than 00277 * the given distance. 00278 * 00279 * Assume you have accumulated \a acc until now, and you want to check if 00280 * the partial distance derived from this accumulator is less than 00281 * the given distance. So you check accLessThan(accumulator,distance) 00282 * 00283 * For this norm it computes acc < dist 00284 */ 00285 inline bool accLessThan(const distance_type acc, 00286 const distance_type dist) const { 00287 return (acc < dist); 00288 } 00289 00290 /** 00291 * Return true if the given partial computed from accumulator is greater 00292 * than the given distance. 00293 * 00294 * Assume you have accumulated \a acc until now, and you want to check if 00295 * the partial distance derived from this accumulator is greater than 00296 * the given distance. So you check accLessThan(accumulator,distance) 00297 * 00298 * For this norm it computes acc > dist 00299 */ 00300 inline bool accGreaterThan(const distance_type acc, 00301 const distance_type dist) const { 00302 return (acc > dist); 00303 } 00304 //@} 00305 }; 00306 00307 // specialization for rgbPixels 00308 // template <> 00309 // class l2SquareDistantor<rgbPixel> { 00310 // public: 00311 // /* 00312 // * type returned by the distantor 00313 // */ 00314 // typedef int distance_type; 00315 00316 // /* 00317 // * compute the distance between a and b 00318 // */ 00319 // inline distance_type operator()(const rgbPixel& a, 00320 // const rgbPixel& b) const { 00321 // return distanceSqr(a,b); 00322 // } 00323 00324 // /** 00325 // * @name Special methods for Minkowski distances 00326 // */ 00327 // //@{ 00328 00329 // /** 00330 // * This member accumulates in the given accumulator, the 00331 // * given element. 00332 // * 00333 // * It can be used when the distance need to be computed manually, but 00334 // * using a distantor to still allow the flexibility of changing distances. 00335 // * 00336 // * For the l2SquareDistantor this is just acc+=(elem*elem). 00337 // * 00338 // * @param element component of the difference between two points. 00339 // * @param accumulator variable where the elements will be accumulated. 00340 // */ 00341 // inline void accumulate(const int element, 00342 // distance_type& accumulator) const { 00343 // accumulator+=(element*element); 00344 // } 00345 00346 // /** 00347 // * This member accumulates in the given accumulator, the difference 00348 // * of the given elements. 00349 // * 00350 // * It can be used when the distance need to be computed manually, but 00351 // * using a distantor to still allow the flexibility of changing distances. 00352 // * 00353 // * For the l2SquareDistantor this is just acc+=((elem2-elem1)^2). 00354 // * 00355 // * @param element1 component of the first point 00356 // * @param element2 component of the second point 00357 // * @param accumulator variable where the elements will be accumulated. 00358 // */ 00359 // inline void accumulate(const ubyte element1, 00360 // const ubyte element2, 00361 // distance_type& accumulator) const { 00362 // const int tmp = static_cast<int>(element2)-static_cast<int>(element1); 00363 // accumulator+=(tmp*tmp); 00364 // } 00365 00366 // /** 00367 // * Compute from the given accumulator the desired distance 00368 // */ 00369 // inline distance_type 00370 // computeDistance(const distance_type& accumulator) const { 00371 // return accumulator; 00372 // } 00373 00374 // /** 00375 // * return the distance between two components, which is in some way 00376 // * a component of the total distance (that is the reason for the name). 00377 // * 00378 // * For this distantor it return (element2-element1)^2 00379 // */ 00380 // inline distance_type 00381 // component(const ubyte element1, 00382 // const ubyte element2) const { 00383 // const distance_type tmp = 00384 // static_cast<distance_type>(element2) - 00385 // static_cast<distance_type>(element1); 00386 // return tmp*tmp; 00387 // } 00388 00389 // /** 00390 // * Return true if the given partial computed from accumulator is less than 00391 // * the given distance. 00392 // * 00393 // * Assume you have accumulated \a acc until now, and you want to check if 00394 // * the partial distance derived from this accumulator is less than 00395 // * the given distance. So you check accLessThan(accumulator,distance) 00396 // * 00397 // * For this norm it computes acc < (dist*dist) 00398 // */ 00399 // inline bool accLessThan(const distance_type acc, 00400 // const distance_type dist) const { 00401 // return (acc < (dist*dist)); 00402 // } 00403 00404 // /** 00405 // * Return true if the given partial computed from accumulator is greater 00406 // * than the given distance. 00407 // * 00408 // * Assume you have accumulated \a acc until now, and you want to check if 00409 // * the partial distance derived from this accumulator is less than 00410 // * the given distance. So you check accLessThan(accumulator,distance) 00411 // * 00412 // * For this norm it computes acc > (dist*dist) 00413 // */ 00414 // inline bool accGreaterThan(const distance_type acc, 00415 // const distance_type dist) const { 00416 // return (acc > (dist*dist)); 00417 // } 00418 // //@} 00419 // }; 00420 00421 /** 00422 * Policy class used by several classifiers/trees to measure the 00423 * euclidian distance between two points of type T. 00424 * 00425 * The type T MUST define the \a value_type type, which exist for example 00426 * for vectors, (t)points and (t)rgbPixels. 00427 * 00428 * If you \e really want, you can use this class directly through the 00429 * operator(). 00430 * 00431 * \code 00432 * l2Distantor< vector<double> > myDist; 00433 * dvector a,b; 00434 * ... // fill vectors with data 00435 * double dist = myDist(a,b); 00436 * \endcode 00437 * 00438 * But remember that there is also a global template function distanceSqr() 00439 * which can be more easily used: 00440 * 00441 * \code 00442 * dvector a,b; 00443 * ... // fill vectors with data 00444 * double dist = sqrt(distanceSqr(a,b)); 00445 * \endcode 00446 * 00447 * You can of course also use the lti::l2Distance functor, as usual with its 00448 * apply() methods. 00449 */ 00450 #ifdef _LTI_MSC_6 00451 template <class T, class D=distanceType<T>::fp_distance_type> 00452 #else 00453 template <class T, class D=typename distanceType<T>::fp_distance_type> 00454 #endif 00455 class l2Distantor { 00456 public: 00457 /** 00458 * type returned by the distantor 00459 */ 00460 typedef D distance_type; 00461 00462 /** 00463 * compute the distance between a and b 00464 */ 00465 inline distance_type operator()(const T& a,const T& b) const { 00466 return sqrt(static_cast<distance_type>(distanceSqr(a,b))); 00467 } 00468 00469 /** 00470 * @name Special methods for Minkowski distances 00471 */ 00472 //@{ 00473 00474 /** 00475 * This member accumulates in the given accumulator, the 00476 * given element. 00477 * 00478 * It can be used when the distance need to be computed manually, but 00479 * using a distantor to still allow the flexibility of changing distances. 00480 * 00481 * For the l2Distantor this is just acc+=(elem*elem). 00482 * 00483 * @param element component of the difference between two points. 00484 * @param accumulator variable where the elements will be accumulated. 00485 */ 00486 inline void accumulate(const distance_type element, 00487 distance_type& accumulator) const { 00488 accumulator+=(element*element); 00489 } 00490 00491 /** 00492 * This member accumulates in the given accumulator, the difference 00493 * of the given elements. 00494 * 00495 * It can be used when the distance need to be computed manually, but 00496 * using a distantor to still allow the flexibility of changing distances. 00497 * 00498 * For the l2Distantor this is just acc+=((elem2-elem1)^2). 00499 * 00500 * @param element1 component of the first point 00501 * @param element2 component of the second point 00502 * @param accumulator variable where the elements will be accumulated. 00503 */ 00504 inline void accumulate(const typename T::value_type element1, 00505 const typename T::value_type element2, 00506 distance_type& accumulator) const { 00507 const distance_type tmp = static_cast<distance_type>(element2-element1); 00508 accumulator+=(tmp*tmp); 00509 } 00510 00511 /** 00512 * Compute from the given accumulator the desired distance 00513 */ 00514 inline distance_type 00515 computeDistance(const distance_type& accumulator) const { 00516 return sqrt(accumulator); 00517 } 00518 00519 /** 00520 * return the distance between two components, which is in some way 00521 * a component of the total distance (that is the reason for the name). 00522 * 00523 * For this distantor it return abs(element2-element1) 00524 */ 00525 inline distance_type 00526 component(const typename T::value_type element1, 00527 const typename T::value_type element2) const { 00528 return static_cast<distance_type>(abs(element2-element1)); 00529 } 00530 00531 /** 00532 * Return true if the given partial computed from accumulator is less than 00533 * the given distance. 00534 * 00535 * Assume you have accumulated \a acc until now, and you want to check if 00536 * the partial distance derived from this accumulator is less than 00537 * the given distance. So you check accLessThan(accumulator,distance) 00538 * 00539 * For this norm it computes acc < (dist*dist) 00540 */ 00541 inline bool accLessThan(const distance_type acc, 00542 const distance_type dist) const { 00543 return (acc < (dist*dist)); 00544 } 00545 00546 /** 00547 * Return true if the given partial computed from accumulator is greater 00548 * than the given distance. 00549 * 00550 * Assume you have accumulated \a acc until now, and you want to check if 00551 * the partial distance derived from this accumulator is less than 00552 * the given distance. So you check accLessThan(accumulator,distance) 00553 * 00554 * For this norm it computes acc > (dist*dist) 00555 */ 00556 inline bool accGreaterThan(const distance_type acc, 00557 const distance_type dist) const { 00558 return (acc > (dist*dist)); 00559 } 00560 //@} 00561 }; 00562 00563 // template <> 00564 // class l2Distantor<rgbPixel> { 00565 // public: 00566 // /* 00567 // * type returned by the distantor 00568 // */ 00569 // typedef int distance_type; 00570 00571 // /* 00572 // * compute the distance between a and b 00573 // */ 00574 // inline distance_type operator()(const rgbPixel& a, 00575 // const rgbPixel& b) const { 00576 // return sqrt(distanceSqr(a,b)); 00577 // } 00578 00579 // /** 00580 // * @name Special methods for Minkowski distances 00581 // */ 00582 // //@{ 00583 00584 // /** 00585 // * This member accumulates in the given accumulator, the 00586 // * given element. 00587 // * 00588 // * It can be used when the distance need to be computed manually, but 00589 // * using a distantor to still allow the flexibility of changing distances. 00590 // * 00591 // * For the l2Distantor this is just acc+=(elem*elem). 00592 // * 00593 // * @param element component of the difference between two points. 00594 // * @param accumulator variable where the elements will be accumulated. 00595 // */ 00596 // inline void accumulate(const int element, 00597 // distance_type& accumulator) const { 00598 // accumulator+=(element*element); 00599 // } 00600 00601 // /** 00602 // * This member accumulates in the given accumulator, the difference 00603 // * of the given elements. 00604 // * 00605 // * It can be used when the distance need to be computed manually, but 00606 // * using a distantor to still allow the flexibility of changing distances. 00607 // * 00608 // * For the l2Distantor this is just acc+=((elem2-elem1)^2). 00609 // * 00610 // * @param element1 component of the first point 00611 // * @param element2 component of the second point 00612 // * @param accumulator variable where the elements will be accumulated. 00613 // */ 00614 // inline void accumulate(const ubyte element1, 00615 // const ubyte element2, 00616 // distance_type& accumulator) const { 00617 // const distance_type tmp = 00618 // static_cast<int>(element2)-static_cast<int>(element1); 00619 // accumulator+=(tmp*tmp); 00620 // } 00621 00622 // /** 00623 // * Compute from the given accumulator the desired distance 00624 // */ 00625 // inline distance_type 00626 // computeDistance(const distance_type& accumulator) const { 00627 // return sqrt(accumulator); 00628 // } 00629 00630 // /** 00631 // * return the distance between two components, which is in some way 00632 // * a component of the total distance (that is the reason for the name). 00633 // * 00634 // * For this distantor it return abs(element2-element1) 00635 // */ 00636 // inline distance_type 00637 // component(const ubyte element1, 00638 // const ubyte element2) const { 00639 // return abs(static_cast<distance_type>(element2) - 00640 // static_cast<distance_type>(element1)); 00641 // } 00642 00643 // /** 00644 // * Return true if the given partial computed from accumulator is less than 00645 // * the given distance. 00646 // * 00647 // * Assume you have accumulated \a acc until now, and you want to check if 00648 // * the partial distance derived from this accumulator is less than 00649 // * the given distance. So you check accLessThan(accumulator,distance) 00650 // * 00651 // * For this norm it computes acc < (dist*dist) 00652 // */ 00653 // inline bool accLessThan(const distance_type acc, 00654 // const distance_type dist) const { 00655 // return (acc < (dist*dist)); 00656 // } 00657 00658 // /** 00659 // * Return true if the given partial computed from accumulator is greater 00660 // * than the given distance. 00661 // * 00662 // * Assume you have accumulated \a acc until now, and you want to check if 00663 // * the partial distance derived from this accumulator is less than 00664 // * the given distance. So you check accLessThan(accumulator,distance) 00665 // * 00666 // * For this norm it computes acc > (dist*dist) 00667 // */ 00668 // inline bool accGreaterThan(const distance_type acc, 00669 // const distance_type dist) const { 00670 // return (acc > (dist*dist)); 00671 // } 00672 00673 // //@} 00674 // }; 00675 00676 /** 00677 * This class computes the L2 distance between two vectors or matrices 00678 * or the L2 norm of a vector. 00679 * 00680 * For other aggregate classes like points and rgbPixels, you can use the 00681 * global functions lti::distanceSqr(), which return the square of the 00682 * euclidian distance (L2 distance) between the two n-dimensional point 00683 * representations. That function exists also for vectors to provide a 00684 * unified interface. 00685 * 00686 * @ingroup gLinearAlgebra 00687 */ 00688 template<class T> 00689 class l2Distance : public distanceFunctor<T> { 00690 public: 00691 /** 00692 * default constructor 00693 */ 00694 l2Distance(); 00695 00696 /** 00697 * copy constructor 00698 * @param other the object to be copied 00699 */ 00700 l2Distance(const l2Distance& other); 00701 00702 /** 00703 * destructor 00704 */ 00705 virtual ~l2Distance(); 00706 00707 /** 00708 * returns the name of this type ("l2Distance") 00709 */ 00710 virtual const char* getTypeName() const; 00711 00712 /** 00713 * calculate the norm of vector v 00714 * @param v the vector<T> 00715 * @param norm the norm of the vectors 00716 * @return false on error 00717 */ 00718 virtual bool apply(const vector<T>& v, T& norm) const; 00719 00720 /** 00721 * calculate the norm of vector v 00722 * @param v the vector<T> 00723 * @return the norm of the vector 00724 */ 00725 virtual T apply(const vector<T>& v) const; 00726 00727 /** 00728 * calculate the norms of rows or columns of the matrix 00729 * @param m the matrix<T> 00730 * @param norms the norms of the rows/columns 00731 * @return false on error 00732 */ 00733 virtual bool apply(const matrix<T>& m, vector<T>& norms) const; 00734 00735 /** 00736 * calculate something like the norm of the matrix: the matrix 00737 * is seen as a vector. 00738 * @param m the matrix<T> 00739 * @param norm the 'norm' of the matrix 00740 * @return false on error 00741 */ 00742 virtual bool apply(const matrix<T>& m, T& norm) const; 00743 00744 /** 00745 * calculate something like the norm of the matrix: the matrix 00746 * is seen as a vector. 00747 * @param m the matrix<T> 00748 * @return the 'norm' of the matrix 00749 */ 00750 virtual T apply(const matrix<T>& m) const; 00751 00752 /** 00753 * calculate the distance between the vectors a and b 00754 * @param a the first vector<T> 00755 * @param b the second vector<T> 00756 * @param dist the distance between the vectors 00757 * @return false on error -> see status string 00758 */ 00759 virtual bool apply(const vector<T>& a, const vector<T>& b, 00760 T& dist) const; 00761 00762 /** 00763 * calculates the L2 distance between the vectors a and b 00764 * If both vectors have different sizes, the returned value will be 00765 * negative! 00766 * @param a the first vector<T> 00767 * @param b the second vector<T> 00768 * @return the L2 distance between a and b 00769 */ 00770 virtual T apply(const vector<T>& a, const vector<T>& b) const; 00771 00772 /** 00773 * calculate the distances between the rows or columns of the 00774 * matrices a and b, determined by the parameters rowWise. 00775 * @param a the first vector<T> 00776 * @param b the second vector<T> 00777 * @param dists the distances between the matrices 00778 * @return false on error -> see status string 00779 */ 00780 virtual bool apply(const matrix<T>& a, const matrix<T>& b, 00781 vector<T>& dists) const; 00782 00783 /** 00784 * calculate the L2 distance between the matrices a and b 00785 * If both matrices have different sizes, the returned value will be 00786 * negative! 00787 * @param a the first matrix<T> 00788 * @param b the second matrix<T> 00789 * @return the L2 distance between a and b 00790 */ 00791 virtual T apply(const matrix<T>& a, const matrix<T>& b) const; 00792 00793 /** 00794 * calculate the L2 distance between the matrices a and b 00795 * If both matrices have different sizes, the returned value will be 00796 * negative! 00797 * @param a the first matrix<T> 00798 * @param b the second matrix<T> 00799 * @param dist the L2 distance between a and b 00800 * @return false on error 00801 */ 00802 virtual bool apply(const matrix<T>& a, const matrix<T>& b, 00803 T& dist) const; 00804 00805 /** 00806 * Calculate the distance between each row or column of m 00807 * depending on the value of rowWise and the vector v. 00808 * @param m the matrix<T> 00809 * @param v the vector to be compared with 00810 * @param dest the vector with the distances to the vector v 00811 * @return false on error 00812 */ 00813 virtual bool apply(const matrix<T>& m, const vector<T>& v, 00814 vector<T>& dest) const; 00815 00816 /** 00817 * copy data of "other" functor. 00818 * @param other the functor to be copied 00819 * @return a reference to this functor object 00820 */ 00821 l2Distance& copy(const l2Distance& other); 00822 00823 /** 00824 * returns a pointer to a clone of this functor. 00825 */ 00826 virtual functor* clone() const; 00827 00828 typedef typename distanceFunctor<T>::parameters parameters; 00829 00830 }; 00831 00832 } 00833 00834 #endif