Commit c988767d by Victor

### workaround Float64 for diversity measures

parent 0ffefc30
 ... @@ -66,9 +66,9 @@ If trait > 0, returns the covariance matrix, with first row geotrait and second ... @@ -66,9 +66,9 @@ If trait > 0, returns the covariance matrix, with first row geotrait and second """ """ function covgeo(world::Array{U,1},t::Number,trait = 0) where U <: Union{Missing,Agent} function covgeo(world::Array{U,1},t::Number,trait = 0) where U <: Union{Missing,Agent} world = collect(skipmissing(world)) world = collect(skipmissing(world)) xarray = get_geo.(world,t) xarray = Float64.(get_geo.(world,t)) if trait > 0 if trait > 0 xstd = reshape(get_x.(world,trait),size(world,1),size(world,2)) xstd = reshape(Float64.(get_x.(world,trait)),size(world,1),size(world,2)) xarray = hcat(xarray,xstd) xarray = hcat(xarray,xstd) end end return cov(xarray) return cov(xarray) ... @@ -91,32 +91,34 @@ function hamming(world::Array{Agent,1}) where T <: Int ... @@ -91,32 +91,34 @@ function hamming(world::Array{Agent,1}) where T <: Int return H return H end end """ """ get_alpha_div(world::Array{U,1},trait=1) where U <: Union{Missing,Agent} get_alpha_div(world::Array{U,1},t::Number,trait=1) where U <: Union{Missing,Agent} Mean of the local variance of `trait` per patch Mean of the local variance of `trait` per patch # Arguments # Arguments """ """ function get_alpha_div(world::Array{U,1},trait=1) where U <: Union{Missing,Agent} function get_alpha_div(world::Array{U,1},t::Number,trait=1) where U <: Union{Missing,Agent} _xall_df = world2df(world,true) _xall_df = world2df(world,t,true) xall_per_patch = groupby(_xall_df, :x1,sort=true) xall_per_patch = groupby(_xall_df, :x1,sort=true) if trait == 0 if trait == 0 return mean([var(xp.g) for xp in xall_per_patch]) # need to convert to Float64, otherwise infinite variance return mean([var(Float64.(xp.g)) for xp in xall_per_patch]) else else return mean([var(xp[:,trait+1]) for xp in xall_per_patch]) return mean([var(Float64.(xp[:,trait+1])) for xp in xall_per_patch]) end end end end """ """ get_beta_div(world::Array{U,1},trait=1) where U <: Union{Missing,Agent} get_beta_div(world::Array{U,1},t::Number,trait=1) where U <: Union{Missing,Agent} Variance of the mean of `trait` per patch Variance of the mean of `trait` per patch # Arguments # Arguments """ """ function get_beta_div(world::Array{U,1},trait=1) where U <: Union{Missing,Agent} function get_beta_div(world::Array{U,1},t::Number,trait=1) where U <: Union{Missing,Agent} _xall_df = world2df(world,true) _xall_df = world2df(world,t,true) xall_per_patch = groupby(_xall_df, :x1,sort=true) xall_per_patch = groupby(_xall_df, :x1,sort=true) if trait == 0 if trait == 0 sbar_i = [mean(xp.g) for xp in xall_per_patch] # need to convert to Float64, otherwise infinite variance sbar_i = [mean(Float64.(xp.g)) for xp in xall_per_patch] else else sbar_i = [mean(xp[:,trait+1]) for xp in xall_per_patch] sbar_i = [mean(Float64.(xp[:,trait+1])) for xp in xall_per_patch] end end return var(sbar_i) return var(sbar_i) end end
 ... @@ -24,13 +24,15 @@ It should correspond to an integer, as it indexes the column to plot ... @@ -24,13 +24,15 @@ It should correspond to an integer, as it indexes the column to plot # p["tspan" ] = p["tspan"][idx_reduced] # p["tspan" ] = p["tspan"][idx_reduced] # world = world[:,idx_reduced] # world = world[:,idx_reduced] # end # end if count(ismissing,world) > 0 # second condition is to make sure that the world corresponds to all the time steps # If not, then we can not get "x" if count(ismissing,world) > 0 && length(p["tspan"]) == size(world,2) tspan_ar = vcat([p["tspan"][i]*ones(Int(p["NMax"] - count(ismissing,world[:,i]))) for i in 1:length(p["tspan"]) ]...); tspan_ar = vcat([p["tspan"][i]*ones(Int(p["NMax"] - count(ismissing,world[:,i]))) for i in 1:length(p["tspan"]) ]...); else else tspan_ar = repeat(p["tspan"],inner = size(world,1)) tspan_ar = repeat(p["tspan"],inner = size(world,1)) end end # tspan = Float64.(tspan) # tspan = Float64.(tspan) tend = p["tspan"][tplot > 0 ? tplot : size(world,2)] tend = p["tspan"][tplot > 0 ? tplot : length(p["tspan"])] world_sm = clean_world(world) world_sm = clean_world(world) if "x" in what if "x" in what d_i = [] d_i = [] ... @@ -57,10 +59,11 @@ It should correspond to an integer, as it indexes the column to plot ... @@ -57,10 +59,11 @@ It should correspond to an integer, as it indexes the column to plot # world should be a one dimensional vector, corresponding to one time step only # world should be a one dimensional vector, corresponding to one time step only if "xs" in what if "xs" in what d_i = []; xt_array = []; x1_array = [] d_i = []; xt_array = []; x1_array = [] world_df_g = groupby(world2df(clean_world(world[:, tplot > 0 ? tplot : size(world,2) ]),tend,true),:x1) world_df_all = world2df(clean_world(world[:, tplot > 0 ? tplot : size(world,2) ]),tend,true) world_df_g = groupby(world_df_all,:x1) for world_df in world_df_g for world_df in world_df_g if trait == 0 if trait == 0 x = world_df.g x = Float64.(world_df.g) else else # fitness occupies first spot # fitness occupies first spot x = world_df[:,trait+1] ; x = world_df[:,trait+1] ; ... @@ -76,12 +79,13 @@ It should correspond to an integer, as it indexes the column to plot ... @@ -76,12 +79,13 @@ It should correspond to an integer, as it indexes the column to plot markercolor := eth_grad_small[d_i ./ maximum(d_i)] markercolor := eth_grad_small[d_i ./ maximum(d_i)] # markercolor := :blue # markercolor := :blue markerstrokewidth := 0 markerstrokewidth := 0 seriesalpha := 1. # seriesalpha := 1. xaxis := "geographical position" xaxis := "geographical position" xticks := sort!(unique(world_df_all.x1)) yaxis := "trait value" yaxis := "trait value" label := "" label := "" grid := false grid := false # markersize := 10 marker := (:rect,20,1.) x1_array[:],xt_array[:] x1_array[:],xt_array[:] end end end end ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!