def kl_divergence(V_a, V_b):
    """
    Calculate Kullback-Leibler distance.

    Uses the smoothing method described in `Bigi 2003
    <http://lvk.cs.msu.su/~bruzz/articles/classification/Using%20Kullback-Leibler%20Distance%20for%20Text%20Categorization.pdf>`_
    to facilitate better comparisons between vectors describing wordcounts.

    Parameters
    ----------
    V_a : list
    V_b : list

    Returns
    -------
    divergence : float
        KL divergence.
    """

    # Find shared features.
    Ndiff = _shared_features(V_a, V_b)

    # aprob and bprob should each sum to 1.0
    aprob = map(lambda v: float(v)/sum(V_a), V_a)
    bprob = map(lambda v: float(v)/sum(V_b), V_b)

    # Smooth according to Bigi 2003.
    aprob, bprob = _smooth(aprob, bprob, Ndiff)

    return sum(map(lambda a, b: (a-b)*log(a/b), aprob, bprob))
Calculate Kullback-Leibler distance.

    Uses the smoothing method described in `Bigi 2003
    <http://lvk.cs.msu.su/~bruzz/articles/classification/Using%20Kullback-Leibler%20Distance%20for%20Text%20Categorization.pdf>`_
    to facilitate better comparisons between vectors describing wordcounts.

    Parameters
    ----------
    V_a : list
    V_b : list

    Returns
    -------
    divergence : float
        KL divergence.