hyperdimensional-computing / torchhd

Torchhd is a Python library for Hyperdimensional Computing and Vector Symbolic Architectures
https://torchhd.readthedocs.io
MIT License
248 stars 25 forks source link

Squared sinc distribution to create triangular kernel shape #151

Closed scken closed 1 year ago

scken commented 1 year ago

@mikeheddes, I added another sampling distribution to the FPE example script from @denkle.

It is a custom torch distribution that samples from a squared sinc function to get a triangular kernel shape in FPE. This might be a helpful suggestion for other users because a linear kernel adds another useful one to the sinc and Gaussian shape.

I'm not sure if the implementation is the best to sample from the given distribution (rejection sampling) - maybe you have another idea for a better implementation.

mikeheddes commented 1 year ago

@scken thank you for adding this example, it is very helpful indeed! I am not sure how to sample more efficiently, my first thought was to do inverse transform sampling but that doesn't seem to be simple in this case since the sinc doesn't have a nice inverse. We can always improve in a future PR if someone knows about a better way.

Just some minor comments on the code, could you change the comment ## Gaussian kernel at the top of the cells you added to reflect the actually implemented kernel. And the first figure label is "Triangular kernel with HRR model" which I belief should be "Triangular kernel with FHRR model". I also see that you got an error in the 2D kernels Unknown projection '3d', if you could resolve the error and re-run the cells that would be great, otherwise everybody will see the error.

Other than that I think the code is great and ready to be merged. Thanks again!

scken commented 1 year ago

Thanks @mikeheddes for your comments. I have fixed the points and pushed the changes to the branch.

mikeheddes commented 1 year ago

Looks great @scken, thank you for your contribution!