To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit 8249cec3 authored by Victor's avatar Victor
Browse files

added a new feature to plots, and the "eth_grad" palette, plus a new funuction "world2df"

parent 07b700f3
......@@ -33,6 +33,12 @@ git-tree-sha1 = "5b08ed6036d9d3f0ee6369410b830f8873d4024c"
uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
version = "0.5.8"
[[CategoricalArrays]]
deps = ["Compat", "DataAPI", "Future", "JSON", "Missings", "Printf", "Reexport", "Statistics", "Unicode"]
git-tree-sha1 = "23d7324164c89638c18f6d7f90d972fa9c4fa9fb"
uuid = "324d7699-5711-5eae-9e2f-1d82baa6b597"
version = "0.7.7"
[[CodeTracking]]
deps = ["InteractiveUtils", "UUIDs"]
git-tree-sha1 = "0becdab7e6fbbcb7b88d8de5b72e5bb2f28239f3"
......@@ -45,6 +51,24 @@ git-tree-sha1 = "05916673a2627dd91b4969ff8ba6941bc85a960e"
uuid = "944b1d66-785c-5afd-91f1-9de20f533193"
version = "0.6.0"
[[ColorTypes]]
deps = ["FixedPointNumbers", "Random"]
git-tree-sha1 = "f746d4fc892fdf683b5c22064c8e99b2f5b990e7"
uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
version = "0.10.2"
[[Colors]]
deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Reexport"]
git-tree-sha1 = "2fdeb981ebcf52cd800ddb6a0aa5eac34153552d"
uuid = "5ae59095-9a9b-59fe-a467-6f913c188581"
version = "0.12.0"
[[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "0198d18b28c093bef39872a22f1a897218a925f5"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "3.8.0"
[[CompilerSupportLibraries_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "7c4f882c41faa72118841185afc58a2eb00ef612"
......@@ -62,12 +86,23 @@ git-tree-sha1 = "674b67f344687a88310213ddfa8a2b3c76cc4252"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
version = "1.1.0"
[[DataFrames]]
deps = ["CategoricalArrays", "Compat", "DataAPI", "Future", "InvertedIndices", "IteratorInterfaceExtensions", "Missings", "PooledArrays", "Printf", "REPL", "Reexport", "SortingAlgorithms", "Statistics", "TableTraits", "Tables", "Unicode"]
git-tree-sha1 = "7d5bf815cc0b30253e3486e8ce2b93bf9d0faff6"
uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
version = "0.20.2"
[[DataStructures]]
deps = ["InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "5a431d46abf2ef2a4d5d00bd0ae61f651cf854c8"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.17.10"
[[DataValueInterfaces]]
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464"
version = "1.0.0"
[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
......@@ -124,6 +159,15 @@ git-tree-sha1 = "3eb5253af6186eada40de3df524a1c10f0c6bfa2"
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
version = "0.8.6"
[[FixedPointNumbers]]
git-tree-sha1 = "3ba9ea634d4c8b289d590403b4a06f8e227a6238"
uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
version = "0.8.0"
[[Future]]
deps = ["Random"]
uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820"
[[Inflate]]
git-tree-sha1 = "f5fc07d4e706b84f72d54eedcc1c13d92fb0871c"
uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9"
......@@ -145,17 +189,34 @@ git-tree-sha1 = "5e9938f4dff72e5ed4c0f7fbe34b204cbabcf43a"
uuid = "d8418881-c3e1-53bb-8760-2df7ec849ed5"
version = "1.1.0"
[[InvertedIndices]]
deps = ["Test"]
git-tree-sha1 = "15732c475062348b0165684ffe28e85ea8396afc"
uuid = "41ab1584-1d38-5bbf-9106-f11c6c58b48f"
version = "1.0.0"
[[IterTools]]
git-tree-sha1 = "05110a2ab1fc5f932622ffea2a003221f4782c18"
uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
version = "1.3.0"
[[IteratorInterfaceExtensions]]
git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856"
uuid = "82899510-4779-5014-852e-03e436cf321d"
version = "1.0.0"
[[JLD2]]
deps = ["CodecZlib", "DataStructures", "FileIO", "Mmap", "Pkg", "Printf", "UUIDs"]
git-tree-sha1 = "d6cfa7c24e27d7eaa2290372739c8298257dae16"
uuid = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
version = "0.1.12"
[[JSON]]
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.21.0"
[[JuliaInterpreter]]
deps = ["CodeTracking", "InteractiveUtils", "Random", "UUIDs"]
git-tree-sha1 = "2eadbbde5534346cbb837c3a75b377cba477a06d"
......@@ -249,6 +310,12 @@ git-tree-sha1 = "2fc6f50ddd959e462f0a2dbc802ddf2a539c6e35"
uuid = "90014a1f-27ba-587c-ab20-58faa44d9150"
version = "0.9.12"
[[Parsers]]
deps = ["Dates", "Test"]
git-tree-sha1 = "75d07cb840c300084634b4991761886d0d762724"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "1.0.1"
[[Pkg]]
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
......@@ -259,6 +326,12 @@ git-tree-sha1 = "a88e0eddef9202b651f4b60b37b59ca67bb49516"
uuid = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
version = "0.7.0"
[[PooledArrays]]
deps = ["DataAPI"]
git-tree-sha1 = "b1333d4eced1826e15adbdf01a4ecaccca9d353c"
uuid = "2dfb63ee-cc39-5dd5-95bd-886bf059d720"
version = "0.5.3"
[[Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
......@@ -367,6 +440,18 @@ version = "0.9.4"
deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"]
uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
[[TableTraits]]
deps = ["IteratorInterfaceExtensions"]
git-tree-sha1 = "b1ad568ba658d8cbb3b892ed5380a6f3e781a81e"
uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c"
version = "1.0.0"
[[Tables]]
deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"]
git-tree-sha1 = "c45dcc27331febabc20d86cb3974ef095257dcf3"
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
version = "1.0.4"
[[Test]]
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
......
......@@ -4,7 +4,9 @@ authors = ["Victor Boussange "]
version = "0.1.7"
[deps]
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
......
......@@ -13,13 +13,13 @@ module ABMEv
include("ABMEv_utils.jl")
@reexport using Distributions
@reexport using Distributions, DataFrames
export update_rates!
export MixedAgent,StdAgent,Agent,get_fitness,get_x,get_dim,get_nancestors,get_xarray,get_xhist,
get_geo,get_b,get_d,increment_x!,get_inc_reflected,
get_geo,get_b,get_d,increment_x!,get_inc_reflected,world2df
split_move,split_merge_move,KK,tin,new_world_G
export copy,runWorld_store_WF,runWorld_store_G #,runWorld_G!,runWorld_WF!,
export H_discrete,findclusters,var,covgeo,hamming
export update_afterbirth_std!,update_afterdeath_std!
export generalised_gaussian,gaussian,ma
export generalised_gaussian,gaussian,ma,eth_grad_std
end
......@@ -48,12 +48,25 @@ get_dim(a::Agent) = size(a.x_history,1)
get_nancestors(a::Agent) = size(a.x_history,2)
"""
get_xarray(world::Array{Agent},trait::Int)
Mainly works for WF-type world
Returns trait of every agents of world in the form of an array which dimensions corresponds to the input.
Particularly suited for an array world corresponding to a timeseries.
"""
get_xarray(world::Array{T},trait::Int) where {T <: Agent}= reshape(hcat(get_x.(world,trait)),size(world,1),size(world,2))
"""
get_xarray(world::Array{Agent,1})
Returns every traits of every agents of world in the form of an array
If geotrait = true, then a last trait dimension is added, corresponding to geotrait.
"""
function get_xarray(world::Array{T,1},geotrait=false) where {T <: Agent}
xarray = hcat(get_x.(world)...)
if geotrait
xarray = vcat( xarray, get_geo.(world)')
end
end
"""
get_xhist(world::Vector{Agent},geotrait = false)
Returns the trait history of every agents of world in the form of an 3 dimensional array,
......@@ -179,3 +192,21 @@ end
function split_merge_move(t)
return .0 + 1/30*(t-10.)*tin(t,10.,40.) + tin(t,40.,70.) + (1- 1/30*(t-70.))*tin(t,70.,100.)
end
"""
world2df(world::Array{T,1}; geotrait = false) where {T <: Agent}
Converts the array of agent world to a datafram, where each column corresponds to a trait of the
agent, and an extra column captures fitness.
Each row corresponds to an agent
"""
function world2df(world::Array{T,1}; geotrait = false) where {T <: Agent}
xx = get_xarray(world)
dfw = DataFrame(:f => get_fitness.(world))
for i in 1:size(xx,1)
dfw[Meta.parse("x$i")] = xx[i,:]
end
if geotrait
dfw[:geo] = get_geo.(world)
end
return dfw
end
using RecipesBase
# function designed for Wright Fisher process
using Colors
import KernelDensity:kde,pdf
@recipe function plot(world::Array{U},p;what=["x","H"],trait = 1) where U <: Union{Missing,Agent}
tot_dim = size(world,2)*size(world,1)
# We reduce time interval if it is too big
if size(world,2)*size(world,1) > 1e6 && size(world,2) >= 200
if tot_dim > 1e6 && size(world,2) >= 200
p = copy(p)
idx_reduced = floor.(Int,range(1,size(world,2),length = 200))
p["tspan" ] = p["tspan"][idx_reduced]
......@@ -14,24 +16,31 @@ using RecipesBase
tspan_ar = repeat(p["tspan"],inner = size(world,1))
end
# tspan = Float64.(tspan)
world = collect(skipmissing(world))
world_sm = collect(skipmissing(world))
if "x" in what
d_i = []
for i in 1:size(world,2)
x = get_x.(skipmissing(world[:,i]),trait)
append!(d_i,pdf(kde(x),x))
end
@series begin
xarray = get_xarray(world,trait)
xarray = get_xarray(world_sm,trait)
seriestype := :scatter
markercolor := "blue"
markercolor := eth_grad_small[d_i ./ maximum(d_i)]
# markercolor := :blue
markerstrokewidth := 0
alpha :=.1
alpha :=1.
xlabel := "time"
ylabel := "trait value"
label := ""
# markersize := 2.3/1000*size(world,1)
grid := false
# markersize := 2.3/1000*size(world_sm,1)
tspan_ar[:],xarray[:]
end
end
if "geo" in what
@series begin
xarray = get_geo.(world)
xarray = get_geo.(world_sm)
seriestype := :scatter
markercolor := "blue"
markerstrokewidth := 0
......@@ -39,14 +48,14 @@ using RecipesBase
xlabel := "time"
ylabel := "trait value"
label := ""
# markersize := 2.3/1000*size(world,1)
# markersize := 2.3/1000*size(world_sm,1)
tspan_ar[:],xarray[:]
end
end
if "3dgeo" in what
@series begin
xarray = get_geo.(world)
yarray = get_xarray(world,2)
xarray = get_geo.(world_sm)
yarray = get_xarray(world_sm,2)
seriestype := :scatter3d
markercolor := "blue"
markerstrokewidth := 0
......@@ -55,14 +64,14 @@ using RecipesBase
ylabel := "geotrait"
zlabel := "trait value"
label := ""
# markersize := 2.3/1000*size(world,1)
# markersize := 2.3/1000*size(world_sm,1)
tspan_ar,xarray[:],yarray[:]
end
end
if "3d" in what
@series begin
xarray = get_xarray(world,1)
yarray = get_xarray(world,2)
xarray = get_xarray(world_sm,1)
yarray = get_xarray(world_sm,2)
seriestype := :scatter3d
markercolor := "blue"
markerstrokewidth := 0
......@@ -71,13 +80,13 @@ using RecipesBase
ylabel := "position"
zlabel := "trait value"
label := ""
# markersize := 2.3/1000*size(world,1)
# markersize := 2.3/1000*size(world_sm,1)
tspan_ar,xarray[:],yarray[:]
end
end
# if "H" in what
# @series begin
# x = get_x.(world,trait)
# x = get_x.(world_sm,trait)
# linewidth := 2
# seriestype := :line
# label := "Interconnectedness"
......@@ -91,7 +100,7 @@ using RecipesBase
label := "Variance"
xlabel := "Time"
ylabel := "Variance"
p["tspan"],var(world,trait=trait)[:]
p["tspan"],var(world_sm,trait=trait)[:]
end
end
if "vargeo" in what
......@@ -101,7 +110,7 @@ using RecipesBase
label := "Variance of geotrait"
xlabel := "Time"
ylabel := "Variance"
p["tspan"],i->first(covgeo(world[:,Int(i)]))
p["tspan"],i->first(covgeo(world_sm[:,Int(i)]))
end
end
# if "density_t" in what
......@@ -111,7 +120,7 @@ using RecipesBase
# label := "Variance of geotrait"
# xlabel := "Time"
# ylabel := "Variance"
# p["tspan"],i->first(covgeo(world[:,Int(i)]))
# p["tspan"],i->first(covgeo(world_sm[:,Int(i)]))
# end
# end
end
......@@ -20,3 +20,7 @@ function ma(x::Array{T},f) where T <: Number
_s = Int((f-1)/2)
return conv(x,ones(f)./f)[_s:_s+_N-1]
end
import Plots:cgrad
const eth_grad_small = cgrad([colorant"#1F407A", RGB(0.671,0.851,0.914),RGB(1.0,1.0,0.749), RGB(0.992,0.682,0.38),RGB(0.647,0.0,0.149),],[.0,.1])
const eth_grad_std = cgrad([colorant"#1F407A", RGB(0.671,0.851,0.914),RGB(1.0,1.0,0.749), RGB(0.992,0.682,0.38),RGB(0.647,0.0,0.149),],[.0,1.])
Markdown is supported
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