Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
yha committed Jun 21, 2022
1 parent 4a4a465 commit 49c9664
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/RunningQuantiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,31 @@ function make_window(winlen::Int)
-winlen÷2:winlen÷2
end


"""
running_median(v, w, nan_mode=SkipNaNs())
Computes the running median of the vector `v` with window `w`, where `w` is an odd window length, or a range of offsets.
See [`running_quantile`](@ref) for details.
"""
function running_median(v, w, nan_mode=SkipNaNs(); buffer = default_buffer(v,0.5,w))
running_quantile(v, 0.5, w, nan_mode; buffer)
end

"""
result = running_quantile(v, p, w, nan_mode=SkipNaNs())
Computes the running `p`-th quantile of the vector `v` with window `w`, where `w` is an odd window length, or a range of offsets.
Specifically,
- if `w` is a `AbstractUnitRange`, `result[i]` is the `p`-th quantile of `v[(i .+ w) ∩ eachindex(v)]`, where `NaN`s are handled according to `nan_mode`:
- `nan_mode==SkipNaN()`: `NaN` values are ignored; quantile is computed over non-`NaN`s
- `nan_mode==PropagateNaNs()`: the result is `NaN` whenever the input window contains `NaN`
- `nan_mode==ErrOnNaN()`: an error is raise if at least one input window contains `NaN`
- if `w` is an odd integer, a centered window of length `w` is used, namely `-w÷2:w÷2`
"""
function running_quantile(v, p, w, nan_mode=SkipNaNs(); buffer = default_buffer(v,p,w))
_running_quantile(v, p, make_window(w), nan_mode; buffer)
end

function _running_quantile(v, p, r::AbstractUnitRange, nan_mode; buffer)
result = similar(v, float(eltype(v)))
# wrapping this Int in a `Ref` helps the compiler not create a `Box`
Expand Down

0 comments on commit 49c9664

Please sign in to comment.