Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-260

Time Encoding Features

Problem

Encode a timestamp with a single seasonal cycle: [sin(2*pi*t/max_period), cos(2*pi*t/max_period)].

Return an empty list when max_period is not positive. The pair places each timestamp on a circle so the encoding wraps smoothly.

Hint

Sinusoidal encodings avoid the discontinuity of raw hour or month numbers.

Test cases

case 1
in: [0,24]
expected: [0,1]
case 2
in: [6,24]
expected: [1,6.123233995736766e-17]
case 3
in: [12,24]
expected: [1.2246467991473532e-16,-1]
case 4
in: [5,0]
expected: []
Starter codePython
import math
def time_encoding_features(t, max_period):
    # Your code here
    pass

4 test cases · run your code against them in the editor