Created
February 13, 2022 14:41
-
-
Save JosepER/b55aba260930f64f068a6d8386b9d0c2 to your computer and use it in GitHub Desktop.
Weighted Atkinson optimized
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### Atkinson index ##### | |
""" | |
wtd_atkinson(v, w, ϵ) | |
Computes the weighted Atkinson index given an inequality adversion parameter ϵ. | |
""" | |
function wtd_atkinson(v::Array{<:Real,1}, w::Array{<:Real,1}, ϵ::Real)::Float64 | |
norm_mean!(v) | |
w = w/sum(w) | |
if ϵ == 1 | |
w = w[v .!= 0] | |
v = v[v .!= 0] | |
return wtd_atk_eps_1_fast(v, w) | |
elseif ϵ < 1 | |
return wtd_atk_eps_diff_1_fast(v, w, ϵ) | |
else | |
w = w[v .!= 0] | |
v = v[v .!= 0] | |
return wtd_atk_eps_diff_1_fast(v, w, ϵ) | |
end | |
end | |
@inline wtd_atk_eps_1_fast(v, w)::Float64 = @fastmath 1 - (prod(exp.(w.*log.(v)))/sum(v .* w/sum(w)) ) | |
@inline wtd_atk_eps_diff_1_fast(v, w, ϵ)::Float64 = @fastmath 1-(sum(((v/sum(v.*w/sum(w))).^(1-ϵ)).*w/sum(w))).^(1/(1-ϵ)) | |
@inline function norm_mean!(x::Array{<:Real,1})::Vector{Float64} | |
x = convert(Vector{Float64}, x) | |
μx = Statistics.mean(x) | |
for i in 1:length(x) | |
x[i] = x[i]/μx | |
end | |
x | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment