def get_max(av_scores, pos, constr=(), neg_pos=(), min_seeds=2):
    """
    Get maximum score from all hyperparameter settings
    :param scores: dict mapping settings tuples to score tuples
    :param pos: position(s) out of tuple of scores to maximise (int or list/tuple of ints)
    :param constr: iterable of (index, value) pairs to constrain hyperparameters
    :param neg_pos: positions to minimise (list/tuple of ints)
    :return: best set of hyperparameters, and its scores
    """
    def key(s):
        "Give average score of considered positions, and only if constraints are satisfied"
        if any(s[i] != v for i,v in constr):
            return 0
        elif av_scores[s][0] < min_seeds:
            return 0
        elif pos is None:
            return av_scores[s][1]
        elif isinstance(pos, (list, tuple)):
            return sum(av_scores[s][1][p] for p in pos) - sum(av_scores[s][1][p] for p in neg_pos)
        else:
            return av_scores[s][1][pos]
    # Get the best hyperparameters
    best = max(av_scores, key=key)
    if pos is None:
        return best, av_scores[best]
    else:
        b = av_scores[best]
        return best, (b[0], b[1][pos])