TruncatedNormal#
- class braintools.init.TruncatedNormal(mean, std, low=None, high=None, unit=None)#
Truncated normal distribution initialization.
Generates values from a normal distribution truncated to specified bounds.
Sampling uses the inverse-CDF (probability integral transform) method, so it is backend-agnostic: it works with the default
brainstate.randombackend as well as a NumPynumpy.random.Generatorpassed viarng.- Parameters:
mean (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Mean of the underlying normal distribution.std (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Standard deviation of the underlying normal distribution (must be >= 0).low (
Array|ndarray|bool|number|bool|int|float|complex|Quantity|None) – Lower bound (default: -inf).high (
Array|ndarray|bool|number|bool|int|float|complex|Quantity|None) – Upper bound (default: +inf).
Examples
>>> import numpy as np >>> import brainunit as u >>> from braintools.init import TruncatedNormal >>> >>> init = TruncatedNormal( ... mean=0.5 * u.siemens, ... std=0.2 * u.siemens, ... low=0.0 * u.siemens, ... high=1.0 * u.siemens ... ) >>> rng = np.random.default_rng(0) >>> weights = init(1000, rng=rng)