Commit cb0a09c7 by Victor

### updating metrics functions

parent 9eee1983
Pipeline #74679 passed with stage
in 21 minutes and 23 seconds
 ... ... @@ -41,7 +41,7 @@ function findclusters(v::Vector,allextrema =true) return collect(h.edges...)[idx .+ 1] .+ s/2, x[idx .+ 1] end import Statistics.var import Statistics:var,mean # TODO: rename this to gamma diversity """ var(world::Array{Agent};trait=:) ... ... @@ -55,6 +55,15 @@ function var(world::World;trait=1) xarray = Float64.(get_x(world,trait)) return var(xarray,dims=1,corrected=false) end """ function mean(world::World;trait=1) """ function mean(world::World;trait=1) xarray = Float64.(get_x(world,trait)) return mean(xarray,dims=1) end """ covgeo(world::Array{Agent,1},trait = 0) If trait = 0, returns the variance of the geotrait, ... ... @@ -99,7 +108,9 @@ function get_alpha_div(world::World,trait=1) return mean([var(Float64.(get_geo(World(subw,space(world),parameters(world)))),corrected=false) for subw in values(g)]) else # here the second mean is here when subspace is multidimensional return mean([mean(var(Float64.(get_x(World(subw,space(world),parameters(world)),trait)),corrected=false)) for subw in values(g)]) v = [var(World(subw,space(world),parameters(world)),trait=trait) for subw in values(g)] h = vcat(v...) return mean(h) end end ... ... @@ -114,9 +125,10 @@ function get_beta_div(world::World,trait=1) # need to convert to Float64, otherwise infinite variance sbar_i = [mean(Float64.(get_geo(World(subw,space(world),parameters(world))))) for subw in values(g)] else sbar_i = [mean(Float64.(get_x(World(subw,space(world),parameters(world)),trait))) for subw in values(g)] m = [mean(World(subw,space(world),parameters(world)),trait=trait) for subw in values(g)] h=vcat(m...) end return var(sbar_i,corrected=false) return mean(var(h,dims=1,corrected=false)) end """ ... ...
 ... ... @@ -65,10 +65,10 @@ end # TODO needs to test hamming distance # testing for real space of dimension d>1 ## testing for real space of dimension d>1 multispace = (DiscreteSegment{Int8}(1,9),RealSpace{3,Float64}(),) K0 = 10000; multia = [Agent(multispace, (rand(Int8(1):Int8(10)),tuple(randn(3)...),),ancestors=true) for i in 1:K0] multia = [Agent(multispace, (rand(Int8(1):Int8(10)),tuple( randn(3) ...),),ancestors=true) for i in 1:K0] D = (Int8(1),tuple(fill(1.,3)...),) mu = [1] NMax = 1000 ... ... @@ -78,5 +78,25 @@ a = multia[10] inc = get_inc(1,D[1],multispace[2]) @test inc[1] != inc[2] # checking that we have independent increments in each direction @test isapprox(mean(var(multiw,trait = 2)),1.,atol=1e-2) @test prod([isapprox(i,0.,atol=1e-1) for i in mean(multiw,trait = 2)]) @test isapprox(get_alpha_div(multiw,2),1.,atol = 1e-2) @test isapprox(get_beta_div(multiw,2),0.,atol = 1e-2) ## some test to write metrics functions # world = multiw;trait=2 # g = groupby(a->a[1],agents(world)) # v = [var(World(subw,space(world),parameters(world)),trait=trait) for subw in values(g)] # h = vcat(v...) # mean(mean(h,dims=1)) # mean(h) # mean([mean(var(Float64.(get_x(World(subw,space(world),parameters(world)),trait)),corrected=false)) for subw in values(g)]) # # [var(Float64.(get_x(World(subw,space(world),parameters(world)),trait)),corrected=false) for subw in values(g)] # subw = collect(values(g))[1] # var(Float64.(get_x(World(subw,space(world),parameters(world)),trait)),corrected=false) # var(World(subw,space(world),parameters(world)),trait=trait) # mean(World(subw,space(world),parameters(world)),trait=1) # # m = [mean(World(subw,space(world),parameters(world)),trait=trait) for subw in values(g)] # h=vcat(m...) # var(h,dims=1,corrected=false)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!