Skip to content
Medium End-to-End

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 = 1 gives [4, 1, 2, 3].
  • amount = -1 gives [2, 3, 4, 1].
  • amount = 5 gives the same result as amount = 1.
  • amount = 0 or a multiple of 4 leaves 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.