brainpy / BrainPy

Brain Dynamics Programming in Python
https://brainpy.readthedocs.io/
GNU General Public License v3.0
515 stars 93 forks source link

fix bugs in `truncated_normal` #585

Closed charlielam0615 closed 9 months ago

charlielam0615 commented 9 months ago

Description

truncated_normal in brainpy.math.random calls jr.uniform to sample from a uniform distribution and then inverse the cdf to get truncated values.

jr.uniform samples from a closed interval. When lower or upper takes inf values and when jr.uniform sampled an extreme value, the inverse cdf would have inf values, which result in underflow values after clipping.

Fix: subtract and add a small value to minval and maxval arguments of jr.uniform.

How Has This Been Tested

Types of changes

Checklist

Other information