ndlib icon indicating copy to clipboard operation
ndlib copied to clipboard

Support weighted graphs for epidemic models

Open pulquero opened this issue 4 years ago • 2 comments

Currently, the SIR model, for instance, samples neighbouring nodes with equal probability. I would like to see an option where edge weights can be used to weight the sampling.

pulquero avatar Sep 22 '21 12:09 pulquero

@GiulioRossetti I can implement this for the S*I* models relatively easily. I think the main point is to change: 1 - (1 - beta) ** len(infected_neighbors) as in: https://github.com/GiulioRossetti/ndlib/blob/5493bbb95131afebd9c8c52166bee3d058e7830d/ndlib/models/epidemics/SIModel.py#L88-L90 but actually have it read the edge weights instead. So, something like: 1-np.prod((1 - beta) ** np.array(infected_neighbors_edge_weight)). That would work as now if the weights are all equal to 1:

beta= 0.10
infected_neighbors_edge_weight = [1,1,1]
(1 - (1 -  beta) ** np.sum(infected_neighbors_edge_weight)  == 
 1 - (1 -  beta) ** len(infected_neighbors_edge_weight))

But it will reweight things accordingly if infected_neighbors_edge_weight is different to unity. Does it make sense to you? (EDIT: forgot the word "sense")

hadjipantelis avatar Dec 06 '24 01:12 hadjipantelis

I made a fork of andlib on my account (https://github.com/hadjipantelis/ndlib). I think I have a working SIModel at this point, prelim. tests work as expected. I will do a quick pass of the S*I* models I can test on my own and PR it.

hadjipantelis avatar Dec 28 '24 19:12 hadjipantelis