Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

MatFeatureNormalization.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Matrix_MatFeatureNormalization_h
00002 #define Impala_Core_Matrix_MatFeatureNormalization_h
00003 
00004 #include "Core/Matrix/MatSet.h"
00005 
00006 namespace Impala
00007 {
00008 namespace Core
00009 {
00010 namespace Matrix
00011 {
00012 
00013 
00014 template<class ArrayT>
00015 inline void
00016 MatFeatureNormalization(ArrayT* m)
00017 {
00018     typedef typename ArrayT::ArithType ArithT;
00019     typedef typename ArrayT::StorType StorT;
00020 
00021     int nRow = MatNrRow(m);
00022     int nCol = MatNrCol(m);
00023     ArrayT* M = VecCreate<ArrayT>(nCol); //means
00024     ArrayT* S = VecCreate<ArrayT>(nCol); //variances 
00025 
00026     MatSet(M, 0);
00027     MatSet(S, 0);
00028 
00029     StorT* MPtr = VecE(M, 0);
00030     StorT* SPtr = VecE(S, 0);
00031     for (int i=0 ; i<nRow ; i++)
00032     {
00033         StorT* miPtr = MatE(m, i, 0);
00034         for (int j=0 ; j<nCol ; j++)
00035         {
00036             ArithT x = miPtr[j];
00037             MPtr[j] += x;
00038             SPtr[j] += x*x;
00039         }
00040     }
00041 
00042     for (int j=0 ; j<nCol ; j++)
00043     {
00044         ArithT mj = MPtr[j]/nRow;
00045         SPtr[j] = sqrt( SPtr[j]/nRow - mj * mj );
00046     }
00047 
00048     //normalize
00049     for (int k=0 ; k<nRow; k++)
00050     {
00051         StorT* mkPtr = MatE(m, k, 0);
00052         for (int j=0 ; j<nCol ; j++)
00053             mkPtr[j] = mkPtr[j] / SPtr[j];
00054     }
00055 
00056     delete M;
00057     delete S;
00058 }
00059 
00060 } // namespace Matrix
00061 } // namespace Core
00062 } // namespace Impala
00063 
00064 #endif

Generated on Fri Mar 19 09:31:15 2010 for ImpalaSrc by  doxygen 1.5.1