Closed martwo closed 1 year ago
Profiling of SkyLLH concluded that much time is spend in the numpy.random.choice function when generating signal events. The code of that function is here: https://github.com/numpy/numpy/blob/20d03bcfd9864527bf70cf3747ade162d2034f68/numpy/random/mtrand.pyx#L952-L995
Since the MC event probabilities do not change between trials, one could save the cumulative distribution function (cdf) and reuse it. Also there is no need for value checking of the probabilities each call. This should speed up signal generation.
I propose a small RandomChoice class which holds the CDF of the signal candidates: https://github.com/icecube/skyllh/blob/074c50891a7b9ecedcb5fef65af6a5b7126cb1b5/skyllh/core/signal_generator.py#L645
RandomChoice
Profiling of SkyLLH concluded that much time is spend in the numpy.random.choice function when generating signal events. The code of that function is here: https://github.com/numpy/numpy/blob/20d03bcfd9864527bf70cf3747ade162d2034f68/numpy/random/mtrand.pyx#L952-L995
Since the MC event probabilities do not change between trials, one could save the cumulative distribution function (cdf) and reuse it. Also there is no need for value checking of the probabilities each call. This should speed up signal generation.
I propose a small
RandomChoice
class which holds the CDF of the signal candidates: https://github.com/icecube/skyllh/blob/074c50891a7b9ecedcb5fef65af6a5b7126cb1b5/skyllh/core/signal_generator.py#L645