have you seen RollingFunctions.jl? Seems to be close to what you want. But it doesn’t have out-of-the-box support for loess etc. It does have a way to use a custom function, so maybe it’s easy to add on your own.
If it’s just a moving average and you want the same exact results as MATLAB then the only thing to figure out is what strategy MATLAB uses to estimate the tails (AR models, … etc.)
If you just want a smoother then they all have pros and cons, e.g. some can interpolate some cannot.
There’s no singular function (yet) that has parity with MATLAB’s smoothdata(), and I +1 for whoever would like to implement something like it!
This works for a moving average at least:
using NaNStatistics, Plots
y = randn(1000)
window_size = length(y)/100.0
z = movmean(y, window_size)
plot(y, linestyle = :dot)
plot!(z, linewidth = 2)
For a package-free moving average, see @tim.holy’s solution here, adapted as follows for m odd integer > 1:
function moving_average(A::AbstractArray, m::Int)
out = similar(A)
R = CartesianIndices(A)
Ifirst, Ilast = first(R), last(R)
I1 = m÷2 * oneunit(Ifirst)
for I in R
n, s = 0, zero(eltype(out))
for J in max(Ifirst, I-I1):min(Ilast, I+I1)
s += A[J]
n += 1
end
out[I] = s/n
end
return out
end
ImageFiltering.jl has multidmensional array smoothing. There’s also a mapwindow(f, A, window) which allows you to apply f to “windows” of A rather than the single elements that map(f, A) applies f to.
Hi,
How do you choose the optimal window size?
The package is very promising, I hope it develops quickly, I am looking forward to using it soon.
Many thanks,
Ayush