示例#1
0
double Distance(FV &distr_1, FV &distr_2) { 
  FV m(distr_1.size());
  for (int i = 0; i < distr_1.size(); ++i) {
    m[i] = (distr_1[i] + distr_2[i]) / 2.0;
  }
  return (KL(distr_1, m) + KL(distr_2, m)) / 2;
}
示例#2
0
double KL(FV &p, FV &q) {
  double kl = 0.0;
  double denom1 = 0.0;
  double denom2 = 0.0;
  for (int i = 0; i < p.size(); ++i) {
//    kl += p[i] * log(p[i] / q[i]);
    kl += abs(p[i] - q[i]);
    denom1 = p[i] * p[i];
    denom2 = q[i] * q[i];
  }
  return kl;
}