Skip to content
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

Noisy node modification #271

Merged
merged 4 commits into from
Aug 13, 2024
Merged
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
9 changes: 8 additions & 1 deletion matsciml/datasets/transforms/pretraining/noisy_positions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class NoisyPositions(AbstractDataTransform):
def __init__(self, scale: float = 1e-3) -> None:
def __init__(self, scale: float = 1e-1, normalize: bool = False) -> None:
"""
Initializes a NoisyPositions transform.

Expand All @@ -31,9 +31,13 @@ def __init__(self, scale: float = 1e-3) -> None:
----------
scale : float
Scale used to multiply N~(0, I_3) Gaussian noise
normalize : bool
If True, rescales the noise tensor by the scale
for loss computation. This is done in Liao, 2024.
"""
super().__init__()
self.scale = scale
self.normalize = normalize

def __call__(self, data: DataDict) -> DataDict:
if "graph" in data:
Expand All @@ -58,6 +62,9 @@ def __call__(self, data: DataDict) -> DataDict:
else:
data["noisy_pos"] = noisy_pos
# set targets so that tasks know what to do
# noise targets are normalized by the scale
if self.normalize:
noise /= self.scale
laserkelvin marked this conversation as resolved.
Show resolved Hide resolved
data["targets"]["denoise"] = noise
if "pretraining" in data["target_types"]:
data["target_types"]["pretraining"].append("denoise")
Expand Down
Loading