Skip to content

Implement Vector-Derived Transformation Binding #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/torchhd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ VSA Models
MAPTensor
HRRTensor
FHRRTensor
VTBTensor


Utilities
Expand Down
2 changes: 2 additions & 0 deletions torchhd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from torchhd.tensors.map import MAPTensor
from torchhd.tensors.hrr import HRRTensor
from torchhd.tensors.fhrr import FHRRTensor
from torchhd.tensors.vtb import VTBTensor

from torchhd.functional import (
ensure_vsa_tensor,
Expand Down Expand Up @@ -84,6 +85,7 @@
"MAPTensor",
"HRRTensor",
"FHRRTensor",
"VTBTensor",
"functional",
"embeddings",
"structures",
Expand Down
8 changes: 4 additions & 4 deletions torchhd/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,9 +806,9 @@ def __init__(
self.out_features = out_features
self.vsa = vsa

if vsa not in {"MAP", "HRR"}:
if vsa not in {"MAP", "HRR", "VTB"}:
raise ValueError(
f"Projection embedding only supports MAP and HRR but provided: {vsa}"
f"Projection embedding supports MAP, HRR, VTB but provided: {vsa}"
)

self.weight = nn.parameter.Parameter(
Expand Down Expand Up @@ -877,9 +877,9 @@ def __init__(
self.out_features = out_features
self.vsa = vsa

if vsa not in {"MAP", "HRR"}:
if vsa not in {"MAP", "HRR", "VTB"}:
raise ValueError(
f"Sinusoid embedding only supports MAP and HRR but provided: {vsa}"
f"Sinusoid embedding supports MAP, HRR, VTB but provided: {vsa}"
)

self.weight = nn.parameter.Parameter(
Expand Down
7 changes: 5 additions & 2 deletions torchhd/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from torchhd.tensors.map import MAPTensor
from torchhd.tensors.hrr import HRRTensor
from torchhd.tensors.fhrr import FHRRTensor
from torchhd.tensors.vtb import VTBTensor
from torchhd.types import VSAOptions


Expand Down Expand Up @@ -82,6 +83,8 @@ def get_vsa_tensor_class(vsa: VSAOptions) -> Type[VSATensor]:
return HRRTensor
elif vsa == "FHRR":
return FHRRTensor
elif vsa == "VTB":
return VTBTensor

raise ValueError(f"Provided VSA model is not supported, specified: {vsa}")

Expand Down Expand Up @@ -540,9 +543,9 @@ def circular(
"""
vsa_tensor = get_vsa_tensor_class(vsa)

if vsa_tensor == HRRTensor:
if vsa == "HRR" or vsa == "VTB":
raise ValueError(
"The circular hypervectors don't currently work with the HRR model. We are not sure why, if you have any insight that could help please share it at: https://github.com/hyperdimensional-computing/torchhd/issues/108."
"The circular hypervectors do currently not work with the HRR and VTB models. We are not sure why, if you have any insight that could help please share it at: https://github.com/hyperdimensional-computing/torchhd/issues/108."
)

# convert from normalized "randomness" variable r to
Expand Down
Loading