本文整理匯總了Python中exp.viroscopy.model.HIVGraph.HIVGraph.removeAllEdges方法的典型用法代碼示例。如果您正苦於以下問題:Python HIVGraph.removeAllEdges方法的具體用法?Python HIVGraph.removeAllEdges怎麽用?Python HIVGraph.removeAllEdges使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類exp.viroscopy.model.HIVGraph.HIVGraph
的用法示例。
在下文中一共展示了HIVGraph.removeAllEdges方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: HIVEpidemicModelTest
# 需要導入模塊: from exp.viroscopy.model.HIVGraph import HIVGraph [as 別名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import removeAllEdges [as 別名]
class HIVEpidemicModelTest(unittest.TestCase):
def setUp(self):
numpy.random.seed(21)
numpy.set_printoptions(suppress=True, precision=4)
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
M = 100
undirected = True
self.graph = HIVGraph(M, undirected)
s = 3
self.gen = scipy.stats.zipf(s)
hiddenDegSeq = self.gen.rvs(size=self.graph.getNumVertices())
rates = HIVRates(self.graph, hiddenDegSeq)
self.model = HIVEpidemicModel(self.graph, rates)
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)
#TODO: Much better testing
def testSimulate2(self):
startDate = 0.0
endDate = 100.0
M = 1000
meanTheta, sigmaTheta = HIVModelUtils.estimatedRealTheta()
undirected = True
graph = HIVGraph(M, undirected)
alpha = 2
zeroVal = 0.9
p = Util.powerLawProbs(alpha, zeroVal)
hiddenDegSeq = Util.randomChoice(p, graph.getNumVertices())
meanTheta[4] = 0.1
recordStep = 10
printStep = 10
rates = HIVRates(graph, hiddenDegSeq)
model = HIVEpidemicModel(graph, rates, endDate, startDate)
model.setRecordStep(recordStep)
model.setPrintStep(printStep)
model.setParams(meanTheta)
initialInfected = graph.getInfectedSet()
times, infectedIndices, removedIndices, graph = model.simulate(True)
#Now test the final graph
edges = graph.getAllEdges()
for i, j in edges:
if graph.vlist.V[i, HIVVertices.genderIndex] == graph.vlist.V[j, HIVVertices.genderIndex] and (graph.vlist.V[i, HIVVertices.orientationIndex] != HIVVertices.bi or graph.vlist.V[j, HIVVertices.orientationIndex] != HIVVertices.bi):
self.fail()
finalInfected = graph.getInfectedSet()
finalRemoved = graph.getRemovedSet()
self.assertEquals(numpy.intersect1d(initialInfected, finalRemoved).shape[0], len(initialInfected))
#Test case where there is no contact
meanTheta = numpy.array([100, 0.95, 1, 1, 0, 0, 0, 0, 0, 0, 0], numpy.float)
times, infectedIndices, removedIndices, graph, model = runModel(meanTheta)
self.assertEquals(len(graph.getInfectedSet()), 100)
self.assertEquals(len(graph.getRemovedSet()), 0)
#.........這裏部分代碼省略.........