Skip to content

Commit dbf2a6d

Browse files
authored
zero RQA parameters for empty histograms (#42)
1 parent 0db7b80 commit dbf2a6d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/rqa.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@ macro histogram_params(keyword, description, hist_fun)
3030
:entropy => "entropy of the $(description)s")
3131
function_bodies = Dict(
3232
:average => quote
33+
(hist==[0]) && return 0.0
3334
points = (1:length(hist)) .* hist
3435
return sum(points)/sum(hist)
3536
end,
36-
:max => quote length(hist) end,
37+
:max => quote
38+
(hist==[0]) && return 0
39+
return length(hist)
40+
end,
3741
:entropy => quote
42+
(hist==[0]) && return 0.0
3843
prob_bins = hist ./ sum(hist)
3944
prob_bins = prob_bins[findall(!iszero, prob_bins)]
4045
return -sum(prob_bins .* log.(prob_bins))
@@ -87,6 +92,7 @@ function determinism(x::ARM; kwargs...)
8792
end
8893

8994
function _determinism(diag_hist::Vector{<:Integer}, npoints)::Float64
95+
(diag_hist==[0]) && return 0.0
9096
diag_points = (1:length(diag_hist)) .* diag_hist
9197
return sum(diag_points)/npoints
9298
end

0 commit comments

Comments
 (0)