KLDistance.cpp 695 B

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * @file KLDistance.cpp
  3. * @brief $\chi^2$ distance measure
  4. * @author Erik Rodner
  5. * @date 02/19/2008
  6. */
  7. #include <iostream>
  8. #include "vislearning/math/distances/KLDistance.h"
  9. using namespace OBJREC;
  10. using namespace std;
  11. // refactor-nice.pl: check this substitution
  12. // old: using namespace ice;
  13. using namespace NICE;
  14. double DeprecatedKLDistance::doCalculate (const NICE::Vector & x, const NICE::Vector & y) const
  15. {
  16. double dist = 0.0;
  17. for ( int i = 0 ; i < (int)x.size() ; i++ )
  18. {
  19. double u = x[i];
  20. double v = y[i];
  21. if ( fabs(u) < 10e-6 ) continue;
  22. if ( fabs(v) < 10e-6 ) v = 10e-6;
  23. dist += u * log ( u / v );
  24. }
  25. if ( dist < 0.0 ) dist = 0.0;
  26. return dist;
  27. }