Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Question ELO calculation in ML-Agents

Discussion in 'ML-Agents' started by swagzinna, Dec 13, 2021.

  1. swagzinna

    swagzinna

    Joined:
    Apr 20, 2021
    Posts:
    9
    Hi,
    I'm currently working on my bachelors thesis regarding the MA-POCA algorithm. For that, i would be eager to know how exactly the ELO score is calculated?
    Can anybody tell me how, or can show where to find the calculation in code?

    Thanks a lot,
    Leon
     
  2. jrupert-unity

    jrupert-unity

    Unity Technologies

    Joined:
    Oct 20, 2021
    Posts:
    12
    from ml-agents/mlagents/trainers/ghost/controller.py:

    Code (CSharp):
    1.    # Adapted from https://github.com/Unity-Technologies/ml-agents/pull/1975 and
    2.     # https://metinmediamath.wordpress.com/2013/11/27/how-to-calculate-the-elo-rating-including-example/
    3.     # ELO calculation
    4.     # TODO : Generalize this to more than two teams
    5.     def compute_elo_rating_changes(self, rating: float, result: float) -> float:
    6.         """
    7.        Calculates ELO. Given the rating of the learning team and result.  The GhostController
    8.        queries the other GhostTrainers for the ELO of their agent that is currently being deployed.
    9.        Note, this could be the current agent or a past snapshot.
    10.        :param rating: Rating of the learning team.
    11.        :param result: Win, loss, or draw from the perspective of the learning team.
    12.        :return: The change in ELO.
    13.        """
    14.         opponent_rating: float = 0.0
    15.         for team_id, trainer in self._ghost_trainers.items():
    16.             if team_id != self._learning_team:
    17.                 opponent_rating = trainer.get_opponent_elo()
    18.         r1 = pow(10, rating / 400)
    19.         r2 = pow(10, opponent_rating / 400)
    20.  
    21.         summed = r1 + r2
    22.         e1 = r1 / summed
    23.  
    24.         change = result - e1
    25.         for team_id, trainer in self._ghost_trainers.items():
    26.             if team_id != self._learning_team:
    27.                 trainer.change_opponent_elo(change)
    28.  
    29.         return change
     
  3. swagzinna

    swagzinna

    Joined:
    Apr 20, 2021
    Posts:
    9
    Hi, thanks a lot, this has been a huge help! Can you also tell me where the variable "result" is beeing calculated?
    Leon
     
  4. WaxyMcRivers

    WaxyMcRivers

    Joined:
    May 9, 2016
    Posts:
    59
    You can go to the github ML-Agents repository and search for the function "compute_elo_rating_changes" and sort through the resulting scripts to see where/how it's used.
     
    jrupert-unity likes this.