Cyclic features wrap around, so the end of one period is adjacent to its beginning. Encode each value as a point on the unit circle.
First compute its angle:
θ=P2πvThen compute its two coordinates:
encoded(v)=[sin(θ),cos(θ)]Here, v is an input value and P is period. Return the sine and cosine pair for every value in the original order.
Input: values = [0, 6, 12, 18], period = 24
Output: [[0.0, 1.0], [1.0, 0.0], [0.0, -1.0], [-1.0, 0.0]]
Explanation: The four values are quarter-period steps and therefore occupy quarter turns on the unit circle.
Input: values = [0, 1, 2, 3], period = 4
Output: [[0.0, 1.0], [1.0, 0.0], [0.0, -1.0], [-1.0, 0.0]]
Use 2 * math.pi * value / period for the angle.
Append math.sin(angle) and math.cos(angle) as a two-item list.
Sign in to take notes on this problem
Accepts: array
Accepts: number
Cyclic features wrap around, so the end of one period is adjacent to its beginning. Encode each value as a point on the unit circle.
First compute its angle:
θ=P2πvThen compute its two coordinates:
encoded(v)=[sin(θ),cos(θ)]Here, v is an input value and P is period. Return the sine and cosine pair for every value in the original order.
Input: values = [0, 6, 12, 18], period = 24
Output: [[0.0, 1.0], [1.0, 0.0], [0.0, -1.0], [-1.0, 0.0]]
Explanation: The four values are quarter-period steps and therefore occupy quarter turns on the unit circle.
Input: values = [0, 1, 2, 3], period = 4
Output: [[0.0, 1.0], [1.0, 0.0], [0.0, -1.0], [-1.0, 0.0]]
Use 2 * math.pi * value / period for the angle.
Append math.sin(angle) and math.cos(angle) as a two-item list.
Sign in to take notes on this problem
Accepts: array
Accepts: number