norms.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008 Radu Bogdan Rusu <rusu -=- cs.tum.edu>
00003  *
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *
00009  *     * Redistributions of source code must retain the above copyright
00010  *       notice, this list of conditions and the following disclaimer.
00011  *     * Redistributions in binary form must reproduce the above copyright
00012  *       notice, this list of conditions and the following disclaimer in the
00013  *       documentation and/or other materials provided with the distribution.
00014  *
00015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00025  * POSSIBILITY OF SUCH DAMAGE.
00026  *
00027  * $Id$
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


door_handle_detector
Author(s): Radu Bogdan Rusu, Marius
autogenerated on Wed Dec 11 2013 14:17:01