code: public static double TopsoeDivergence(double[] p, double[] q) {
          double r = 0;
          for (int i = 0; i < p.length; i++) {
              if (p[i] != 0 && q[i] != 0) {
                  double den = p[i] + q[i];
                  r += p[i] * Math.log(2 * p[i] / den) + q[i] * Math.log(2 * q[i] / den);
              }
          }
          return r;
      }
docs: Gets the Topsoe divergence.
  
  @param p P vector.
  @param q Q vector.
  @return The Topsoe divergence between p and q.