def information_gain(
    w_samples,
    w_samples_parent,
    w_samples_left,
    w_samples_right,
    impurity_parent,
    impurity_left,
    impurity_right,
):
    """Computes the information gain (improvement in impurity) using the equation

        n_v / n * impurity_v - n_v0 / n_v * impurity_v0 - n_v1 / n_v * impurity_v1)

    where:
        * v, v0, v1 are respectively the parent, left child and right child nodes
        * n is the total weighted number of samples
        * n_w and impurity_w are respectively the weighted number of samples and
          impurity of a node w

    Parameters
    ----------
    w_samples : float
        Total weighted number of samples

    w_samples_parent : float
        Weighted number of samples in parent node

    w_samples_left : float
        Weighted number of samples in left child node

    w_samples_right : float
        Weighted number of samples in right child node

    impurity_parent : float
        Impurity of the parent node

    impurity_left : float
        Impurity of the left child node

    impurity_right : float
        Impurity of the right child node

    Returns
    -------
    output : float
        Information gain obtained after splitting the parent into left and and
        right child nodes
    """
    return (w_samples_parent / w_samples) * (
        impurity_parent
        - (w_samples_right / w_samples_parent * impurity_right)
        - (w_samples_left / w_samples_parent * impurity_left)
    )