Traditional cyclical feature engineering maps periodic inputs (such as time of day, day of the week, or wind direction) to a unit circle using standard trigonometric functions:
While this preserves continuity across the boundary (
Because the derivatives are themselves sinusoidal, the speed at which coordinates change varies across the domain, accelerating near the axes and decelerating near the diagonals. This often degrades the performance of linear systems and optimization surfaces, such as those in Neural Networks.
This repository introduces L1 Cyclical Encoding, an alternative approach that maps periodic variables along a Manhattan-distance (
By executing a steady counter-clockwise walk around this diamond-shaped perimeter instead of an sin and cos), relying purely on simple arithmetic and modulo operations.
When moving at a constant speed along a circle, the absolute value rate of change for each individual feature w.r.t the input variable continually fluctuates:
This fluctuation is remedied here, making it highly suitable for linear processing and gradient-based models like Neural Networks or Linear Regression. Within any given quadrant of the perimeter, the individual feature rates of change are perfectly uniform:
* The derivative is technically undefined at the sharp corner vertices (points of non-differentiability), but this has no practical implication for feature engineering or downstream machine learning tasks.
A Python implementation & it's documentation is provided with the repository.

