def normalize()

in jat/utils.py [0:0]


def normalize(values: List[float], env_id: str, strategy: str) -> List[float]:
    """
    Normalize the scores.

    Args:
        values (List[float]): Scores to normalize.
        env_id (str): Environment name.
        strategy (str): Normalization strategy. Can be either "max" or "expert" or "human".

    Returns:
        List[float]: Normalized scores.
    """
    scores_dict = get_scores_dict()

    # Check if the environment is available
    if env_id not in scores_dict:
        raise KeyError(f"Environment {env_id} not found in scores_dict.json")
    if "random" not in scores_dict[env_id]:
        raise KeyError(f"Random scores not found for environment {env_id}")
    random_score = scores_dict[env_id]["random"]["mean"]

    # Get the max score depending on the strategy
    if strategy == "max":
        max_score = np.max(values)
    elif strategy == "expert":
        if "expert" not in scores_dict[env_id]:
            raise KeyError(f"Expert scores not found for environment {env_id}")
        max_score = scores_dict[env_id]["expert"]["mean"]
    elif strategy == "human":
        if "human" not in scores_dict[env_id]:
            raise KeyError(f"Human scores not found for environment {env_id}")
        max_score = scores_dict[env_id]["human"]["mean"]

    if max_score <= random_score:
        print(f"Upper score is under random score for {env_id}")
        return [1.0 for _ in values]

    return [(v - random_score) / abs(max_score - random_score) for v in values]