mdr/utils/utils.py
def mutual_information(X, Y, base=2):
    """Calculates the mutual information between two variables, I(X;Y), in the given base

    Parameters
    ----------
    X: array-like (# samples)
        An array of values for which to compute the mutual information
    Y: array-like (# samples)
        An array of values for which to compute the mutual information
    base: integer (default: 2)
        The base in which to calculate mutual information

    Returns
    ----------
    mutual_information: float
        The mutual information calculated according to the equation I(X;Y) = H(Y) - H(Y|X)

    """
    return entropy(Y, base=base) - conditional_entropy(Y, X, base=base)
def mutual_information(X, Y, base=2):
    """Calculates the mutual information between two variables, I(X;Y), in the given base

    Parameters
    ----------
    X: array-like (# samples)
        An array of values for which to compute the mutual information
    Y: array-like (# samples)
        An array of values for which to compute the mutual information
    base: integer (default: 2)
        The base in which to calculate mutual information

    Returns
    ----------
    mutual_information: float
        The mutual information calculated according to the equation I(X;Y) = H(Y) - H(Y|X)

    """
    return entropy(Y, base=base) - conditional_entropy(Y, X, base=base)
Calculates the mutual information between two variables, I(X;Y), in the given base

    Parameters
    ----------
    X: array-like (# samples)
        An array of values for which to compute the mutual information
    Y: array-like (# samples)
        An array of values for which to compute the mutual information
    base: integer (default: 2)
        The base in which to calculate mutual information

    Returns
    ----------
    mutual_information: float
        The mutual information calculated according to the equation I(X;Y) = H(Y) - H(Y|X)