import math


def has_gotten_higher(values: list, allow_same: bool = True, EPS: float = 1e-6) -> bool:
    """
    Check if any of the elements is higher than the first element.
    Used for early stopping.
    If the list contains None, ignore them.

    ```
    if not has_gotten_higher(val_acc[-20:]):
        logger.info("Validation accuracy hasn't increased for 20 epochs. Stopping training..")
        raise Exception("Early stopping triggered.")
    ```
    """

    values = [value for value in values if value is not None and not math.isnan(value)]

    if len(values) <= 1:
        raise ValueError("Can't determine if values got higher with 0 or 1 value.")

    if allow_same:
        for value in values[1:]:
            if values[0] < value + EPS:
                return True
    else:
        for value in values[1:]:
            if values[0] < value - EPS:
                return True

    return False