fix Chi Square histogram comparison

The existing formula is the pure stochastic Chi square test. However, for histogram comparison it needs to be adjusted like in the given patch. This normalizes the output, resulting in much smoother gradients. It also makes the comparison symmetric, which makes the comparison closer to a semi-metric.