metrics.jl 1.34 KB
Newer Older
1
2
3
4

K0 = 1000; σ = 1e-1
agents1 = [Agent( [σ]  .* randn(1) .- .5) for i in 1:K0]
agents2 = [Agent( [σ σ]  .* randn(2) .- .5) for i in 1:K0]
5
6
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 )
7
8
## testing variance
@testset "Testing metrics" begin
9
10
11
12
    @testset "var" begin
        @test first(var(agents1))  (σ).^2 atol=0.001
        @test first(var(agents2,trait=2))  (σ).^2 atol=0.001
    end
13
14
15

    ## testing covgeo
    @testset "covgeo" begin
16
        @test covgeo(agents1)  (σ).^2 atol=0.001
17
18
19
20
21
         for i in covgeo(agents1,1)
             @test i  (σ).^2 atol=0.001
         end
     end
     # not sure this is the bestway of testing
22
     # there is a problem here
23
24
     @testset "covgeo2d" begin
         cmat = covgeo(agents2,2);
25
26
         smat = [σ^2 0; 0 σ^2]
         @test cmat  smat atol=0.01
27
      end
28
29
30
31
32
33
34
35
36
37
38
39
40
41
      @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
42
43
44
end

# TODO needs to test hamming distance