sample_beta_with_mean#
- bamengine.utils.sample_beta_with_mean(mean, n=1, low=None, high=None, concentration=12.0, *, relative_margin=0.5, rng=None)[source]#
Draw n samples from a Beta distribution scaled to [low, high), such that the scaled mean is approximately ``mean``.
- Parameters:
mean (
float) – Desired mean of the returned samples. Can be any positive value.n (
int, default1) – Number of samples to draw.low (
floatorNone, optional) –Bounds of the target interval. If either is None, it is derived as:
low = mean * (1 - relative_margin) high = mean * (1 + relative_margin)
making the mean the midpoint of the interval. A tiny eps is added when needed to guarantee
low < mean < high.high (
floatorNone, optional) –Bounds of the target interval. If either is None, it is derived as:
low = mean * (1 - relative_margin) high = mean * (1 + relative_margin)
making the mean the midpoint of the interval. A tiny eps is added when needed to guarantee
low < mean < high.concentration (
float, default12) – Total pseudo–sample size of the Beta (a+b). Larger values concentrate the draws more tightly around mean.relative_margin (
float, default0.50) – Half-width of the automatically generated interval as a fraction of mean. Set 0.25 for ±25 %, 1.0 for ±100 %, etc.rng (
np.random.Generator, optional) – Random number generator (falls back todefault_rng()).
- Returns:
n samples if
n > 1; otherwise a scalar.- Return type:
floatorndarray
Notes
If mean is very close to zero, the automatically chosen
lowmay be negative; it is then clipped to zero and an eps-wide gap is kept so thatmeanstays strictly inside the interval.The function raises
ValueErrorfor invalid arguments.