Skip to content

[WIP] Adding a sinusoidal temporal embedding #2826

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

yichiac
Copy link
Contributor

@yichiac yichiac commented Jun 10, 2025

Adding a generic cyclic/periodic embedding where the user inputs the period length and gets back sin/cos. #2382

@github-actions github-actions bot added testing Continuous integration testing transforms Data augmentation transforms labels Jun 10, 2025
@yichiac yichiac changed the title Adding a sinusoidal temporal embedding [WIP] Adding a sinusoidal temporal embedding Jun 10, 2025
@adamjstewart adamjstewart mentioned this pull request Jun 11, 2025
48 tasks
@yichiac yichiac marked this pull request as draft June 11, 2025 15:54
@yichiac yichiac requested a review from adamjstewart June 16, 2025 13:44
self,
period: pd.Timedelta,
time_key: str = 'time',
out_key: str = 'time_embedding',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's split the output into two keys. May not even need an out_key parameter. Could just use f"sin_{time_key}" and f"cos_{time_key}".

@@ -41,3 +41,22 @@ def test_rearrange_integration_in_augmentation_sequential() -> None:
out_batch = train_transforms(batch)
assert 'image' in out_batch
assert out_batch['image'].shape == (b, t * c, h, w)


def test_temporal_embedding_shape_and_values() -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also test the values themselves. They should be bounded between [-1, 1]. It may be useful to check math.isclose(output, expected) for a real number to make sure we do the pd.Timestamp <-> float conversion correctly, as I noticed that it isn't exactly intuitive and can be bug prone.

@adamjstewart adamjstewart added this to the 0.8.0 milestone Jun 19, 2025


class CyclicalEncoder(nn.Module):
"""Generic sinusoidal embedding for periodic temporal features."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. versionadded:: 0.8

@adamjstewart
Copy link
Collaborator

Let's make this even more generic. The same kind of encoder should work for lat/lon, not just time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Continuous integration testing transforms Data augmentation transforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants