-
Notifications
You must be signed in to change notification settings - Fork 20
return order of node metrics #192
Comments
Or in simpler words through an example, if I define a function as: using Chain, EcologicalNetworks
in_degrees = @chain unipartite_foodweb begin
adjacency
sum(_,dims = 2)
vec
end How do I reconcile its values with, say, centrality_degree(unipartite_foodweb) ? |
Most (all?) species-level functions will return a BUT the names returned by the So a solution would be to use... I guess |
Just to add further information, |
It sounds promising. |
Ok, what I've come up with is something like this: function merge_metrics(adj_metric::A, EN_metric::E, species_web::Vector{MangalNode}) where {A <: Vector, E <: Dict{MangalNode,<:Any}}
adj_metric_df = DataFrame([(sp.id, adj_metric[position]) for (position, sp) in enumerate(species_web)])
EN_metric_df = DataFrame([(sp.id, EN_metric[sp]) for sp in species_web])
metric_df = innerjoin(adj_metric_df,EN_metric_df; on = Symbol(1), makeunique = true)
rename!(metric_df, [:Species_id, :adj_metric, :EN_metric])
return metric_df
end where:
It returns a DataFrame with the species id and the two metrics. It's easy to provide an higher abstraction function such as: merge_metrics(adj_metric::A, EN_metric::E, web::W) where {A <: Vector, E <: Dict{MangalNode,<:Any}, W <: AbstractEcologicalNetwork} = merge_metrics(adj_metric, EN_metric, species(web)) Do you think this is the right approach? Would you have tackled this differently? PS one thing I don't fully like is the dependency on |
My issue with this is that it might lead people to do something like |
My workflow using EcologicalNetworks is often:
However, I'm never sure in which order EcologicalNetworks returns its values.
One thing that may be possible is to force functions such as
centrality_degree
to return species values in the same order with whichadjacency
assign species to rows (or columns).An other way is to add an option to
adjacency
so that it return the species key in the right order, so that one can match.PS I'm proposing this because I think that at the moment the order of rows in 'adjacency
and
centrality_...are not the same. I tried to test it comparing a hand made degree (rowsums / colsums of the adjacency matrix) and the vals out of
centrality_...`. Yet, I may be wrong.The text was updated successfully, but these errors were encountered: