logo

Elo vertinimo algoritmas

The Elo vertinimo algoritmas yra plačiai naudojamas reitingavimo algoritmas, naudojamas žaidėjams reitinguoti daugelyje konkurencinių žaidimų. 

  • Žaidėjai, turintys aukštesnį ELO reitingą, turi didesnę tikimybę laimėti žaidimą nei žaidėjai, turintys žemesnius ELO reitingus.
  • Po kiekvieno žaidimo ELO žaidėjų reitingas atnaujinamas.
  • Jei žaidėjas, turintis aukštesnį ELO reitingą, laimi, tik keli taškai perkeliami iš žemesnio reitingo žaidėjo.
  • Tačiau jei laimi žemesnio reitingo žaidėjas, tada aukštesnio reitingo žaidėjo pervesti taškai yra daug didesni.

Prieiga: Norėdami išspręsti problemą, vadovaukitės toliau pateikta idėja:

P1: Tikimybė laimėti žaidėjui su reitingu2 P2: tikimybė laimėti žaidėjui su reitingu1. 
P1 = (1,0 / (1,0 + pow(10 ((vertinimas1 - įvertinimas2) / 400)))); 
P2 = (1,0 / (1,0 + pow(10 ((2 reitingas - 1 įvertinimas)) / 400)))); 



Akivaizdu, kad P1 + P2 = 1. Žaidėjo reitingas atnaujinamas pagal toliau pateiktą formulę:- 
įvertinimas1 = įvertinimas1 + K*(faktinis balas – numatomas balas); 

Daugumoje žaidimų „Faktinis rezultatas“ yra 0 arba 1 reiškia, kad žaidėjas laimi arba pralaimi. K yra konstanta. Jei K yra mažesnės reikšmės, įvertinimas pasikeičia nedidele dalimi, bet jei K yra didesnės reikšmės, reitingo pokyčiai yra reikšmingi. Skirtingos organizacijos nustato skirtingą K vertę.

Pavyzdys:

Tarkime, kad tarp dviejų žaidėjų vyksta tiesioginis chess.com mačas 
reitingas1 = 1200 reitingas2 = 1000; 

P1 = (1,0 / (1,0 + pow(10 ((1000-1200) / 400)))) = 0,76 
P2 = (1,0 / (1,0 + pow(10 ((1200-1000) / 400)))) = 0,24 
Ir Tarkime, kad konstanta K=30; 

1 ATVEJIS: 
Tarkime, laimi 1 žaidėjas: reitingas1 = įvertinimas1 + k*(faktinis – tikimasi) = 1200+30(1 – 0,76) = 1207,2; 
įvertinimas2 = įvertinimas2 + k*(faktinis – numatomas) = ​​1000+30(0 – 0,24) = 992,8; 

2 atvejis:  
Tarkime, laimi 2 žaidėjas: reitingas1 = reitingas1 + k*(faktinis – tikimasi) = 1200+30(0 – 0,76) = 1177,2; 
įvertinimas2 = įvertinimas2 + k*(faktinis – numatomas) = ​​1000+30(1 – 0,24) = 1022,8;

Norėdami išspręsti problemą, atlikite toliau nurodytus veiksmus.

  • Apskaičiuokite žaidėjų A ir B laimėjimo tikimybę pagal aukščiau pateiktą formulę
  • Jei žaidėjas A laimi arba žaidėjas B laimi, reitingai atitinkamai atnaujinami naudojant formules:
    • įvertinimas 1 = įvertinimas 1 + K* (faktinis balas – numatomas balas)
    • 2 įvertinimas = 2 įvertinimas + K* (faktinis balas – numatomas balas)
    • Kai faktinis balas yra 0 arba 1
  • Spausdinkite atnaujintus įvertinimus

Žemiau pateikiamas pirmiau minėto metodo įgyvendinimas:

CPP
#include    using namespace std; // Function to calculate the Probability float Probability(int rating1 int rating2) {  // Calculate and return the expected score  return 1.0 / (1 + pow(10 (rating1 - rating2) / 400.0)); } // Function to calculate Elo rating // K is a constant. // outcome determines the outcome: 1 for Player A win 0 for Player B win 0.5 for draw. void EloRating(float Ra float Rb int K float outcome) {  // Calculate the Winning Probability of Player B  float Pb = Probability(Ra Rb);  // Calculate the Winning Probability of Player A  float Pa = Probability(Rb Ra);  // Update the Elo Ratings  Ra = Ra + K * (outcome - Pa);  Rb = Rb + K * ((1 - outcome) - Pb);  // Print updated ratings  cout << 'Updated Ratings:-n';  cout << 'Ra = ' << Ra << ' Rb = ' << Rb << endl; } // Driver code int main() {  // Current ELO ratings  float Ra = 1200 Rb = 1000;  // K is a constant  int K = 30;  // Outcome: 1 for Player A win 0 for Player B win 0.5 for draw  float outcome = 1;  // Function call  EloRating(Ra Rb K outcome);  return 0; } 
Java
import java.lang.Math; public class EloRating {  // Function to calculate the Probability  public static double Probability(int rating1 int rating2) {  // Calculate and return the expected score  return 1.0 / (1 + Math.pow(10 (rating1 - rating2) / 400.0));  }  // Function to calculate Elo rating  // K is a constant.  // outcome determines the outcome: 1 for Player A win 0 for Player B win 0.5 for draw.  public static void EloRating(double Ra double Rb int K double outcome) {  // Calculate the Winning Probability of Player B  double Pb = Probability(Ra Rb);  // Calculate the Winning Probability of Player A  double Pa = Probability(Rb Ra);  // Update the Elo Ratings  Ra = Ra + K * (outcome - Pa);  Rb = Rb + K * ((1 - outcome) - Pb);  // Print updated ratings  System.out.println('Updated Ratings:-');  System.out.println('Ra = ' + Ra + ' Rb = ' + Rb);  }  public static void main(String[] args) {  // Current ELO ratings  double Ra = 1200 Rb = 1000;  // K is a constant  int K = 30;  // Outcome: 1 for Player A win 0 for Player B win 0.5 for draw  double outcome = 1;  // Function call  EloRating(Ra Rb K outcome);  } } 
Python
import math # Function to calculate the Probability def probability(rating1 rating2): # Calculate and return the expected score return 1.0 / (1 + math.pow(10 (rating1 - rating2) / 400.0)) # Function to calculate Elo rating # K is a constant. # outcome determines the outcome: 1 for Player A win 0 for Player B win 0.5 for draw. def elo_rating(Ra Rb K outcome): # Calculate the Winning Probability of Player B Pb = probability(Ra Rb) # Calculate the Winning Probability of Player A Pa = probability(Rb Ra) # Update the Elo Ratings Ra = Ra + K * (outcome - Pa) Rb = Rb + K * ((1 - outcome) - Pb) # Print updated ratings print('Updated Ratings:-') print(f'Ra = {Ra} Rb = {Rb}') # Current ELO ratings Ra = 1200 Rb = 1000 # K is a constant K = 30 # Outcome: 1 for Player A win 0 for Player B win 0.5 for draw outcome = 1 # Function call elo_rating(Ra Rb K outcome) 
C#
using System; class EloRating {  // Function to calculate the Probability  public static double Probability(int rating1 int rating2)  {  // Calculate and return the expected score  return 1.0 / (1 + Math.Pow(10 (rating1 - rating2) / 400.0));  }  // Function to calculate Elo rating  // K is a constant.  // outcome determines the outcome: 1 for Player A win 0 for Player B win 0.5 for draw.  public static void CalculateEloRating(ref double Ra ref double Rb int K double outcome)  {  // Calculate the Winning Probability of Player B  double Pb = Probability((int)Ra (int)Rb);  // Calculate the Winning Probability of Player A  double Pa = Probability((int)Rb (int)Ra);  // Update the Elo Ratings  Ra = Ra + K * (outcome - Pa);  Rb = Rb + K * ((1 - outcome) - Pb);  }  static void Main()  {  // Current ELO ratings  double Ra = 1200 Rb = 1000;  // K is a constant  int K = 30;  // Outcome: 1 for Player A win 0 for Player B win 0.5 for draw  double outcome = 1;  // Function call  CalculateEloRating(ref Ra ref Rb K outcome);  // Print updated ratings  Console.WriteLine('Updated Ratings:-');  Console.WriteLine($'Ra = {Ra} Rb = {Rb}');  } } 
JavaScript
// Function to calculate the Probability function probability(rating1 rating2) {  // Calculate and return the expected score  return 1 / (1 + Math.pow(10 (rating1 - rating2) / 400)); } // Function to calculate Elo rating // K is a constant. // outcome determines the outcome: 1 for Player A win 0 for Player B win 0.5 for draw. function eloRating(Ra Rb K outcome) {  // Calculate the Winning Probability of Player B  let Pb = probability(Ra Rb);  // Calculate the Winning Probability of Player A  let Pa = probability(Rb Ra);  // Update the Elo Ratings  Ra = Ra + K * (outcome - Pa);  Rb = Rb + K * ((1 - outcome) - Pb);  // Print updated ratings  console.log('Updated Ratings:-');  console.log(`Ra = ${Ra} Rb = ${Rb}`); } // Current ELO ratings let Ra = 1200 Rb = 1000; // K is a constant let K = 30; // Outcome: 1 for Player A win 0 for Player B win 0.5 for draw let outcome = 1; // Function call eloRating(Ra Rb K outcome); 

Išvestis
Updated Ratings:- Ra = 1207.21 Rb = 992.792 

Laiko sudėtingumas: Algoritmo sudėtingumas laike labiausiai priklauso nuo pow funkcijos, kurios sudėtingumas priklauso nuo kompiuterių architektūros, sudėtingumo. x86 tai yra pastovaus laiko veikimas: -O(1)
Pagalbinė erdvė: O(1)