A.I.M.S algorithms


distance_d.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 
35 #ifndef DISTANCE_D_H
36 #define DISTANCE_D_H
37 
38 #include <cstdlib>
40 #include <math.h>
41 
42 
43 template <class T>
45 {
46 }
47 
48 template <class T>
50 {
51 }
52 
53 template <class T>
54 float aims::Distance<T>::norm1( const std::vector<T>& ind1, const std::vector<T>& ind2,
55  unsigned int beginIndex, unsigned int endIndex )
56 {
57  unsigned int size1, size2 ;
58  size1 = ind1.size() ;
59  size2 = ind2.size() ;
60  ASSERT( size1 == size2 ) ;
61 
62  float dist = 0. ;
63  for( unsigned int i = beginIndex ; i <= endIndex ; ++i )
64  dist += fabs( double( ind1[i] - ind2[i] ) ) ;
65  return dist ;
66 }
67 
68 
69 template <class T>
70 float aims::Distance<T>::norm2( const std::vector<T>& ind1, const std::vector<T>& ind2,
71  unsigned int beginIndex, unsigned int endIndex )
72 {
73  unsigned int size1, size2 ;
74  size1 = ind1.size() ;
75  size2 = ind2.size() ;
76  ASSERT( size1 == size2 ) ;
77 
78  float dist = 0. ;
79  for( unsigned int i = beginIndex ; i <= endIndex ; ++i )
80  dist += ( ind1[i] - ind2[i] ) * ( ind1[i] - ind2[i] ) ;
81  return sqrt( dist ) ;
82 }
83 
84 
85 template <class T>
86 float aims::Distance<T>::norm2sqr( const std::vector<T>& ind1, const std::vector<T>& ind2,
87  unsigned int beginIndex, unsigned int endIndex )
88 {
89  unsigned int size1, size2 ;
90  size1 = ind1.size() ;
91  size2 = ind2.size() ;
92  ASSERT( size1 == size2 ) ;
93 
94  float dist = 0. ;
95  for( unsigned int i = beginIndex ; i <= endIndex ; ++i )
96  dist += ( ind1[i] - ind2[i] ) * ( ind1[i] - ind2[i] ) ;
97  return dist ;
98 }
99 
100 
101 template <class T>
102 float aims::Distance<T>::infiniteNorm( const std::vector<T>& ind1, const std::vector<T>& ind2,
103  unsigned int beginIndex, unsigned int endIndex )
104 {
105  unsigned int size1, size2 ;
106  size1 = ind1.size() ;
107  size2 = ind2.size() ;
108  ASSERT( size1 == size2 ) ;
109 
110  float dist = 0., distmax = 0. ;
111  for( unsigned int i = beginIndex ; i <= endIndex ; ++i ){
112  dist = fabs( double( ind1[i] - ind2[i] ) ) ;
113  if( dist > distmax ) distmax = dist ;
114  }
115  return distmax ;
116 }
117 
118 #endif
static float norm2sqr(const std::vector< T > &ind1, const std::vector< T > &ind2, unsigned int beginIndex, unsigned int endIndex)
Definition: distance_d.h:86
static float infiniteNorm(const std::vector< T > &ind1, const std::vector< T > &ind2, unsigned int beginIndex, unsigned int endIndex)
Definition: distance_d.h:102
static float norm2(const std::vector< T > &ind1, const std::vector< T > &ind2, unsigned int beginIndex, unsigned int endIndex)
Definition: distance_d.h:70
static float norm1(const std::vector< T > &ind1, const std::vector< T > &ind2, unsigned int beginIndex, unsigned int endIndex)
Definition: distance_d.h:54
#define ASSERT(EX)