HistIntersectDistance.cpp 1.1 KB

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