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

fixed floating point error #713

Merged
merged 5 commits into from
Nov 5, 2024
Merged
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
8 changes: 4 additions & 4 deletions src/counts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ Equivalent to `counts(x, levels) / length(x)`.
If a vector of weights `wv` is provided, the proportion of weights is computed rather
than the proportion of raw counts.
"""
proportions(x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}) = counts(x, levels) .* inv(length(x))
proportions(x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}) = counts(x, levels) / length(x)
proportions(x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}, wv::AbstractWeights) =
counts(x, levels, wv) .* inv(sum(wv))
counts(x, levels, wv) / sum(wv)

"""
proportions(x, k::Integer, [wv::AbstractWeights])
Expand Down Expand Up @@ -204,9 +204,9 @@ counts(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}) = counts(x, y,
counts(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, wv::AbstractWeights) = counts(x, y, (span(x), span(y)), wv)

proportions(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, levels::NTuple{2,UnitRange{<:Integer}}) =
counts(x, y, levels) .* inv(length(x))
counts(x, y, levels) / length(x)
proportions(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, levels::NTuple{2,UnitRange{<:Integer}}, wv::AbstractWeights) =
counts(x, y, levels, wv) .* inv(sum(wv))
counts(x, y, levels, wv) / sum(wv)

proportions(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, ks::NTuple{2,Integer}) =
proportions(x, y, (1:ks[1], 1:ks[2]))
Expand Down
Loading