Module rating.rating.polyrating_davidson
Classes
class PolyratingDavidson (theta: float = 1, *args, **kwargs)-
A class that represents the Whole History Rating system based on the Davidson method. Davidson extends the Bradley-Terry model to accommodate the possibility of ties. Based on https://www.semanticscholar.org/paper/On-Extending-the-Bradley-Terry-Model-to-Accommodate-Davidson/3833525afb515fbf56c616b5ae5470247fc38fa5
Attributes
- theta (float): A parameter that controls the weight of the tie probability in the rating calculation.
Args
- theta (float): The value of theta parameter.
Expand source code
class PolyratingDavidson(Polyrating): def __init__(self, theta: float = 1, *args, **kwargs) -> 'PolyratingDavidson': """ A class that represents the Whole History Rating system based on the Davidson method. Davidson extends the Bradley-Terry model to accommodate the possibility of ties. Based on https://www.semanticscholar.org/paper/On-Extending-the-Bradley-Terry-Model-to-Accommodate-Davidson/3833525afb515fbf56c616b5ae5470247fc38fa5 Attributes: - theta (float): A parameter that controls the weight of the tie probability in the rating calculation. Args: - theta (float): The value of theta parameter. """ if 'allow_complex_result' in kwargs: del kwargs['allow_complex_result'] super().__init__(*args, **kwargs, theta=theta, allow_complex_result=False) def denominator(self, gamma1 : float, gamma2 : float) -> float: return (gamma1 + gamma2 + self.theta * np.sqrt(gamma1 * gamma2)) def win_prob(self, rating1 : float, rating2 : float) -> float: gamma1 = self.gamma(rating1) gamma2 = self.gamma(rating2) return gamma1 / self.denominator(gamma1, gamma2) def log_win(self, rating1 : float, rating2 : float) -> float: gamma1 = self.gamma(rating1) gamma2 = self.gamma(rating2) return np.log(gamma1) - np.log(self.denominator(gamma1, gamma2)) def tie_prob(self, rating1 : float, rating2 : float) -> float: gamma1 = self.gamma(rating1) gamma2 = self.gamma(rating2) return self.theta * np.sqrt(gamma1 * gamma2) / self.denominator(gamma1, gamma2) def log_tie(self, rating1 : float, rating2 : float, result : float = 0.5) -> float: gamma1 = self.gamma(rating1) gamma2 = self.gamma(rating2) return np.log(self.theta * np.sqrt(gamma1 * gamma2)) - np.log(self.denominator(gamma1, gamma2)) def derivative_log_win(self, rating1 : float, rating2 : float) -> float: gamma1 = self.gamma(rating1) gamma2 = self.gamma(rating2) derivative1 = self.derivative_gamma(rating1) term1 = 1 / gamma1 * derivative1 term2 = - 1 / self.denominator(gamma1, gamma2) * (1 + self.theta / 2 * np.sqrt(gamma2 / gamma1)) * derivative1 return term1 + term2 def second_derivative_log_win(self, rating1 : float, rating2 : float) -> float: gamma1 = self.gamma(rating1) gamma2 = self.gamma(rating2) derivative1 = self.derivative_gamma(rating1) second_derivative1 = self.second_derivative_gamma(rating1) term1 = -1 / gamma1 ** 2 * derivative1 ** 2 + 1 / gamma1 * second_derivative1 term2 = 1 / (self.denominator(gamma1, gamma2) ** 2) * (1 + self.theta / 2 * np.sqrt(gamma2 / gamma1)) ** 2 * derivative1 ** 2 term3 = - 1 / self.denominator(gamma1, gamma2) * (1 + self.theta / 2 * np.sqrt(gamma2 / gamma1)) * second_derivative1 term4 = 1 / self.denominator(gamma1, gamma2) * self.theta / 4 * np.sqrt(gamma2) * (1 / gamma1) ** (3 / 2) * derivative1 ** 2 return term1 + term2 + term3 + term4 def derivative_log_loss(self, rating1 : float, rating2 : float) -> float: gamma1 = self.gamma(rating1) gamma2 = self.gamma(rating2) derivative1 = self.derivative_gamma(rating1) term2 = - 1 / self.denominator(gamma1, gamma2) * (1 + self.theta / 2 * np.sqrt(gamma2 / gamma1)) * derivative1 return term2 def second_derivative_log_loss(self, rating1 : float, rating2 : float) -> float: gamma1 = self.gamma(rating1) gamma2 = self.gamma(rating2) derivative1 = self.derivative_gamma(rating1) second_derivative1 = self.second_derivative_gamma(rating1) term2 = 1 / (self.denominator(gamma1, gamma2) ** 2) * (1 + self.theta / 2 * np.sqrt(gamma2 / gamma1)) ** 2 * derivative1 ** 2 term3 = - 1 / self.denominator(gamma1, gamma2) * (1 + self.theta / 2 * np.sqrt(gamma2 / gamma1)) * second_derivative1 term4 = 1 / self.denominator(gamma1, gamma2) * self.theta / 4 * np.sqrt(gamma2) * (1 / gamma1) ** (3 / 2) * derivative1 ** 2 return term2 + term3 + term4 def derivative_log_tie(self, rating1 : float, rating2 : float, result : float = 0.5) -> float: gamma1 = self.gamma(rating1) gamma2 = self.gamma(rating2) derivative1 = self.derivative_gamma(rating1) term1 = 1 / (2 * gamma1) * derivative1 term2 = - 1 / self.denominator(gamma1, gamma2) * (1 + self.theta / 2 * np.sqrt(gamma2 / gamma1)) * derivative1 return term1 + term2 def second_derivative_log_tie(self, rating1 : float, rating2 : float, result : float = 0.5) -> float: gamma1 = self.gamma(rating1) gamma2 = self.gamma(rating2) derivative1 = self.derivative_gamma(rating1) second_derivative1 = self.second_derivative_gamma(rating1) term1 = -1 / gamma1 ** 2 * derivative1 ** 2 + 1 / gamma1 * second_derivative1 term2 = 1 / (self.denominator(gamma1, gamma2) ** 2) * (1 + self.theta / 2 * np.sqrt(gamma2 / gamma1)) ** 2 * derivative1 ** 2 term3 = - 1 / self.denominator(gamma1, gamma2) * (1 + self.theta / 2 * np.sqrt(gamma2 / gamma1)) * second_derivative1 term4 = 1 / self.denominator(gamma1, gamma2) * self.theta / 4 * np.sqrt(gamma2) * (1 / gamma1) ** (3 / 2) * derivative1 ** 2 return term1 / 2 + term2 + term3 + term4Ancestors
Methods
def denominator(self, gamma1: float, gamma2: float) ‑> float
Inherited members
Polyrating:add_kwargsapply_armijos_ruleassign_submatrixbreak_condition_player_nonebreak_condition_player_not_nonecompute_expected_scorecompute_expected_score_ratingcompute_final_variances_playercompute_likelihoodcompute_period_updatecompute_tournament_performancederivative_gammaderivative_log_lossderivative_log_tiederivative_log_winderivative_markovderivative_priorextract_periodsfind_classgammagenerate_kwarg_settinggenerate_list_settingsgenerate_settingsget_all_subclassesget_default_ratingsget_input_parametersinitialize_games_per_playersinitialize_ratingsinitialize_shared_derivativesloadload_from_dictload_from_list_settingsload_from_settingslog_priorlog_tielog_winmarkovperiod_updatesavesecond_derivative_gammasecond_derivative_log_losssecond_derivative_log_tiesecond_derivative_log_winsecond_derivative_markovsecond_derivative_priortie_probupdate_playerupdate_shared_ratingswin_prob