Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

cython - Accelerate a poisson waiting time calculation in Python

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...