Agents.jl: Discussion of naming convention for collected data

Created on 24 Apr 2020  路  11Comments  路  Source: JuliaDynamics/Agents.jl

I was wondering whether it would be possible or desired to use function_variable rather than function(variable) as the naming convention of creating variables for data collection. For example, in the sheep wolf example:

adata = [(sheep, count), (wolves, count), (grass, count)]
results, _ = run!(model, agent_step!, n_steps; adata = adata)

pyplot()
@df results plot(:step, cols(Symbol("count(sheep)")), grid=false, xlabel="Step",
    ylabel="Population", label="Sheep")

it is necessary to wrap the variables around two functions. Furthermore, indexing columns is cumbersome. As far as I can tell, its not possible to index by df.function_variable.

All 11 comments

Why not use the recommended function aggname? aggname(adata[1]) gives what you want.

Do you mean this:

@df results plot(:step, cols(aggname(:sheep, count)), grid=false, xlabel="Step",
    ylabel="Population", label="Sheep")

and

results[:,aggname(:sheep,count)]

as opposed to

@df results plot(:step, :count_sheep), grid=false, xlabel="Step",
    ylabel="Population", label="Sheep")

and

results.count_sheep

I don't know what @df does and what interference with our naming scheme it has.

If you have

using Plots
...
plot(results[!,:one], results[!, :two])

StatsPlots provides @df to enable you to extract the dataframe out of the plotting function.

using StatsPlots
...
@df results plot(:one, :two)

This macro can't handle Symbol("something") it seems. So you must wrap it in a call to cols(). Perhaps this is something to discuss upstream in StatsPlots rather than here.

Can the macro handle variables??? Because it doesn't matter what the symbol is. Can you do?

x = :one   # or x = aggname(adata[1]) doesn't matter.
y = :two 
@df results plot(x, y)

? Because _thats_ what should happen. You want to specify columns programmatically. Also, saying the words

This macro can't handle Symbol("something") it seems

clearly shows me that this issue should be open in StatsPlots.jl and not Agents.jl.

This is orthogonal with the naming scheme. If more people like the underscore we should consider using it. But we shouldn't consider any change because some other package is not good enough.

It can handle x = :one, not x = aggname(adata[1]). This is an upstream issue then.

Besides, you can always rename! as you wish. I still like the syntax sum(mood) or mean(attribute) much more, but maybe we can have a poll in the channel #agents3.

I agree that the issue about cols is orthogonal, yet it is a side effect. The more fundamental issue is whether the benefit of using function(variable) justifies the inconvenience and verbosity of calling Symbol("function(variable)") in order to access the column. I am amenable to a poll, but in my experience democracy can produce strange results =)

justifies the inconvenience and verbosity of calling Symbol("function(variable)") in order to access the column

This is exactly the reason I wrote aggname, so that this inconvenience doesn't exist :)

What _could_ happen, is that it may lead to other similar issues later down the line, because some other package doesn't handle symbols properly, etc... So maybe this by itself is a reason to change it.

Yeah. I didn't even consider that it could interfere with other packages. Aside from that and the issue of verbosity, an additional advantage of switching is that it is conventional to index a DataFrame and other containers directly by the column name (e.g. df.column or df[:, :column]) rather than indirectly with a formatting function. I think users might find the standard approach to be a more natural interface.

okay you've convinced me. A simple PR changing the definition of aggname is enough.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kavir1698 picture kavir1698  路  7Comments

Libbum picture Libbum  路  9Comments

Datseris picture Datseris  路  3Comments

Datseris picture Datseris  路  9Comments

Libbum picture Libbum  路  7Comments