An encoder that ends in global pooling discards when a thermal event happened, so the position of a bin in the year has to be given to it as input if it is to be used at all. These channels carry that position as the sine and cosine of the bin's fractional place in the year, which is continuous across the turn of the year where the fraction itself is not. On a record read finer than a day, the same pair for the place in the day carries where a reading sits in the daily cycle.
Arguments
- x
A
grain_matrix()result. Alookback_matrix()result has no place in the calendar and is refused.- cycles
Which cycles to place each bin in,
"year","day"or both, in the order given. The day cycle reads bins that sit less than a day apart; at a day or coarser every bin would sit at the same place in the day, and it is refused.
Value
An array of the same units and bins with two channels per cycle, year_sin and
year_cos, day_sin and day_cos, identical across units. Combine it with the readings
using bind_channels(). The channels are recorded as positions in the position attribute,
and the encoders of torch_learners read them at their own amplitude rather than
standardise them.
Details
They are the time index of each bin, not a summary of the readings, so adding them introduces no hand-built thermal feature: whatever a model does with them it could have done with a calendar.
The position is read at the midpoint of the record each bin holds, in UTC, so a bin the record
only partly covers sits at the phase it was actually measured over. A site's longitude and a
zone's offset move the day's phase by the same amount for every bin, which a model absorbs, where
a local clock's summer time would move it twice a year. inst/spec/representation.md is the
normative description.
Examples
t <- seq(as.POSIXct("2021-09-01", tz = "UTC"), by = "hour", length.out = 24 * 400)
d <- data.frame(plot = "a", t = t, temp = sin(seq_along(t) / 500))
x <- grain_matrix(d, plot, t, temp, grain = "month")
round(calendar_channels(x)[1, 1:4, ], 3)
hourly <- grain_matrix(d, plot, t, temp, grain = "native")
round(calendar_channels(hourly, cycles = c("year", "day"))[1, 1:4, ], 3)