Compute global attention weights and context vectors for time series

computeattention(series)

Arguments

series

Numeric vector containing the time series of length n

Value

List containing:

attention_weights

n × n matrix where entry (i,j) represents the attention weight of time j on time i. Only entries j <= i are non-zero (causal attention).

context_vectors

Vector of length n where each entry i is the weighted sum of all values up to time i, using the attention weights.

Examples

# For a series of length 5
series <- c(1, 2, 3, 4, 5)
result <- computeattention(series)

# attention_weights will be 5x5 matrix
# context_vectors will be length 5
dim(result$attention_weights)  # [1] 5 5
#> [1] 5 5
length(result$context_vectors) # [1] 5
#> [1] 5