Commit fa0e6ec4 by Victor

### Adding some tests for geotrait and diversity measures

parent a5baf982
 ... ... @@ -57,7 +57,7 @@ get_nancestors(a::Agent) = size(a.x_history,2) get_x(world::Array{T},trait::Integer) where {T <: Agent} = trait > 0 ? reshape(hcat(get_x.(world,trait)),size(world,1),size(world,2)) : throw(ErrorException("Not the right method, need `t` as an argument")) """ get_x(world::Array{T},t::Number,trait::Integer) where {T <: Agent} get_x(world::Array{T},t::Number,trait::Integer) where {T <: Agent} Returns trait of every agents of world in the form of an array which dimensions corresponds to the input. If trait = 0 , we return the geotrait. ... ... @@ -149,9 +149,9 @@ end """ increment_x!(a::Agent{StdAgent,U},t::U,p::Dict) where U This function increments agent by random numbers specified in p ONLY FOR CONTINUOUS DOMAINS function increment_x!(a::Agent{StdAgent,U},t::U,p::Dict) where U This function increments agent by random numbers specified in p ONLY FOR CONTINUOUS DOMAINS """ function increment_x!(a::Agent{StdAgent,U},t,p::Dict) where U tdim = length(p["D"]) ... ...
 ... ... @@ -2,20 +2,22 @@ K0 = 1000; σ = 1e-1 agents1 = [Agent( [σ] .* randn(1) .- .5) for i in 1:K0] agents2 = [Agent( [σ σ] .* randn(2) .- .5) for i in 1:K0] agentsd = [Agent{MixedAgent}( Float16[rand(1:10), 1e-1* randn() + 5.5] ) for i in 1:K0] p = Dict("mu" => [1. 1.],"D" => [0. 0.], "nodes" =>10 ) ## testing variance @testset "Testing metrics" begin @test first(var(agents1)) ≈ (σ).^2 atol=0.001 @test first(var(agents2,trait=2)) ≈ (σ).^2 atol=0.001 @testset "var" begin @test first(var(agents1)) ≈ (σ).^2 atol=0.001 @test first(var(agents2,trait=2)) ≈ (σ).^2 atol=0.001 end ## testing covgeo @test covgeo(agents1) ≈ (σ).^2 atol=0.001 @testset "covgeo" begin @test covgeo(agents1) ≈ (σ).^2 atol=0.001 for i in covgeo(agents1,1) @test i ≈ (σ).^2 atol=0.001 end end # not sure this is the bestway of testing # there is a problem here @testset "covgeo2d" begin ... ... @@ -23,6 +25,20 @@ agents2 = [Agent( [σ σ] .* randn(2) .- .5) for i in 1:K0] smat = [σ^2 0; 0 σ^2] @test cmat ≈ smat atol=0.01 end @testset "Alpha diversity" begin α = get_alpha_div(agentsd,1.0,2); @test abs(α) < Inf end @testset "Beta diversity" begin β = get_beta_div(agentsd,1.0,2); @test abs(β) < Inf end end @testset "Geotrait computation" begin a = Agent{MixedAgent}( Float16[1, randn()] ); increment_x!(a,1.,p); @test get_geo(a,2.0) ≈ 2.0 end # TODO needs to test hamming distance
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!