@@ -744,7 +744,11 @@ def _sum_q(
744
744
)
745
745
comparison_count += 1
746
746
747
- adjusted_mu += margin_adjustment / comparison_count
747
+ adjusted_mu += (
748
+ (margin_adjustment / comparison_count )
749
+ if comparison_count
750
+ else margin_adjustment
751
+ )
748
752
749
753
summed = math .exp (adjusted_mu / c )
750
754
for q , team_q in enumerate (team_ratings ):
@@ -830,7 +834,11 @@ def _compute(
830
834
)
831
835
comparison_count += 1
832
836
833
- adjusted_mu_i += margin_adjustment / comparison_count
837
+ adjusted_mu_i += (
838
+ (margin_adjustment / comparison_count )
839
+ if comparison_count
840
+ else margin_adjustment
841
+ )
834
842
835
843
i_mu_over_c = math .exp (adjusted_mu_i / c )
836
844
@@ -1075,10 +1083,8 @@ def _calculate_team_ratings(
1075
1083
1076
1084
:return: A list of :class:`PlackettLuceTeamRating` objects.
1077
1085
"""
1078
- if ranks :
1079
- rank = self ._calculate_rankings (game , ranks )
1080
- else :
1081
- rank = self ._calculate_rankings (game )
1086
+ if ranks is None :
1087
+ ranks = self ._calculate_rankings (game )
1082
1088
1083
1089
result = []
1084
1090
for index , team in enumerate (game ):
@@ -1097,7 +1103,7 @@ def _calculate_team_ratings(
1097
1103
sigma_squared_summed += (player .sigma * balance_weight ) ** 2
1098
1104
result .append (
1099
1105
PlackettLuceTeamRating (
1100
- mu_summed , sigma_squared_summed , team , int (rank [index ])
1106
+ mu_summed , sigma_squared_summed , team , int (ranks [index ])
1101
1107
)
1102
1108
)
1103
1109
return result
@@ -1124,15 +1130,15 @@ def _calculate_rankings(
1124
1130
return []
1125
1131
1126
1132
if ranks :
1127
- team_scores = [ranks [i ] or i for i , _ in enumerate (game )]
1133
+ team_scores = []
1134
+ for index , _ in enumerate (game ):
1135
+ team_scores .append (ranks [index ] or index )
1128
1136
else :
1129
1137
team_scores = [i for i , _ in enumerate (game )]
1130
1138
1131
- output_ranks : dict [int , float ] = {}
1132
- s = 0
1133
- for index , value in enumerate (team_scores ):
1134
- if index > 0 :
1135
- if team_scores [index - 1 ] < team_scores [index ]:
1136
- s = index
1137
- output_ranks [index ] = s
1138
- return list (output_ranks .values ())
1139
+ sorted_scores = sorted (team_scores )
1140
+ rank_map : dict [float , int ] = {}
1141
+ for index , value in enumerate (sorted_scores ):
1142
+ if value not in rank_map :
1143
+ rank_map [value ] = index
1144
+ return [rank_map [v ] for v in team_scores ]
0 commit comments