fidelity.py 870 B

123456789101112131415161718192021222324
  1. # fidelity.py
  2. # Keep fidelity/importance generators small and explicit.
  3. import random
  4. def generate_fidelity_list_random(path_num: int, alpha: float = 0.95, beta: float = 0.85, variance: float = 0.04):
  5. """
  6. Generate `path_num` fidelities.
  7. One "good" link around alpha, the rest around beta, clipped to [0.5, 1.0].
  8. """
  9. vals = []
  10. for i in range(path_num):
  11. mu = alpha if i == 0 else beta
  12. # simple Gaussian around mu, but clipped
  13. v = random.gauss(mu, variance**0.5)
  14. v = max(0.5, min(1.0, v))
  15. vals.append(v)
  16. # shuffle so the "good" link is not always index 0
  17. random.shuffle(vals)
  18. return vals
  19. def generate_importance_list_random(n: int, low: float = 0.5, high: float = 2.0):
  20. """Return a list of n importances I_n ~ Uniform[low, high]."""
  21. return [random.uniform(low, high) for _ in range(n)]