JeffreySarnoff / RollingFunctions.jl

Roll a window over data; apply a function over the window.
MIT License
114 stars 6 forks source link

Version 0.8 broke runcov() #49

Open minhuangr opened 9 months ago

minhuangr commented 9 months ago

I just upgraded RollingFunctions.jl to 0.8.0 but found runcov() was broken. I have to downgrade to 0.7.0. Is it possibly due to the new padding feature?

runcov(rand(100),rand(100),10)

ERROR: MethodError: no method matching running(::typeof(Statistics.cov), ::Vector{Float64}, ::Vector{Float64}, ::Int64, ::Int64)

I just input one Int64 but the error message suggests two.

J-Sarnoff commented 9 months ago

thank you -- this release was in response to another request, and an earlier update that never was tagged. Clearly something is amiss -- looking into it.

J-Sarnoff commented 9 months ago

for the moment -- you can do this with v0.8

using StatsBase
datalen = 12;
data1 = randn(datalen);
data2 = sort(data1);
window_width = datalen - 2;

cov_1to7 = cov(data1[1:7], data2[1:7]);
cov_1to8 = cov(data1[1:8], data2[1:8]);
cov_1to9 = cov(data1[1:9], data2[1:9]);
cov_789 = [cov_1to7, cov_1to8, cov_1to9];

cov_result = running(cov, data1, data2, window_width);
isapprox(cov_789, cov_result[7:9]) # true, they are == in my test
# re padding

julia> running(cov, data1, data2, window_width)[1:4]
4-element Vector{Float64}:
 NaN
  -0.010042855884454055
  -0.16906938390288762
  -0.23392207942162288

julia> running(cov, data1, data2, window_width; padding=[0.0])[1:4]
4-element Vector{Float64}:
  0.0
 -0.010042855884454055
 -0.16906938390288762
 -0.23392207942162288

running(cov, data1, data2, window_width)

minhuangr commented 9 months ago

yep, I read the notes for this 1.0 version. Maybe I should post on the main branch.

J-Sarnoff commented 9 months ago

well there is no 1.0 version before there is a 1.0 version -- the branches are playthings the actual to-be 1.0 version is in a different repository .. this 1.0 branch is just as notes now