Stream: helpdesk (published)

Topic: Agents.jl "no possible aggregation"


view this post on Zulip Lorenzo Gaifas (Jul 01 2022 at 17:50):

I have an agent based model from which I'm attempting to aggregate data. If each of my agents has an energy field, I can do this:

energy(a) = a.energy
adata = [(energy, mean)]
fig, = abmexploration(
    model;
    agent_step!,
    model_step!,
    adata,
)

and all works well. However, I would like to exclude some agents from the aggregation (it's a mixed agent model, and for some types the energy field should not even be there). To do so, I thought I could use NaN to my advantage:

energy(a) = a isa MyAgentType1 ? a.energy : NaN
nanmean(collection) = mean(filter(!isnan,  collection))
adata = [(energy, nanmean)]

However, this produces a rather cryptic error:

No possible aggregation for energy using nanmean

    multi_agent_agg_types!(::Vector{Vector}, ::Tuple{DataType, DataType}, ::Vector{String}, ::Agents.AgentBasedModel{Agents.ContinuousSpace{2, true, Float64, typeof(Agents.defvel)}, Union{Main.workspace#3.Blob, Main.workspace#3.Food}, Agents.Schedulers.Randomly, Dict{Symbol, Int64}, Random.TaskLocalRNG}, ::Vector{Tuple{typeof(Main.workspace#3.energy), typeof(Main.workspace#5.nanmean)}})@collect.jl:381
    init_agent_dataframe(::Agents.AgentBasedModel{Agents.ContinuousSpace{2, true, Float64, typeof(Agents.defvel)}, Union{Main.workspace#3.Blob, Main.workspace#3.Food}, Agents.Schedulers.Randomly, Dict{Symbol, Int64}, Random.TaskLocalRNG}, ::Vector{Tuple{typeof(Main.workspace#3.energy), typeof(Main.workspace#5.nanmean)}})@collect.jl:317
    var"#ABMObservable#27"(::Function, ::Function, ::Vector{Tuple{typeof(Main.workspace#3.energy), typeof(Main.workspace#5.nanmean)}}, ::Nothing, ::Bool, ::Type{InteractiveDynamics.ABMObservable}, ::Agents.AgentBasedModel{Agents.ContinuousSpace{2, true, Float64, typeof(Agents.defvel)}, Union{Main.workspace#3.Blob, Main.workspace#3.Food}, Agents.Schedulers.Randomly, Dict{Symbol, Int64}, Random.TaskLocalRNG})@model_observable.jl:40
    var"#abmplot!#30"(::Function, ::Function, ::Vector{Tuple{typeof(Main.workspace#3.energy), typeof(Main.workspace#5.nanmean)}}, ::Nothing, ::Bool, ::Bool, ::Bool, ::Bool, ::Base.Pairs{Symbol, typeof(Main.workspace#3.agent_color), Tuple{Symbol}, NamedTuple{(:ac,), Tuple{typeof(Main.workspace#3.agent_color)}}}, ::typeof(InteractiveDynamics.abmplot!), ::Makie.MakieLayout.Axis, ::Agents.AgentBasedModel{Agents.ContinuousSpace{2, true, Float64, typeof(Agents.defvel)}, Union{Main.workspace#3.Blob, Main.workspace#3.Food}, Agents.Schedulers.Randomly, Dict{Symbol, Int64}, Random.TaskLocalRNG})@abmplot.jl:131
    #abmplot#29@abmplot.jl:112[inlined]
    var"#abmexploration#81"(::Nothing, ::Nothing, ::NamedTuple{(), Tuple{}}, ::Base.Pairs{Symbol, Any, NTuple{4, Symbol}, NamedTuple{(:agent_step!, :model_step!, :ac, :adata), Tuple{typeof(Main.workspace#3.agent_step!), typeof(Main.workspace#3.model_step!), typeof(Main.workspace#3.agent_color), Vector{Tuple{typeof(Main.workspace#3.energy), typeof(Main.workspace#5.nanmean)}}}}}, ::typeof(InteractiveDynamics.abmexploration), ::Agents.AgentBasedModel{Agents.ContinuousSpace{2, true, Float64, typeof(Agents.defvel)}, Union{Main.workspace#3.Blob, Main.workspace#3.Food}, Agents.Schedulers.Randomly, Dict{Symbol, Int64}, Random.TaskLocalRNG})@convenience.jl:39

I didn't manage to find anything with google... and the nanmean method works as intended, if I call it myself. Suggestions?

view this post on Zulip Michael Fiano (Jul 01 2022 at 17:52):

I am clueless here but what about missing?

view this post on Zulip Lorenzo Gaifas (Jul 01 2022 at 18:00):

unfortunately no, because mean([1, missing]) is missing.


Last updated: Oct 02 2023 at 04:34 UTC