def METHOD_NAME(
    trial: "optuna.trial.FrozenTrial", direction: StudyDirection
) -> float:
    values = np.asarray(list(trial.intermediate_values.values()), dtype=float)
    if direction == StudyDirection.MAXIMIZE:
        return np.nanmax(values)
    return np.nanmin(values)