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
00033 #ifndef _CLOUD_GEOMETRY_NORMS_H_
00034 #define _CLOUD_GEOMETRY_NORMS_H_
00035
00036 namespace cloud_geometry
00037 {
00038
00039 namespace norms
00040 {
00042
00050 inline double
00051 L1_Norm (float *A, float *B, int dim)
00052 {
00053 double norm = 0.0;
00054
00055 for (int i = 0; i < dim; i++)
00056 norm += fabs (A[i] - B[i]);
00057
00058 return norm;
00059 }
00060
00062
00068 inline double
00069 L2_Norm_SQR (float *A, float *B, int dim)
00070 {
00071 double norm = 0.0;
00072
00073 for (int i = 0; i < dim; i++)
00074 norm += (A[i] - B[i]) * (A[i] - B[i]);
00075
00076 return norm;
00077 }
00078
00080
00086 inline double
00087 L2_Norm (float *A, float *B, int dim)
00088 {
00089 double norm = 0.0;
00090
00091 for (int i = 0; i < dim; i++)
00092 norm += (A[i] - B[i]) * (A[i] - B[i]);
00093
00094 return sqrt (norm);
00095 }
00096
00098
00105 inline double
00106 Linf_Norm (float *A, float *B, int dim)
00107 {
00108 double norm = 0.0;
00109
00110 for (int i = 0; i < dim; i++)
00111 norm = (fabs (A[i] - B[i]) > norm) ? fabs (A[i] - B[i]) : norm;
00112
00113 return norm;
00114 }
00115
00117
00123 inline double
00124 JM_Norm (float *A, float *B, int dim)
00125 {
00126 double norm = 0.0;
00127
00128 for (int i = 0; i < dim; i++)
00129 norm += (sqrt (A[i]) - sqrt (B[i])) * (sqrt (A[i]) - sqrt (B[i]));
00130
00131 return sqrt (norm);
00132 }
00133
00135
00140 inline double
00141 B_Norm (float *A, float *B, int dim)
00142 {
00143 double norm = 0.0, result;
00144
00145 for (int i = 0; i < dim; i++)
00146 norm += sqrt (A[i] * B[i]);
00147
00148 if (norm > 0)
00149 result = -log (norm);
00150 else
00151 result = 0;
00152
00153 return result;
00154 }
00155
00157
00162 inline double
00163 Sublinear_Norm (float *A, float *B, int dim)
00164 {
00165 double norm = 0.0;
00166
00167 for (int i = 0; i < dim; i++)
00168 norm += sqrt (fabs (A[i] - B[i]));
00169
00170 return norm;
00171 }
00172
00174
00179 inline double
00180 CS_Norm (float *A, float *B, int dim)
00181 {
00182 double norm = 0.0;
00183
00184 for (int i = 0; i < dim; i++)
00185 if ((A[i] + B[i]) != 0)
00186 norm += (A[i] - B[i]) * (A[i] - B[i]) / (A[i] + B[i]);
00187 else
00188 norm += 0;
00189 return norm;
00190 }
00191
00193
00198 inline double
00199 Div_Norm (float *A, float *B, int dim)
00200 {
00201 double norm = 0.0;
00202
00203 for (int i = 0; i < dim; i++)
00204 if ((A[i] / B[i]) > 0)
00205 norm += (A[i] - B[i]) * log (A[i] / B[i]);
00206 else
00207 norm += 0;
00208 return norm;
00209 }
00210
00212
00219 inline double
00220 PF_Norm (float *A, float *B, int dim, double P1, double P2)
00221 {
00222 double norm = 0.0;
00223
00224 for (int i = 0; i < dim; i++)
00225 norm += (P1 * A[i] - P2 * B[i]) * (P1 * A[i] - P2 * B[i]);
00226 return sqrt (norm);
00227 }
00228
00230
00237 inline double
00238 K_Norm (float *A, float *B, int dim, double P1, double P2)
00239 {
00240 double norm = 0.0;
00241
00242 for (int i = 0; i < dim; i++)
00243 norm += fabs (P1 * A[i] - P2 * B[i]);
00244 return norm;
00245 }
00246
00248
00253 inline double
00254 KL_Norm (float *A, float *B, int dim)
00255 {
00256 double norm = 0.0;
00257
00258 for (int i = 0; i < dim; i++)
00259 if ( (B[i] != 0) && ((A[i] / B[i]) > 0) )
00260 norm += A[i] * log (A[i] / B[i]);
00261 else
00262 norm += 0;
00263 return norm;
00264 }
00265 }
00266 }
00267
00268 #endif