00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <cmath>
00037 #include "pcl/win32_macros.h"
00038
00039 namespace pcl
00040 {
00041
00042 inline float L1_Norm (float *a, float *b, int dim)
00043 {
00044 float norm = 0.0f;
00045 for (int i = 0; i < dim; ++i)
00046 norm += fabsf(*(a++) - *(b++));
00047 return norm;
00048 }
00049
00050
00051 inline float L2_Norm_SQR (float *a, float *b, int dim)
00052 {
00053 float norm = 0.0;
00054 for (int i = 0; i < dim; ++i)
00055 {
00056 float diff = *(a++) - *(b++);
00057 norm += diff*diff;
00058 }
00059 return norm;
00060 }
00061
00062
00063 inline float L2_Norm (float *a, float *b, int dim)
00064 {
00065 return sqrtf(L2_Norm_SQR(a, b, dim));
00066 }
00067
00068
00069 inline float Linf_Norm (float *a, float *b, int dim)
00070 {
00071 float norm = 0.0;
00072 for (int i = 0; i < dim; ++i)
00073 norm = (std::max)(fabsf(*(a++) - *(b++)), norm);
00074 return norm;
00075 }
00076
00077
00078 inline float JM_Norm (float *a, float *b, int dim)
00079 {
00080 float norm = 0.0;
00081
00082 for (int i = 0; i < dim; ++i)
00083 norm += (sqrtf (a[i]) - sqrtf (b[i])) * (sqrtf (a[i]) - sqrtf (b[i]));
00084
00085 return sqrtf (norm);
00086 }
00087
00088
00089 inline float B_Norm (float *a, float *b, int dim)
00090 {
00091 float norm = 0.0, result;
00092
00093 for (int i = 0; i < dim; ++i)
00094 norm += sqrtf (a[i] * b[i]);
00095
00096 if (norm > 0)
00097 result = -log (norm);
00098 else
00099 result = 0;
00100
00101 return result;
00102 }
00103
00104
00105 inline float Sublinear_Norm (float *a, float *b, int dim)
00106 {
00107 float norm = 0.0;
00108
00109 for (int i = 0; i < dim; ++i)
00110 norm += sqrtf (fabsf (a[i] - b[i]));
00111
00112 return norm;
00113 }
00114
00115
00116 inline float CS_Norm (float *a, float *b, int dim)
00117 {
00118 float norm = 0.0;
00119
00120 for (int i = 0; i < dim; ++i)
00121 if ((a[i] + b[i]) != 0)
00122 norm += (a[i] - b[i]) * (a[i] - b[i]) / (a[i] + b[i]);
00123 else
00124 norm += 0;
00125 return norm;
00126 }
00127
00128
00129 inline float Div_Norm (float *a, float *b, int dim)
00130 {
00131 float norm = 0.0;
00132
00133 for (int i = 0; i < dim; ++i)
00134 if ((a[i] / b[i]) > 0)
00135 norm += (a[i] - b[i]) * log (a[i] / b[i]);
00136 else
00137 norm += 0;
00138 return norm;
00139 }
00140
00141
00142 inline float PF_Norm (float *a, float *b, int dim, float P1, float P2)
00143 {
00144 float norm = 0.0;
00145
00146 for (int i = 0; i < dim; ++i)
00147 norm += (P1 * a[i] - P2 * b[i]) * (P1 * a[i] - P2 * b[i]);
00148 return sqrtf (norm);
00149 }
00150
00151
00152 inline float K_Norm (float *a, float *b, int dim, float P1, float P2)
00153 {
00154 float norm = 0.0;
00155
00156 for (int i = 0; i < dim; ++i)
00157 norm += fabsf (P1 * a[i] - P2 * b[i]);
00158 return norm;
00159 }
00160
00161
00162 inline float KL_Norm (float *a, float *b, int dim)
00163 {
00164 float norm = 0.0;
00165
00166 for (int i = 0; i < dim; ++i)
00167 if ( (b[i] != 0) && ((a[i] / b[i]) > 0) )
00168 norm += a[i] * log (a[i] / b[i]);
00169 else
00170 norm += 0;
00171 return norm;
00172 }
00173
00174 inline float HIK_Norm(float *a, float *b, int dim)
00175 {
00176 float norm = 0.0f;
00177 for (int i = 0; i < dim; ++i)
00178 norm += (std::min)(*(a++), *(b++));
00179 return norm;
00180 }
00181
00182 }