From: Diemo S. <di...@us...> - 2007-04-11 10:08:41
|
Update of /cvsroot/jmax/jmax/packages/data/c/src In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv11039 Modified Files: fvec.c Log Message: return 0 variance for empty vectors instead of NaN Index: fvec.c =================================================================== RCS file: /cvsroot/jmax/jmax/packages/data/c/src/fvec.c,v retrieving revision 1.165 retrieving revision 1.166 diff -C2 -d -r1.165 -r1.166 *** fvec.c 16 Feb 2007 08:39:42 -0000 1.165 --- fvec.c 11 Apr 2007 10:08:36 -0000 1.166 *************** *** 2012,2016 **** fvec_t *self = (fvec_t *)o; double sum = 0.0, sum2 = 0.0; ! double mean, var; float *p; int size, stride; --- 2012,2016 ---- fvec_t *self = (fvec_t *)o; double sum = 0.0, sum2 = 0.0; ! double mean, var = 0; float *p; int size, stride; *************** *** 2019,2031 **** fvec_get_vector(self, &p, &size, &stride); ! for (i = 0; i < size * stride; i += stride) { ! sum += p[i]; ! sum2 += p[i] * p[i]; ! } ! ! mean = sum / (double) size; ! var = sum2 / (double) size - mean * mean; fts_set_float(ret, var); --- 2019,2034 ---- fvec_get_vector(self, &p, &size, &stride); ! if (size > 0) { ! for (i = 0; i < size * stride; i += stride) ! { ! sum += p[i]; ! sum2 += p[i] * p[i]; ! } + mean = sum / (double) size; + var = sum2 / (double) size - mean * mean; + } + fts_set_float(ret, var); |