HistIntersectDistance.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * @file HistIntersectDistance.cpp
  3. * @brief $\chi^2$ distance measure
  4. * @author Erik Rodner
  5. * @date 02/19/2008
  6. */
  7. #ifdef NOVISUAL
  8. #include <vislearning/nice_nonvis.h>
  9. #else
  10. #include <vislearning/nice.h>
  11. #endif
  12. #include <iostream>
  13. #include <assert.h>
  14. #include "vislearning/math/distances/HistIntersectDistance.h"
  15. using namespace OBJREC;
  16. using namespace std;
  17. // refactor-nice.pl: check this substitution
  18. // old: using namespace ice;
  19. using namespace NICE;
  20. HistIntersectDistance::HistIntersectDistance()
  21. {
  22. }
  23. HistIntersectDistance::~HistIntersectDistance()
  24. {
  25. }
  26. double HistIntersectDistance::doCalculate (const NICE::Vector & x, const NICE::Vector & y) const
  27. {
  28. /*************************************************
  29. calculate (x,x) is only in seldom cases
  30. zero. A idea for normalization would be
  31. \sum_i \max{x_i,y_i} - \min{x_i,y_i}
  32. which is exactly the L_1 distance
  33. **************************************************/
  34. double dist = 0.0;
  35. for ( int i = 0 ; i < (int)x.size() ; i++ )
  36. {
  37. double u = x[i];
  38. double v = y[i];
  39. assert ( u >= 0 );
  40. assert ( v >= 0 );
  41. if ( u < v ) dist += u;
  42. else dist += v;
  43. }
  44. return - dist;
  45. }