We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
Data Augmentation
Apply one specified transformation to a one-dimensional signal. These operations are deterministic: the caller chooses the transform and supplies all parameters, including any noise values. Do not sample random numbers.
Your task
Implement augment(signal, transform, params). signal is a floating-point
tensor of shape (L,), with L >= 1. transform is one of the four strings
below, and params contains the matching parameters.
| Transform | Parameters | Operation |
|---|---|---|
"flip" |
{} |
Reverse the order of signal elements. |
"scale" |
{"factor": float} |
Multiply every element by the supplied factor. |
"shift" |
{"amount": int} |
Move elements by that many positions, wrapping at the ends. |
"noise" |
{"noise": tensor} |
Add the supplied (L,) noise tensor elementwise. |
Return a tensor of shape (L,). Apply only the selected operation, preserving
the signal and any supplied noise tensor. Do not clip, normalize or pad the
result. Scale factors may be zero or negative.
Circular shifts
A positive amount shifts right; a negative amount shifts left. Elements that move past an end wrap around instead of being discarded or replaced with zeros.
For signal [1, 2, 3, 4]:
amount = 1gives[4, 1, 2, 3].amount = -1gives[2, 3, 4, 1].amount = 5gives the same result asamount = 1.amount = 0or a multiple of4leaves the values unchanged.
Other examples
Flipping [1, -2, 3] gives [3, -2, 1]. It reverses positions, not signs.
Scaling that signal by -2 gives [-2, 4, -6]. Adding noise
[0.5, 0, -0.5] gives [1.5, -2, 2.5].
In a training pipeline, whether a transform is appropriate depends on the data and target: reversing or rescaling a signal does not always preserve its meaning. This exercise checks the specified operations, not that choice of augmentation.
Understand the ideas behind this exercise. The Problem tab contains the exact implementation requirements.
Transform an example while keeping its target valid
Data augmentation gives a model varied versions of its training examples. The transformation must preserve the target or transform it consistently. Flipping an image horizontally may preserve its object category, but can change a left-versus- right direction label.
For a one-dimensional signal:
- Reversal changes the order of values.
- Scaling changes their amplitudes.
- A circular shift moves values and wraps them around the ends.
- Additive noise perturbs the values.
A circular right shift of one turns [1, 2, 3, 4] into [4, 1, 2, 3]. It does
not insert zero padding.
Apply the supplied transformations in the specified order
If the exercise supplies a noise tensor, use that tensor instead of drawing
additional noise. Follow the specified scale, shift direction, and axes.
Transformation order matters: scaling after adding noise scales the noise too.
For input 2, noise 1, and scale 3, (2 + 1) * 3 = 9, while
2 * 3 + 1 = 7.
Check parameter broadcasting and output shape. Large circular shifts can be reduced modulo the signal length, but an empty signal needs a separate rule.
In a training pipeline, choose augmentations that reflect valid variations for the task. Use a consistent evaluation procedure so changes in validation scores can be compared meaningfully.
Your code, saved here
Sign in to access your accepted solutions and saved draft history. You can keep reading the lesson without an account.
Sign in to your accountStuck?
PyTorch reference solution
Sign in to track your attempts toward unlocking the reference solution.