Open Islast opened 6 years ago
Woooo! This is a REALLY useful issue!! Thank you @Islast! ✨
I'm happy to discuss any refactoring that's needed. I have to admit that I don't really know the benefits of having class methods 😬. The most important thing for me with this refactoring is that the values are written out in a standard form (csv
for example) so that the other commands can be run without running this one.
The value of having something saved as a class attribute instead of as a global namespace variable or in a dictionary is that they are easier to identify. i.e if you want to find the nodal partition you calculated for a given graph G
, you only need to type G.nodal_partition
.
The value of class methods is that grammatically you expect nodal_partition(G)
to return a nodal partition, while you expect G.nodal_partition()
to return nothing and make changes to G
. This means that if we want the nodal partition to be saved automatically as an class attribute, G.nodal_partition()
is the better choice.
I think it's good to provide functions in terms of both: normal functions for when you just want to return the result, and class methods for when you want to automatically add to the graph attributes.
BUT, I don't know how adding new class methods to an existing class interferes with it (adding attributes is fine).
@Kirstie, let me know where and when and what you would like to see written to disk :hibiscus:
Completed in #74
This is a very long issue to discuss how to change the network_analysis_from_corrmat wrapper, for more modularity and easier adjustment.
Decisions
Moving data and functions to class attributes and methods
One major consideration is how much of the data that accompanies the correlation matrix (names, centroids) and how much of the data produced afterwards (partitions, random graphs and measures) can or should be stored as attributes of the graph, graph nodes or edges. Furthermore should some of these functions (nodal partition, calculate measures, the smaller functions wrapped in the 'calculate_nodal_measures' function, write_out_x) be Class methods? Adding class methods to the networkx Graph class seems cavalier. We could define a new class, but if we do it should support all the same methods as a networkx Graph.
Breaking down the main function
Set-up
read in data and initialise graph:
Nodal measures
calculate nodal partition What we mean by calculate nodal partition is "assign communities to the nodes via the louvain method", and is where we use the community package.
calculate nodal measures We calculate a range of nodal mesures including:
write out nodal measures exactly what it says on the tin
Global measures
generate random graphs generate n random graphs via edge-swapping
calculate global measures
write out global measures
Rich Club
calculate rich club coefficients
write out rich club
The main function verbatim
As of Latest commit 81713d6