-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from EthanMarx/augmentations
Add `SignalInverter` and `SignalReverser` Augmentations
- Loading branch information
Showing
3 changed files
with
1,419 additions
and
1,102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import torch | ||
|
||
|
||
class SignalInverter(torch.nn.Module): | ||
""" | ||
Takes a tensor of timeseries of arbitrary dimension | ||
and randomly inverts (i.e. h(t) -> -h(t)) | ||
each timeseries with probability `prob`. | ||
Args: | ||
prob: | ||
Probability that a timeseries is inverted | ||
""" | ||
|
||
def __init__(self, prob: float = 0.5): | ||
super().__init__() | ||
self.prob = prob | ||
|
||
def forward(self, X): | ||
mask = torch.rand(size=X.shape[:-1]) < self.prob | ||
X[mask] *= -1 | ||
return X | ||
|
||
|
||
class SignalReverser(torch.nn.Module): | ||
""" | ||
Takes a tensor of timeseries of arbitrary dimension | ||
and randomly reverses (i.e. h(t) -> h(-t)) | ||
each timeseries with probability `prob`. | ||
Args: | ||
prob: | ||
Probability that a kernel is reversed | ||
""" | ||
|
||
def __init__(self, prob: float = 0.5): | ||
super().__init__() | ||
self.prob = prob | ||
|
||
def forward(self, X): | ||
mask = torch.rand(size=X.shape[:-1]) < self.prob | ||
X[mask] = X[mask].flip(-1) | ||
return X |
Oops, something went wrong.