TensorTonic
Problems
Cyclic Encoding
Feature Engineering
Easy

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:

θ=2πvP\theta = \frac{2\pi v}{P}θ=P2πv​

Then compute its two coordinates:

encoded⁡(v)=[sin⁡(θ),cos⁡(θ)]\operatorname{encoded}(v) = [\sin(\theta), \cos(\theta)]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.

Loading visualization...

Examples

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]]

Hint 1

Use 2 * math.pi * value / period for the angle.

Hint 2

Append math.sin(angle) and math.cos(angle) as a two-item list.

Requirements

  • Convert every value to an angle using the supplied period.
  • Return sine first and cosine second for each angle.
  • Preserve the original value order.

Constraints

  • period is positive.
  • values contains nonnegative numbers.
  • Time limit: 300 ms.
Try Similar Problems
Interaction FeaturesEasyFrequency EncodingEasyOrdinal EncodingEasyPolynomial FeaturesEasyTarget EncodingEasyLag FeaturesEasyRank TransformEasyBag-of-Words VectorEasyMissing Value ImputationEasyAngle FeaturesEasyBag of WordsEasyFeature ScalingEasy
Scratchpad

Accepts: array

Accepts: number

You must run your code first.
Cyclic Encoding

Cyclic Encoding

Feature Engineering
Easy

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:

θ=2πvP\theta = \frac{2\pi v}{P}θ=P2πv​

Then compute its two coordinates:

encoded⁡(v)=[sin⁡(θ),cos⁡(θ)]\operatorname{encoded}(v) = [\sin(\theta), \cos(\theta)]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.

Loading visualization...

Examples

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]]

Hint 1

Use 2 * math.pi * value / period for the angle.

Hint 2

Append math.sin(angle) and math.cos(angle) as a two-item list.

Requirements

  • Convert every value to an angle using the supplied period.
  • Return sine first and cosine second for each angle.
  • Preserve the original value order.

Constraints

  • period is positive.
  • values contains nonnegative numbers.
  • Time limit: 300 ms.
Try Similar Problems
Interaction FeaturesEasyFrequency EncodingEasyOrdinal EncodingEasyPolynomial FeaturesEasyTarget EncodingEasyLag FeaturesEasyRank TransformEasyBag-of-Words VectorEasyMissing Value ImputationEasyAngle FeaturesEasyBag of WordsEasyFeature ScalingEasy
Scratchpad

Accepts: array

Accepts: number

You must run your code first.
Problems
Loading...
1 / 1