def testExpandIntArray(self): v = numpy.array([1, 3, 2, 4], numpy.int) w = Util.expandIntArray(v) self.assertTrue((w == numpy.array([0,1,1,1,2,2,3,3,3,3], numpy.int)).all()) v = numpy.array([], numpy.int) w = Util.expandIntArray(v) self.assertTrue((w == numpy.array([], numpy.int)).all())
def testExpandIntArray(self): v = numpy.array([1, 3, 2, 4], numpy.int) w = Util.expandIntArray(v) self.assertTrue((w == numpy.array([0, 1, 1, 1, 2, 2, 3, 3, 3, 3], numpy.int)).all()) v = numpy.array([], numpy.int) w = Util.expandIntArray(v) self.assertTrue((w == numpy.array([], numpy.int)).all())
def runRandomChoice(): #can just do non-zero entries w = Util.expandIntArray(v) reps = 10000 for i in range(reps): w[numpy.random.randint(0, w.shape[0])]
We simulate a network of sexual contacts and see if we can approximate the degree using a subset of the edges. """ import numpy from apgl.viroscopy.model.HIVGraph import HIVGraph from sandbox.util.Util import Util numpy.set_printoptions(linewidth=200, threshold=10000) numVertices = 500 graph = HIVGraph(numVertices) T = 100 t = 0 expandedDegreeSeq = Util.expandIntArray(graph.outDegreeSequence()) expandedDegreeSeq = numpy.arange(numVertices) contactRate = 0.01 tau = 1.0 infectedList = range(10) #infectedList = range(numVertices) while (t < T): contactRatesMatrix = numpy.zeros((len(infectedList), numVertices)) #Select a random contact based on the degree edsInds = numpy.random.randint(0, expandedDegreeSeq.shape[0], len(infectedList)) #Choose between a contact sampled from those with edges and one from random