Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

including handling of missing inside rqatrend_impl #51

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/rqatrend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ Compute the RQA trend metric for the non-missing time steps of xin, and save it
`thresh` specifies the epsilon threshold of the Recurrence Plot computation
"""
function rqatrend(pix_trend, pix, thresh=2)
ts = collect(skipmissing(pix))
pix_trend .= rqatrend_impl(ts; thresh)
pix_trend .= rqatrend_impl(pix; thresh)
end


Expand Down Expand Up @@ -67,8 +66,17 @@ function tau_rr(y, d; thresh=2, metric=Euclidean())
if d == 0
return 1.0
else
# `sum/n` is almost twice as fast as using `mean`
return @inbounds sum(evaluate(metric, y[i], y[i+d]) <= thresh for i in 1:length(y)-d) / (length(y)-d)
# `sum/n` is almost twice as fast as using `mean`, but sum is probably numerically less accurate
nominator = 0
denominator = 0
@inbounds for i in 1:length(y)-d
if y[i] === missing || y[i+d] === missing
continue
end
nominator += evaluate(metric, y[i], y[i+d]) <= thresh
denominator += 1
end
return nominator/denominator
end
end

Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,14 @@ Random.seed!(1234)

@test isapprox(RQADeforestation.rqatrend_impl(y; thresh=0.5), -0.11125611687816017)
@test isempty(AllocCheck.check_allocs(RQADeforestation.rqatrend_impl, Tuple{Vector{Float64}}))


y2 = similar(y, Union{Float64, Missing})
copy!(y2, y)
y2[[1,4,10,20,33,65]] .= missing


@test isapprox(RQADeforestation.rqatrend_impl(y2; thresh=0.5), -0.11069045524336744)
@test isempty(AllocCheck.check_allocs(RQADeforestation.rqatrend_impl, Tuple{Vector{Union{Float64,Missing}}}))

end
Loading