1234567891011121314151617181920212223242526272829303132333435 |
- /**
- * @file KLDistance.cpp
- * @brief $\chi^2$ distance measure
- * @author Erik Rodner
- * @date 02/19/2008
- */
- #include <iostream>
- #include "vislearning/math/distances/KLDistance.h"
- using namespace OBJREC;
- using namespace std;
- // refactor-nice.pl: check this substitution
- // old: using namespace ice;
- using namespace NICE;
- double DeprecatedKLDistance::doCalculate (const NICE::Vector & x, const NICE::Vector & y) const
- {
- double dist = 0.0;
- for ( int i = 0 ; i < (int)x.size() ; i++ )
- {
- double u = x[i];
- double v = y[i];
- if ( fabs(u) < 10e-6 ) continue;
- if ( fabs(v) < 10e-6 ) v = 10e-6;
-
- dist += u * log ( u / v );
- }
- if ( dist < 0.0 ) dist = 0.0;
- return dist;
- }
|