I'm a beginner to Python, attempting something a bit too complicated for me...
I want to output a list (q), k-items long, where each item is one of five options (contained in list w).
w = [a, b, c, d, e]
I'm using random.choices to create list q.
I want each item's weighting to be governed by a skewed bell curve (or even a rough approximation of one), where the horizontal position of the curve's peak equals p. p can range from 0.1 to 1.
So, if p = 0.55, item c should have the highest probability of appearing in list q, with b and d having the second highest probability, and a and e having the lowest probability. If p = 0.1, a should be the most likely to appear and e the least likely, and so on.
I've found scipy.stats.skewnorm, which seems like it could work. However, I'm really struggling to adapt it into the form I need.
I'm after a function where 0 ≤ y ≤ 1 and 0 ≤ x ≤ 1.2. I then want this function to create the five weights for random.choices, something like so:
p = 0.7
prob_a = f(0.2, p)
prob_b = f(0.4, p)
prob_c = f(0.6, p)
etc...
q = random.choices(w, weights=[prob_a, prob_b, prob_c, etc...], k=10)
I'd be extremely grateful for any and all advice, direction, or suggestions! I'm not wedded to either random.choices or skewnorm – if there's a simpler way to achieve a similar result, that'd be amazing!
Many thanks.
Aucun commentaire:
Enregistrer un commentaire