tapios / risk-networks

Code for risk networks: a blend of compartmental models, graphs, data assimilation and semi-supervised learning
Other
2 stars 2 forks source link

Avoid assumption that nodes are a simple range #62

Closed glwagner closed 4 years ago

glwagner commented 4 years ago

The issues discussed in #58 and #60 arise because the node id's generated from 'edge_list_SBM_1e4.txt' are not a range from 0 to population-1.

In contrast, many initialization functions --- populate_ages, sample_distribution, and TransitionRates assume that the nodes are a range from 0 to population-1, and therefore correspond 1-1 with the node id's.

To relax the assumption that node id's are a range, we need to either use dictionaries, or the contact network itself to assign ages and clinical statistics to the population.

I propose that we use the contact network itself. In this abstraction, we will assign ages to the contact network according to a distribution. Thus populate_ages will be replaced with assign_ages(contact_network, distribution). The generation of distributions for the clinical parameters, as well as the constructor for TransitionRates will have to be modified accordingly.

I don't think this will take long. @lubo93, please advise.

lubo93 commented 4 years ago

Yes, we should use G.nodes() as our node iterator. This would be quite helpful.

I will also fix our current networks to fix the issue for the moment.

glwagner commented 4 years ago

@lubo93 there is one complication. The master equation solver does not use a graph. Therefore, there needs to be a 1-1 correspondence between list elements and node numbers.

If we want to allow the node id's to have "gaps", but still correspond in a simple way to a list, we can potentially use an OrderedGraph?

https://networkx.github.io/documentation/stable/reference/classes/ordered.html

@lubo93, please advise.

lubo93 commented 4 years ago

Ok, I will then just fix our networks. We should add a description in the README to make sure that everyone uses edge lists with 0,1,... node numbers. Some objects in networkx (e.g., lattices) don't use this convention.

lubo93 commented 4 years ago

This issue should be solved by using "contact_network = nx.convert_node_labels_to_integers(contact_network)". @glwagner , can you confirm that this solves the problem? Then we could close this issue.

glwagner commented 4 years ago

Yes, I believe this issue was solved by #64. Thanks @lubo93 .