Skip to content

Fix underflow in weighted sampling without replacement - #3990

Merged
quaquel merged 2 commits into
mesa:mainfrom
bhabishnu:fix/select-random-weight-underflow
Nov 6, 2026
Merged

quaquel merged 2 commits into
mesa:mainfrom
bhabishnu:fix/select-random-weight-underflow

Conversation

@bhabishnu

Copy link
Copy Markdown
Contributor

Pre-PR Checklist

  • This PR is a bug fix, not a new feature or enhancement.

Summary

Fixes weighted sampling without replacement when normalized weights, such as softmax probabilities, cause the A-Res keys to underflow.

Bug / Issue

select_random() currently computes keys using u ** (1 / w). With many small normalized weights, these can collapse to 0.0 and bias selection toward insertion order.

Implementation

Compute the keys as log(u) / w instead. This preserves the same ordering while avoiding the underflow.

Testing

Added a regression test comparing raw fitness weights with the same weights normalized to probabilities.

  • tests/test_agentset.py: 52 passed
  • Ruff and pre-commit checks passed

Additional Notes

AI tools were used as assistive tools during investigation and review.

@github-actions github-actions Bot added the testing Release notes label label Oct 26, 2026
@quaquel quaquel added the bug Release notes label label Nov 6, 2026
@quaquel
quaquel merged commit 7d795e9 into mesa:main Nov 6, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Release notes label testing Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants