/** * @file ChiSqDistance.cpp * @brief $\chi^2$ distance measure * @author Erik Rodner * @date 02/19/2008 */ #include #include "vislearning/math/distances/ChiSqDistance.h" using namespace OBJREC; using namespace std; // refactor-nice.pl: check this substitution // old: using namespace ice; using namespace NICE; ChiSqDistance::ChiSqDistance() { } ChiSqDistance::~ChiSqDistance() { } double ChiSqDistance::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]; double s = u+v; // lim_{(p,q) \rightarrow \infty} ( (p-q)^2 / (p+q) = 0 if ( fabs(s) < 10e-6 ) continue; double d = u-v; dist += d*d / s; } return 0.5*dist; }