I have $t_1, t_2, ..., t_N$, where each $t \in [0, 1[$ is a time during the day (i.e. 0.01 is right after midnight and 0.99 is right before midnight). I want to compute the distance between these time of day such that I can identify times that are close to each other.
The distance should wrap around midnight such that times right before midnight and right after midnight are close (constraint 1 below). The distance between two points should also be such that a time twice as far away should have twice the distance (constraint 2 below).
The tricky part is that because this time comparison will be part of an existing nearest neighbor search solution, the distance metric has to be Euclidean distance (L2).
To put it more mathematically:
- $t \in [0, 1[$
- $f(t)$ maps $t$ to a vector of dimension $f_d$
- $d(f(t_1), f(t_2))$ is the Euclidean distance between $f(t_1)$ and $f(t_2)$
These are the constraints we're trying to achieve:
- $d(f(t_1 + \Delta, 1), f(t_2 + \Delta, 1)) = c$ for all $\Delta \in [0, 1]$, where $c \in \mathbb{R}$ is a constant
- $d(f(t), f(t + k \cdot \Delta)) = k \cdot d(f(t), f(t + \Delta))$
These two constraints could probably expressed in a simpler way. If so, feel free to try to reformulate them!
Own attempt
I tried mapping the time onto the unit circle, i.e. $f(t) = (\sin(t), \cos(t))$. This fulfills constraint 1 as the Euclidean distance between two points on the unit circle is the chord length, which only depends on the angle and thereby wraps around the midnight point at 1. However, this approach doesn't fulfill constraint 2 above as a time twice as far away does not have twice the distance, e.g. $t=0.25, \Delta=0.25, k=2$ such that $d(f(0.25), f(0.75) \ne 2 \cdot d(f(0.25), f(0.5))$.
This can't be done.
First of all, you don't actually want constraint 2 as stated, because of the wraparound: you want the distance between $0$ and $3\cdot \frac25$ to equal $\frac15$, not $3\cdot\frac25=\frac65$.
But even confining to situations where you want this literal statement, one can derive a contradiction. For example, consider the images $f(0),f(\frac25),f(\frac45),f(\frac65)=f(\frac15)$:
And these three facts are incompatible with one another. (Well, if $f$ is a constant function then I guess it works, but I doubt that's what you want.)