Hi folks,
I try to study the spread of an epidemic on graphs. During the simulation, I would like to go through the non-zero elements of a SparseArray and delete these entries with some probability p.
n = 10; (* number of vertices *)
q = 0.75; (* rewiring probability *)
adjMat = 0.2*AdjacencyMatrix[RandomGraph[WattsStrogatzGraphDistribution[n, q]]];
I implemented the routine to do this in the following way:
Do[(* Go through all rows of the adjacency Matrix and modify them *)
adjMat[[i]] =
Map[RandomChoice[{#, 1. - #} -> {1, 0}] &, adjMat[[i]]]
, {i, 1, n}]
Afterwards, one has to make the SparseArray sparse again, to save memory:
adjMat = adjMat//SparseArray
For a graph with 1000 vertices, it takes quite some time.
Is there a more efficient way to do this?
Cheers,
Philipp