From c60f89deeea561ae755f1f02e498d4e548644906 Mon Sep 17 00:00:00 2001 From: SevgiAkten Date: Mon, 12 Aug 2024 12:24:00 +0300 Subject: [PATCH] add the disappearing sample function --- src/optimizer.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/optimizer.py b/src/optimizer.py index 9d3222d..9181387 100644 --- a/src/optimizer.py +++ b/src/optimizer.py @@ -841,6 +841,28 @@ def generate_probability_vector(mins: List[float], maxs: List[float], ntries: in return probvector +def sample(probvector: List[float]) -> List[int]: + """ + Sample a vector based on the provided probability vector. + + Parameters + ---------- + probvector : List[float] + Probability vector for sampling. + + Returns + ------- + List[int] + Sampled binary vector. + """ + n = len(probvector) + newvector = [0] * n + + for i in range(n): + if random.random() < probvector[i]: + newvector[i] = 1 + + return newvector