I am trying to generate datasets following truncated negative binomial distribution consisting of numbers such that the number set has a max value.
def truncated_Nbinom(n, p, max_value, size):
import scipy.stats as sct
temp_size = size
while True:
temp_size *= 2
temp = sct.nbinom.rvs(n, p, size=temp_size)
truncated = temp[temp <= max_value]
if len(truncated) >= size:
return truncated[:size]
I am able to get results when the max_value and n are smaller. However when I try with:
input_1= truncated_Nbinom(99, 0.3, 99, 5000).tolist()
The kernel keeps dying. I tried to change the port of python and raising the recursion limit, but they didn't work. Do you have any ideas to make my code faster?