Skip to content

Commit

Permalink
Flag for half handicap rank adjustments for hc1
Browse files Browse the repository at this point in the history
For testing as per #7
  • Loading branch information
anoek committed Jan 11, 2021
1 parent f569921 commit 82c9676
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def process_game(self, game: GameRecord) -> Glicko2Analytics:
## since we do not update deviation in periods without games, we have to do update it now if there are empty periods size the base rating was calclulated
black_base_time = self._storage.get_first_timestamp_older_than(game.black_id, window)
white_base_time = self._storage.get_first_timestamp_older_than(game.white_id, window)

if black_base_time is not None:
black_base.expand_deviation_because_no_games_played(int((game.ended - black_base_time) / no_games_window_witdh))
if white_base_time is not None:
Expand Down Expand Up @@ -118,7 +118,7 @@ def process_game(self, game: GameRecord) -> Glicko2Analytics:


# Run
config(cli.parse_args(), name="glicko2-glickman-1-week-window")
config(cli.parse_args(), name="glicko2-week-window-no-unexpected-changes")
ogs_game_data = GameData()
storage = InMemoryStorage(Glicko2Entry)
engine = DailyWindows(storage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def process_game(self, game: GameRecord) -> Glicko2Analytics:
## since we do not update deviation in periods without games, we have to do update it now if there are empty periods size the base rating was calclulated
black_base_time = self._storage.get_first_timestamp_older_than(game.black_id, window)
white_base_time = self._storage.get_first_timestamp_older_than(game.white_id, window)

if black_base_time is not None:
black_base.expand_deviation_because_no_games_played(int((game.ended - black_base_time) / no_games_window_witdh))
if white_base_time is not None:
Expand Down Expand Up @@ -85,7 +85,7 @@ def process_game(self, game: GameRecord) -> Glicko2Analytics:
)

## limit rating changes by base RD * num games
# glicko2 is desinged to update ratings based on full rating periods. There is a natural lower bound of the RD
# glicko2 is desinged to update ratings based on full rating periods. There is a natural lower bound of the RD
# depending on the number of games in the period. If there are fewer games in a period the RD is higher which
# results in bigger changes per game.
# We calculate imemdiate ratings each time a game ends. So after a new rating period started the game pool is
Expand Down Expand Up @@ -134,7 +134,7 @@ def process_game(self, game: GameRecord) -> Glicko2Analytics:


# Run
config(cli.parse_args(), name="glicko2-glickman-1-week-window")
config(cli.parse_args(), name="glicko2-week-window-reduce-rating-movement")
ogs_game_data = GameData()
storage = InMemoryStorage(Glicko2Entry)
engine = DailyWindows(storage)
Expand Down
22 changes: 16 additions & 6 deletions analysis/util/RatingMath.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@
help="Use logarithmic, linear, or GoR ranking",
)

A = 850
C = 32.25
#A = 850
#C = 32.25
A = 478
C = 12.9
D = 0
P = 1
HALF_STONE_HANDICAP = False

cli.add_argument(
"--half-stone-handicap", dest="half_stone_handicap", const=1, default=False, action="store_const", help="Use a 0.5 rank adjustment for hc1",
)

logarithmic = cli.add_argument_group(
"logarithmic ranking variables", "rating to ranks converted with `(log(rating / a) ** p) * c + d`",
Expand Down Expand Up @@ -65,10 +72,10 @@ def set_exhaustive_log_parameters(a: float, c:float, d:float, p:float = 1.0) ->
P = p

def get_handicap_adjustment(rating: float, handicap: int) -> float:
#return rank_to_rating(rating_to_rank(rating) + handicap) - rating

#return rank_to_rating(rating_to_rank(rating) + (handicap - 0.5 if handicap > 0 else 0)) - rating
return rank_to_rating(rating_to_rank(rating) + (0.5 if handicap == 1 else handicap)) - rating
global HALF_STONE_HANDICAP
if HALF_STONE_HANDICAP:
return rank_to_rating(rating_to_rank(rating) + (0.5 if handicap == 1 else handicap)) - rating
return rank_to_rating(rating_to_rank(rating) + handicap) - rating

def set_optimizer_rating_points(points: List[float]) -> None:
global optimizer_rating_control_points
Expand All @@ -81,7 +88,9 @@ def configure_rating_to_rank(args: argparse.Namespace) -> None:
global A
global C
global D
global HALF_STONE_HANDICAP

HALF_STONE_HANDICAP = args.half_stone_handicap
system: str = args.ranks
a: float = args.a
c: float = args.c
Expand All @@ -95,6 +104,7 @@ def configure_rating_to_rank(args: argparse.Namespace) -> None:

rating_config["system"] = system


if system == "linear":

def __rank_to_rating(rank: float) -> float:
Expand Down

0 comments on commit 82c9676

Please sign in to comment.