Commit b9dd0eab authored by Victor's avatar Victor
Browse files

Adding new method for get_xhist that takes as input an array world

parent 172eb449
name = "ABMEv"
uuid = "837ac870-fb52-4b0c-9a0e-030f2f36f5ed"
authors = ["Victor Boussange "]
version = "0.1.5"
version = "0.1.6"
[deps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
......
......@@ -15,7 +15,7 @@ module ABMEv
@reexport using Distributions
export update_rates!
export Agent,get_fitness,get_x,get_xarray,get_xhist,
export Agent,get_fitness,get_x,get_dim,get_nancestors,get_xarray,get_xhist,
get_geo,get_b,get_d,increment_x!,get_inc_reflected,
split_move,split_merge_move,KK,tin,new_world_G
export copy,runWorld_store_WF,runWorld_store_G #,runWorld_G!,runWorld_WF!,
......
......@@ -37,13 +37,41 @@ get_geo(a::Agent) = sum(get_xhist(a,1))
get_d(a::Agent) = a.d
get_b(a::Agent) = a.b
get_fitness(a::Agent) = a.b - a.d
get_dim(a::Agent) = size(a.x_history,1)
get_nancestors(a::Agent) = size(a.x_history,2)
"""
get_xarray(world::Array{Agent{T}},trait::Int) where T
Returns trait of every agents of world in the form of an array
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{Agent{T}},trait::Int) where T = reshape(hcat(get_x.(world,trait)),size(world,1),size(world,2))
"""
get_xhist(world::Vector{Agent{T}},geotrait = false)
Returns the trait history of every agents of world in the form of an 3 dimensional array,
with
- first dimension as the agent index
- second as time index
- third as trait index
If geotrait = true, then a last trait dimension is added, corresponding to geotrait.
Note that because number of ancestors are different between agents, we return an array which size corresponds to the minimum of agents ancestors,
and return the last generations, dropping the youngest ones
"""
function get_xhist(world::Vector{Agent{T}},geotrait = false) where T
hist = minimum(get_nancestors.(world))
ntraits = get_dim(first(worldall));
xhist = zeros(length(worldall), hist, ntraits + geotrait);
for (i,a) in enumerate(worldall)
xhist[i,:,1:end-geotrait] = get_xhist(a)[:,end-hist+1:end]';
if geotrait
xhist[i,:,ntraits+geotrait] = cumsum(get_xhist(a,1))[end-hist+1:end]
end
end
return xhist
end
"""
increment_x!(a::Agent{Float64},p::Dict)
This function increments current position by inc and updates xhist,
......
"""
generalised_gaussian(x::Float64,mu::Float64,sigma::Float64,epsilon::Float64)
"""
function generalised_gaussian(x::Float64,mu::Float64,sigma::Float64,epsilon::Float64)
return exp( -.5 * ((x-mu) / sigma)^epsilon)
end
......
Supports Markdown
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