Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
413 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 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...