Commit 0ffefc30 authored by Victor's avatar Victor
Browse files

adding alpha_div, beta_div

parent 6f5317b6
......@@ -19,7 +19,7 @@ module ABMEv
get_geo,get_b,get_d,increment_x!,get_inc_reflected,world2df,
split_move,split_merge_move,tin,new_world_G
export copy,runWorld_store_WF,runWorld_store_G,clean_world #,runWorld_G!,runWorld_WF!,
export H_discrete,findclusters,var,covgeo,hamming
export H_discrete,findclusters,var,covgeo,hamming,get_beta_div, get_alpha_div
export update_afterbirth_std!,update_afterdeath_std!
export generalised_gaussian,gaussian,ma,eth_grad_std
end
......@@ -91,23 +91,32 @@ function hamming(world::Array{Agent,1}) where T <: Int
return H
end
"""
get_alpha_div(world::Array{U,1};trait=1) where U <: Union{Missing,Agent{T}} where T
get_alpha_div(world::Array{U,1},trait=1) where U <: Union{Missing,Agent}
Mean of the local variance of `trait` per patch
# Arguments
"""
function get_alpha_div(world::Array{U,1};trait=1) where U <: Union{Missing,Agent{T}} where T
_xall_df = world2df(world,geotrait=true)
function get_alpha_div(world::Array{U,1},trait=1) where U <: Union{Missing,Agent}
_xall_df = world2df(world,true)
xall_per_patch = groupby(_xall_df, :x1,sort=true)
#TODO: to be continued
if trait == 0
return mean([var(xp.g) for xp in xall_per_patch])
else
return mean([var(xp[:,trait+1]) for xp in xall_per_patch])
end
end
"""
get_beta_div(world::Array{U,1};trait=1) where U <: Union{Missing,Agent{T}} where T
get_beta_div(world::Array{U,1},trait=1) where U <: Union{Missing,Agent}
Variance of the mean of `trait` per patch
# Arguments
"""
function get_beta_div(world::Array{U,1};trait=1) where U <: Union{Missing,Agent{T}} where T
_xall_df = world2df(world,geotrait=true)
function get_beta_div(world::Array{U,1},trait=1) where U <: Union{Missing,Agent}
_xall_df = world2df(world,true)
xall_per_patch = groupby(_xall_df, :x1,sort=true)
sbar_i = [mean(xp.x2) for xp in xall_per_patch]
#TODO: to be continued
if trait == 0
sbar_i = [mean(xp.g) for xp in xall_per_patch]
else
sbar_i = [mean(xp[:,trait+1]) for xp in xall_per_patch]
end
return var(sbar_i)
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment