pathpy / pathpyG

GPU-accelerated Next-Generation Network Analytics and Graph Learning for Time Series Data on Complex Networks.
https://www.pathpy.net
GNU Affero General Public License v3.0
33 stars 3 forks source link

VoseAliasSampling slow for many samples #217

Closed M-Lampert closed 1 week ago

M-Lampert commented 3 weeks ago

The VoseAliasSampling implementation migrated from the older PathPy versions does as far as I am aware the same thing as torch.multinomial or np.random.choice. Both are an order of magnitude faster for large values and similarly fast for one sample. The following MWE shows this:

import torch

from pathpyG.processes import VoseAliasSampling

weights = torch.randint(0, 10, (3000,)).float()
sampler = VoseAliasSampling(weights.tolist())

Using the Jupyter cell magic %timeit, we get the following runtimes for each of them:

Although there is a small runtime benefit for single samples, I propose to remove this class altogether in favor of using torch.multinomial, since our goal is to speed up the code that would be using this sampler with torch anyway.