- Notifications
You must be signed in to change notification settings - Fork8
Roll a window over data; apply a function over the window.
License
JeffreySarnoff/RollingFunctions.jl
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
For now, rather than use e.grunmean
,runcov
, with version 0.8 userunning(cov, ..)
here is an example
- data that is a simple vector
- data that is a CartesianIndexed vector
- weights given as a simple vector
- weights given as a kind of StatsBase.AbstractWeights
- applied over unweighted or weighted data
- same 1-arg function applied to each column
- with a simple vector
- with a DataFrame column
- with a TimeSeries column
- with your own function
Withndata = length(data)
, using a window of lengthwindowsize
, rolling a function results in a vector ofndata - windowsize + 1
elements. So there will be obtainedwindowsize - 1
fewer values than there are data values. All exported functions named with the prefixroll
behave this wayunless the keywordpadding
is given with the value to use for padding (e.g.missing
). Usingpadding
will fill the initialwindowsize - 1
values with that padding value; the result will match the length of the data.
julia> data=collect(1.0f0:5.0f0);print(data)Float32[1.0,2.0,3.0,4.0,5.0]julia> windowsize=3;julia> result=rollmean(data, windowsize);print(result)Float32[2.0,3.0,4.0]julia> result=rollmean(data, windowsize; padding=missing);print(result)Union{Missing, Float32}[missing,missing,2.0,3.0,4.0]
julia> weights=normalize([1.0f0,2.0f0,4.0f0])3-element Array{Float32,1}:0.218217880.436435760.8728715 julia> result=rollmean(data, windowsize, weights);print(result)Float32[1.23657,1.74574,2.25492]julia> result=rollmean(data, windowsize, weights; padding=missing);print(result)Union{Missing,Float32}[missing,missing,1.23657,1.74574,2.25492]
To obtain the same number of output data values as are given, the initialwindowsize - 1
values output must be generated outside of the rolling behavior. This is accomplished by tapering the needed values -- using the same function, rolling it over successively smaller window sizes. All exported functions named with the prefixrun
behave this way.
julia>using RollingFunctionsjulia> data=collect(1.0f0:5.0f0);print(data)Float32[1.0,2.0,3.0,4.0,5.0]julia> windowsize=3;julia> result=runmean(data, windowsize);print(result)Float32[1.0,1.5,2.0,3.0,4.0]
julia>using RollingFunctionsjulia>using LinearAlgebra: normalizejulia> weights=normalize([1.0f0,2.0f0,4.0f0]); julia> result=runmean(data, windowsize, weights);print(result)Float32[1.0,1.11803,1.23657,1.74574,2.25492]
rollmin
,rollmax
,rollmean
,rollmedian
rollvar
,rollstd
,rollsem
,rollmad
,rollmad_normalized
rollskewness
,rollkurtosis
,rollvariation
rollcor
,rollcov
(over two data vectors)
runmin
,runmax
,runmean
,runmedian
runvar
,runstd
,runsem
,runmad
,runmad_normalized
runskewness
,runkurtosis
,runvariation
runcor
,runcov
(over two data vectors)
Some of these use a limit value for running over vec of length 1.
rolling(function, data1, data2, windowsize)
rolling(function, data1, data2, windowsize, weights)
(weights apply to both data vectors)rolling(function, data1, data2, windowsize, weights1, weights2)
rolling(function, data1, data2, data3, windowsize)
rolling(function, data1, data2, data3, windowsize, weights)
(weights apply to all data vectors)rolling(function, data1, data2, data3, windowsize, weights1, weights2, weights3)
running(function, data1, data2, data3, data4, windowsize)
running(function, data1, data2, data3, data4, windowsize, weights)
(weights apply to all data vectors)running(function, data1, data2, data3, data4, windowsize, weights1, weights2, weights3, weights4)
!! CHANGE ME !!Many statistical functions of two or more vector variables are not well defined for vectors of length 1.To run these functions and get an initial tapered value that is well defined, supply the desired value asfirstresult
.
running(function, data1, data2, windowsize, firstresult)
running(function, data1, data2, windowsize, weights, firstresult)
(weights apply to both data vectors)
This package provides a way for rolling and for running a functional window over data. Data is conveyed either as a vector or as a means of obtaining a vector from a matrix or 3D array or other data structure (e.g. dataframes, timeseries). Windows move over the data. One may use unweighted windows or windows wherein each position carries weight. Weighted windows apply the weight sequence through the window as it moves over the data.
When a window is provided with weights, the weightsshould must be normalized. We provide an algorithmically safe normalizing function that you may rely upon. Adding the sequence of normalized values one to the next obtains 1.0 or a value very slightly less than 1.0 -- their sum will not exceed unity.I do not know how to augment something already whole while respecting its integrity.
When running with a weighted window, the initial (first, second ..) values are determined using a tapering of the weighted window's span. This requires that the weights themselves be tapered along with the determinative function that is rolled. In this case, the weight subsequence is normalized (sums to one(T)), and that reweighting is used with the foreshortened window to taper that which rolls.
This software exists to simpilfy some of what you create and to faciliate some of the work you do.
Some who use it insightfully share the best of that. Others write words that smile.
All of this is expressed through the design of RollingFunctions.
- The mapwindow function fromImageFilteringsupports multidimensional window indexing and different maps.
About
Roll a window over data; apply a function over the window.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.