- You have a data sequence ๐ท๐๐ก๐, the Vector[1, 2, 3, 4, 5].
- The window span ๐๐๐๐ of each subsequence is 3.
- The function ๐น๐ข๐๐ to be applied over subsequences of ๐ท๐๐ก๐ is sum.
using RollingFunctions
๐ท๐๐ก๐ = [1, 2, 3, 4, 5]
๐น๐ข๐๐ = sum
๐๐๐๐ = 3
rolled = rolling(๐น๐ข๐๐,๐ท๐๐ก๐, ๐๐๐๐)
julia> rolled
3-element Vector{Int64}:
6
9
12
#=
The first windowed value is the ๐น๐ข๐๐ (sum) of the first ๐๐๐๐ (3) values in ๐ท๐๐ก๐.
The second windowed value is the ๐น๐ข๐๐ (sum) of the second ๐๐๐๐ (3) values in ๐ท๐๐ก๐.
The third windowed value is the ๐น๐ข๐๐ (sum) of the third ๐๐๐๐ (3) values in ๐ท๐๐ก๐.
There can be no fourth value as the third value used the fins entries in๐ท๐๐ก๐.
=#
julia> sum(๐ท๐๐ก๐[1:3]), sum(๐ท๐๐ก๐[2:4]), sum(๐ท๐๐ก๐[3:5])
(6, 9, 12)
If the span of each subsequence increases to 4..
๐๐๐๐ = 4
rolled = rolling(๐ท๐๐ก๐, ๐๐๐๐, ๐ฎ);
rolled
2-element Vector{Int64}:
10
14Generally, with data that has r rows using a window_span of s results in r - s + 1 rows of values.
To get back a result with the same number of rows as your data
Welcome to the wonderful world of padding
You may pad the result with the padding value of your choice
- padding is a keyword argument
- missing, 0.0 are commonly used
- almost all values are usable
- using nothing as the padding is allowed
- using the type Nothing is disallowed
using RollingFunctions
๐ท๐๐ก๐ = [1, 2, 3, 4, 5]
๐น๐ข๐๐ = sum
๐๐๐๐ = 3
rolled = rolling(๐น๐ข๐๐,๐ท๐๐ก๐, ๐๐๐๐; padding = missing);
julia> rolled
5-element Vector{Union{Missing, Int64}}:
missing
missing
missing
10
14
rolled = rolling(๐ท๐๐ก๐, ๐๐๐๐, ๐ฎ; padding = zero(eltype(๐ท๐๐ก๐));
julia> rolled
5-element Vector{Int64}:
0
0
0
10
14Give me the real values first, pad to the end.
rolled = rolling(๐น๐ข๐๐,๐ท๐๐ก๐, ๐๐๐๐; padding = zero(eltype(๐ท๐๐ก๐), padlast=true);
julia> rolled
5-element Vector{Int64}:
10
14
0
0
0technical note: this is not the same asreverse(rolling(๐ท๐๐ก๐, ๐๐๐๐, ๐ฎ; padding = zero(eltype(๐ท๐๐ก๐)).