Skip to content

Commit

Permalink
change get max score algorithm to search in coarse and then fine steps
Browse files Browse the repository at this point in the history
reduces number of iterations required to seek maximum score by approx 2 orderes magnitude
  • Loading branch information
TomHall2020 committed Mar 5, 2024
1 parent 4db85f5 commit eea8ef4
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions archeryutils/handicaps/handicap_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,21 +584,30 @@ def _get_max_score_handicap(

if self.desc_scale:
handicap = min(self.scale_bounds)
delta_hc = 0.01
delta_hc = 1.0
else:
handicap = max(self.scale_bounds)
delta_hc = -0.01
delta_hc = -1.0

target = max_score - self.max_score_rounding_lim

def check_score(handicap):
return self.score_for_round(handicap, rnd, arw_d, rounded_score=False)

# Work down to where we would round or ceil to max score
# Work down (coarse) to where we would round or ceil to max score
while check_score(handicap) > target:
handicap = handicap + delta_hc
handicap += delta_hc

# Step back extra after overshoot and reduce step size
handicap -= 1.01 * delta_hc
delta_hc /= 100

# Work down (fine) to where we would round or ceil to max score
while check_score(handicap) > target:
handicap += delta_hc

handicap -= delta_hc # Undo final iteration that overshoots

handicap = handicap - delta_hc # Undo final iteration that overshoots
if int_prec:
if self.desc_scale:
handicap = np.floor(handicap)
Expand Down

0 comments on commit eea8ef4

Please sign in to comment.