ChiSqDistance.cpp 782 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * @file ChiSqDistance.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/ChiSqDistance.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. ChiSqDistance::ChiSqDistance()
  15. {
  16. }
  17. ChiSqDistance::~ChiSqDistance()
  18. {
  19. }
  20. double ChiSqDistance::doCalculate (const NICE::Vector & x, const NICE::Vector & y) const
  21. {
  22. double dist = 0.0;
  23. for ( int i = 0 ; i < (int)x.size() ; i++ )
  24. {
  25. double u = x[i];
  26. double v = y[i];
  27. double s = u+v;
  28. // lim_{(p,q) \rightarrow \infty} ( (p-q)^2 / (p+q) = 0
  29. if ( fabs(s) < 10e-6 ) continue;
  30. double d = u-v;
  31. dist += d*d / s;
  32. }
  33. return 0.5*dist;
  34. }