iqm.error_reduction_tools.utils.general_utils.total_variational_distance#
- iqm.error_reduction_tools.utils.general_utils.total_variational_distance(dist_a, dist_b)#
Total Variation Distance between two probability distributions.
The Total Variation Distance between the probability distributions P and Q is defined as
\[\text{TVD}(P, Q) = \frac{1}{2} \sum_x |P(x) - Q(x)|.\]TVD is always in \([0, 1]\).
This function accepts both:
Proper probability distributions (
dict[str, float]with values summing to 1)Samplings of distributions (
dict[str, int]with arbitrary sums)
The distributions are automatically normalized before computing the distance, so the input values do not actually need to sum to 1.