本文整理汇总了Python中exp.viroscopy.model.HIVGraph.HIVGraph.setRandomInfected方法的典型用法代码示例。如果您正苦于以下问题:Python HIVGraph.setRandomInfected方法的具体用法?Python HIVGraph.setRandomInfected怎么用?Python HIVGraph.setRandomInfected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exp.viroscopy.model.HIVGraph.HIVGraph
的用法示例。
在下文中一共展示了HIVGraph.setRandomInfected方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testSimulate
# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import setRandomInfected [as 别名]
def testSimulate(self):
T = 1.0
self.graph.getVertexList().setInfected(0, 0.0)
self.model.setT(T)
times, infectedIndices, removedIndices, graph = self.model.simulate(verboseOut=True)
numInfects = 0
for i in range(graph.getNumVertices()):
if graph.getVertex(i)[HIVVertices.stateIndex] == HIVVertices==infected:
numInfects += 1
self.assertTrue(numInfects == 0 or times[len(times)-1] >= T)
#Test with a larger population as there seems to be an error when the
#number of infectives becomes zero.
M = 100
undirected = True
graph = HIVGraph(M, undirected)
graph.setRandomInfected(10, 0.95)
self.graph.removeAllEdges()
T = 21.0
hiddenDegSeq = self.gen.rvs(size=self.graph.getNumVertices())
rates = HIVRates(self.graph, hiddenDegSeq)
model = HIVEpidemicModel(self.graph, rates)
model.setRecordStep(10)
model.setT(T)
times, infectedIndices, removedIndices, graph = model.simulate(verboseOut=True)
self.assertTrue((times == numpy.array([0, 10, 20], numpy.int)).all())
self.assertEquals(len(infectedIndices), 3)
self.assertEquals(len(removedIndices), 3)
示例2: testSetRandomInfected
# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import setRandomInfected [as 别名]
def testSetRandomInfected(self):
numVertices = 10000
graph = HIVGraph(numVertices)
graph.setRandomInfected(100, 0.8)
heteroInfected = numpy.logical_and(graph.vlist.V[:, HIVVertices.stateIndex]==HIVVertices.infected, graph.vlist.V[:, HIVVertices.orientationIndex]==HIVVertices.hetero)
biInfected = numpy.logical_and(graph.vlist.V[:, HIVVertices.stateIndex]==HIVVertices.infected, graph.vlist.V[:, HIVVertices.orientationIndex]==HIVVertices.bi)
self.assertAlmostEqual(heteroInfected.sum()/float(100), 0.8)
self.assertAlmostEqual(biInfected.sum()/float(100), 0.2)
graph = HIVGraph(numVertices)
graph.setRandomInfected(100, 0.5)
heteroInfected = numpy.logical_and(graph.vlist.V[:, HIVVertices.stateIndex]==HIVVertices.infected, graph.vlist.V[:, HIVVertices.orientationIndex]==HIVVertices.hetero)
biInfected = numpy.logical_and(graph.vlist.V[:, HIVVertices.stateIndex]==HIVVertices.infected, graph.vlist.V[:, HIVVertices.orientationIndex]==HIVVertices.bi)
self.assertAlmostEqual(heteroInfected.sum()/float(100), 0.5)
self.assertAlmostEqual(biInfected.sum()/float(100), 0.5)
graph = HIVGraph(numVertices)
graph.setRandomInfected(100, 0.0)
heteroInfected = numpy.logical_and(graph.vlist.V[:, HIVVertices.stateIndex]==HIVVertices.infected, graph.vlist.V[:, HIVVertices.orientationIndex]==HIVVertices.hetero)
biInfected = numpy.logical_and(graph.vlist.V[:, HIVVertices.stateIndex]==HIVVertices.infected, graph.vlist.V[:, HIVVertices.orientationIndex]==HIVVertices.bi)
self.assertAlmostEqual(heteroInfected.sum()/float(100), 0.0)
self.assertAlmostEqual(biInfected.sum()/float(100), 1.0)
graph = HIVGraph(numVertices)
graph.setRandomInfected(100, 1.0)
heteroInfected = numpy.logical_and(graph.vlist.V[:, HIVVertices.stateIndex]==HIVVertices.infected, graph.vlist.V[:, HIVVertices.orientationIndex]==HIVVertices.hetero)
biInfected = numpy.logical_and(graph.vlist.V[:, HIVVertices.stateIndex]==HIVVertices.infected, graph.vlist.V[:, HIVVertices.orientationIndex]==HIVVertices.bi)
self.assertAlmostEqual(heteroInfected.sum()/float(100), 1.0)
self.assertAlmostEqual(biInfected.sum()/float(100), 0.0)
示例3: testSetRandomInfected
# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import setRandomInfected [as 别名]
def testSetRandomInfected(self):
numVertices = 10000
graph = HIVGraph(numVertices)
graph.setRandomInfected(100)
self.assertAlmostEqual(len(graph.getInfectedSet()), 100)
graph = HIVGraph(numVertices)
graph.setRandomInfected(50, 0.5)
self.assertAlmostEqual(len(graph.getInfectedSet()), 50)
graph = HIVGraph(numVertices)
graph.setRandomInfected(20, 0.0)
self.assertAlmostEqual(len(graph.getInfectedSet()), 20)
graph = HIVGraph(numVertices)
graph.setRandomInfected(10, 1.0)
self.assertAlmostEqual(len(graph.getInfectedSet()), 10)