Skip to content

[Draft] 349 feat simulated annealing#380

Draft
amarshah1999 wants to merge 18 commits into
Alek050:developfrom
amarshah1999:349-feat-simulated-annealing
Draft

[Draft] 349 feat simulated annealing#380
amarshah1999 wants to merge 18 commits into
Alek050:developfrom
amarshah1999:349-feat-simulated-annealing

Conversation

@amarshah1999

@amarshah1999 amarshah1999 commented May 7, 2026

Copy link
Copy Markdown

[Draft] Introduces the simulated annealing project as outlined here #349

ToDo List:

  • Replace Tester file with actual docs and a sample notebook
  • Add unit test
  • Create a visualisation function to show the changes that the algorithm makes to player positions (and then undo my changes in visualize.py)

amarshah1999 and others added 13 commits March 8, 2026 20:44
- Working commit
- Introduces new base classes, and simulated annealing itself
- Temporary tester file
- Created a re-usable ObjectiveTerm function which takes in at least an input frame and computes a float from it
- Used these reusable objectives and weights in the SimulatedAnnealing class to compute the objective
- Adds a class for generic constraints, which can be computed to check validity based on an input frame and player id
- Implemented a specific constraint for simulated annealing that ensures the player is within a TimeToIntercept radius, i.e. the perturbation from simulated annealing is such that the player could get there within X seconds.
- Makes a minor addition of an alpha parameter to visualize.py also
- Move optimization objects into separate classes
- Add logging properly instead of print statements
- Formatting
Creates a wrapper function around the Algorithm.run() method that can easily be extended to hot swap optimization algorithms
@amarshah1999 amarshah1999 marked this pull request as draft May 7, 2026 19:27
@codecov

codecov Bot commented May 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.28%. Comparing base (e4ce2b3) to head (b53cc9f).
⚠️ Report is 89 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #380      +/-   ##
===========================================
+ Coverage    99.22%   99.28%   +0.05%     
===========================================
  Files           49       67      +18     
  Lines         3736     5441    +1705     
===========================================
+ Hits          3707     5402    +1695     
- Misses          29       39      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Previously I was trying to save compute by only passing in what is necessary
- It's much cleaner to use if all the constraints and objectives just take in game, frame and some optional extra arguments.
- I will revisit this if we want to make the pre-made objectives a bit more flexible
@Alek050

Alek050 commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Hi @amarshah1999,

I really like the implementation, it is clean and structured. I was able to play with it and it worked really nicely. I think this is a great starting point and now we have to make it (1) more customisable and intuitive and (2) production ready. Let me give a few examples of point 1 I think would benefit:

  • Add a random_state variable
  • Add a verbosity to track progress
  • fix overflow warnings (especially in match.exp calls)
  • Add a patience so the early stopping is customizable as well
  • More complicated but a deepcopy of a Game is probably the least efficient way to make the visualisation, so we have to think about if we can make this better.

Again, I really like it. It also confirmed what I thought would be the case: not the optimization algorithm but the creation of the right objective function is probably the bottleneck of these use cases, but implementing this will give the community the tools to work on that.

I also think that it would be great to be more elaborate on different situations, including/excluding players to change position, etc.. And ideally I would not want the skillcorner but some databally inherintly supported exmaple data (e.g. docs/saved_games/synced_game) to showcase since the integration of skillcorner, kloppy, and databallpy is not really the subject of this project.

Let me know what you think and if you want me to help you out anywhere with that!

- added random state, verbosity, patience
- replaced skillcorner data
- made it explicit in the docs that you can specify which players to move
@amarshah1999

amarshah1999 commented Jun 13, 2026

Copy link
Copy Markdown
Author
  • Add a random_state variable
  • Add a verbosity to track progress
  • fix overflow warnings (especially in match.exp calls) - could you elaborate on this? I could not figure out how to repro this error. I found a runtime error which happens when calling tti on a stationary player, this might be the same thing you were seeing?
  • Add a patience so the early stopping is customizable as well
  • More complicated but a deepcopy of a Game is probably the least efficient way to make the visualisation, so we have to think about if we can make this better. agree! let me think on this some more
  • Replace skillcorner data with default synced_game
  • Filtering players to include - I added this to the docs, it was already available just hidden.

Will remove the warnings from the docs later on. Just have it like that because my local setup is overly verbose.

Comment on lines +119 to +121
if (new_score > best_score) or math.exp(
(new_score - best_score) / T
) > self._rng.random():

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amarshah1999,

I mean this part, when new_score - best_score / T is greater than 709 or smaller than -709 it will result in a overflow warning/error. Just clip it with np.clip((new_score - best_score) / T, -700, 700) or a similar solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants