Within my python routine, I have a function that I call to simulate poisson waiting times:
import numpy as np
import math
def poisson_claims(n_vals, lambda):
x = np.random.uniform(0, 1, size=n_vals)
indiv_wait_times = [-math.log(1.0 - i)/lambda for i in x]
return np.cumsum(indiv_wait_times)
Unfortunately, I have determined that this function call is extremely expensive. Accordingly, I am looking for alternative code structures that can accelerate this. In my search, I have identified cython and numba but they seem non-trivial to implement (cython seems more complex given that my code may be run in a Windows, Linux or Mac environment; numba keeps giving me an error related to usage of a panda series when it is advertised to work with numpy??). Is there an easier way to accelerate the code that I'm missing?
question from:
https://stackoverflow.com/questions/66056572/accelerate-a-poisson-waiting-time-calculation-in-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…