hyperdimensional-computing / torchhd

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

`randsel` has inverted probability for input versus other selection #161

Closed arendsee closed 8 months ago

arendsee commented 8 months ago

The function randsel takes a parameter p which the documentation states is the probability of selecting a value from the input vector. So it should be true that randsel(x, y, p=1) == x. However, this is not true and instead randsel(x, y, p=0) == x and randsel(x, y, p=1) == y.

p is the probability of not selecting from the input vector. I suspect you have a 1-p in your code where you should just have p.

mikeheddes commented 8 months ago

Thank you for opening this issue. You are right, there is a 1-p which shouldn't be. I will fix it right away.

arendsee commented 8 months ago

You could also just change the documentation. I'm using randsel to "fuzz" a vector. For example, randsel(red_color, random(1, d), p=0.1), randomly moves 1/10 of the bits in red_color, making a "reddish" value. As it stands,p is a measure of the degree to which the input is moved toward the output.

mikeheddes commented 8 months ago

That would also be an option but with the changes I just made the API works the same as torch.where where True selects input and False selects other. I don't have a strong opinion which one is better.