Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization results aren't exactly the same from run to run even with set seed #504

Open
kelvinburke opened this issue Jul 5, 2024 · 1 comment
Assignees

Comments

@kelvinburke
Copy link
Contributor

kelvinburke commented Jul 5, 2024

So doing some testing for the optimization-start-skip branch - I found that from run to run, the function values that an optimization would get would not always be exactly the same if you re-run with the same seed.

This is because of:
constrain_sum_bounded() calls scipy.optimize.minimize, which can give a slightly different solution if you re-order the initial vector.

constrain_sum_bounded() is called by TotalSpendConstraint.constrain_instructions() and the hard_constraints that it receives has hard_constraints["programs"][t] as a set. This means from run to run hard_constraints["programs"][t] can change order, so the input to constrain_sum_bounded() changes order and gives a different constrained budget.

So the budget getting constrained differently gives different results from run to run.

Solutions are:

  • progs = sorted(hard_constraints["programs"][t]) # Programs eligible for constraining at this time gives a consistent order to the programs from run to run. This alone fixes the problem
  • Optionally order the array in constrain_sum_bounded() before running scipy.optimize.minimize and then put back in the original order. This doesn't always fix it - if the values in the array have duplicates. So this change is not necessary and I might undo it?
  • Possibly could change hard_constraints["programs"][t] to not be a set? I haven't tried this

See optimization-start-skip branch for these committed changes

@RomeshA
Copy link
Contributor

RomeshA commented Jul 10, 2024

Thanks @kelvinburke, of those options I think sorting the programs with sorted(hard_constraints["programs"][t]) would be the best 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

No branches or pull requests

2 participants