def f1_from_roc(fpr, tpr, pos, neg):
    """Calculate f1 score from roc values.

    Parameters
    ----------
        fpr : float
            The false positive rate.
        tpr : float
            The true positive rate.
        pos : int
            The number of positive labels.
        neg : int
            The number of negative labels.

    Returns
    -------
    float
        The f1 score.
    """
    fp = fpr * neg
    fn = (1 - tpr) * pos
    tp = pos - fn
    f1 = tp / (tp + ((fn + fp) / 2))
    return f1