COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libcoopy_core/FloatSheet.cpp
Go to the documentation of this file.
00001 #include <coopy/FloatSheet.h>
00002 
00003 #include <math.h>
00004 
00005 using namespace coopy::store;
00006 
00007 Stat FloatSheet::normalize(int first, int last, float sc, bool modify) {
00008   Stat s;
00009   int hh = height();
00010   int ww = width();
00011   if (first==-1) first = 0;
00012   if (last==-1) last = ww-1;
00013   float tot = 0;
00014   float tot2 = 0;
00015   int ct = 0;
00016   for (int i=0; i<hh; i++) {
00017     for (int j=first; j<=last; j++) {
00018       float r = cell(j,i);
00019       tot += r;
00020       tot2 += r*r;
00021       ct++;
00022     }
00023   }
00024   if (ct==0) return s;
00025   float mean = tot;
00026   float dev = 1;
00027   mean /= ct;
00028   dev = tot2 / ct - mean*mean;
00029   if (dev<0) { 
00030     dev = 0; 
00031   } else {
00032     dev = sqrt(dev);
00033   }
00034   //printf("mean %g, dev %g\n", mean, dev);
00035   if (dev<sc) dev = sc;
00036   if (modify) {
00037     for (int i=0; i<hh; i++) {
00038       for (int j=first; j<=last; j++) {
00039         float r = cell(j,i);
00040         r = (r-mean)/dev;
00041         cell(j,i) = r;
00042       }
00043     }
00044   }
00045   s.mean = mean;
00046   s.stddev = dev;
00047   s.valid = true;
00048   return s;
00049 }
00050 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines