Projective Simulation
  • Get started
  • Documentation
  • Tutorials
  • Research

source

sample_binomial_gap

def sample_binomial_gap(
    mu_:float, var_:float, rng:NoneType=None
)->int:

Sample a nonnegative integer gap with target mean/variance using a Binomial fit, then clamp to ensure the gap length is at least 1 (timeout ≥ 1).

Logic: - Binomial(n,p) has mean μ = n p and variance σ² = n p (1-p) = μ (1-p). Given target μ, σ² < μ implies p = 1 - σ²/μ ∈ (0,1) and n ≈ μ / p. We round n to an integer ≥ 1 and recompute p = μ / n (clipped into (0,1)). - If σ² ≥ μ (outside Binomial under-dispersion), we approximate the Poisson boundary by taking a large n with small p that preserves μ, still sampling from Binomial. - Finally, we enforce a minimum gap of 1 to guarantee at least one timeout step.

  • View source
  • Report an issue