'Returns the label for the given position in the event sequence.
Returns an integer in the range [0, self.num_classes). Indices in the range
[0, self._one_hot_encoding.num_classes) map to standard events. Indices
self._one_hot_encoding.num_classes and self._one_hot_encoding.num_classes +
1 are signals to repeat events from earlier in the sequence. More distant
repeats are selected first and standard events are selected last.
Assuming a one-hot encoding with 38 classes and two lookback distances,
self.num_classes = 40 and the values will be as follows.
Values [0, 39]:
[0, 37]: Event of the last step in the event sequence, if not repeating
any of the lookbacks.
38: If the last event is repeating the first lookback, if not also
repeating the second lookback.
39: If the last event is repeating the second lookback.
Args:
events: A list-like sequence of events.
position: An integer position in the event sequence.
Returns:
A label, an integer.'

def events_to_label(self, events, position):

    if (self._lookback_distances and (position < self._lookback_distances[(-1)]) and (events[position] == self._one_hot_encoding.default_event)):
        return ((self._one_hot_encoding.num_classes + len(self._lookback_distances)) - 1)
    for (i, lookback_distance) in reversed(list(enumerate(self._lookback_distances))):
        lookback_position = (position - lookback_distance)
        if ((lookback_position >= 0) and (events[position] == events[lookback_position])):
            return (self._one_hot_encoding.num_classes + i)
    return self._one_hot_encoding.encode_event(events[position])
