本文整理汇总了Python中exp.viroscopy.model.HIVGraph.HIVGraph类的典型用法代码示例。如果您正苦于以下问题:Python HIVGraph类的具体用法?Python HIVGraph怎么用?Python HIVGraph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HIVGraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testSimulate
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: profileSimulate
def profileSimulate(self):
startDate, endDate, recordStep, printStep, M, targetGraph = HIVModelUtils.realSimulationParams()
meanTheta, sigmaTheta = HIVModelUtils.estimatedRealTheta()
meanTheta = numpy.array([337, 1.4319, 0.211, 0.0048, 0.0032, 0.5229, 0.042, 0.0281, 0.0076, 0.0293])
undirected = True
graph = HIVGraph(M, undirected)
logging.info("Created graph: " + str(graph))
alpha = 2
zeroVal = 0.9
p = Util.powerLawProbs(alpha, zeroVal)
hiddenDegSeq = Util.randomChoice(p, graph.getNumVertices())
rates = HIVRates(graph, hiddenDegSeq)
model = HIVEpidemicModel(graph, rates)
model.setT0(startDate)
model.setT(startDate+100)
model.setRecordStep(recordStep)
model.setPrintStep(printStep)
model.setParams(meanTheta)
logging.debug("MeanTheta=" + str(meanTheta))
ProfileUtils.profile('model.simulate()', globals(), locals())
示例3: testInfectionProbability
def testInfectionProbability(self):
undirected = True
numVertices = 10
graph = HIVGraph(numVertices, undirected)
hiddenDegSeq = self.gen.rvs(size=graph.getNumVertices())
rates = HIVRates(graph, hiddenDegSeq)
t = 0.1
graph.getVertex(0)[HIVVertices.stateIndex] = HIVVertices.infected
graph.getVertex(1)[HIVVertices.stateIndex] = HIVVertices.removed
graph.getVertex(2)[HIVVertices.stateIndex] = HIVVertices.infected
for vertexInd1 in range(numVertices):
for vertexInd2 in range(numVertices):
vertex1 = graph.getVertex(vertexInd1)
vertex2 = graph.getVertex(vertexInd2)
if vertex1[HIVVertices.stateIndex]!=HIVVertices.infected or vertex2[HIVVertices.stateIndex]!=HIVVertices.susceptible:
self.assertEquals(rates.infectionProbability(vertexInd1, vertexInd2, t), 0.0)
elif vertex1[HIVVertices.genderIndex] == HIVVertices.female and vertex2[HIVVertices.genderIndex] == HIVVertices.male:
self.assertEquals(rates.infectionProbability(vertexInd1, vertexInd2, t), rates.infectProb)
elif vertex1[HIVVertices.genderIndex] == HIVVertices.male and vertex2[HIVVertices.genderIndex] == HIVVertices.female:
self.assertEquals(rates.infectionProbability(vertexInd1, vertexInd2, t), rates.infectProb)
elif vertex1[HIVVertices.genderIndex] == HIVVertices.male and vertex2[HIVVertices.orientationIndex]==HIVVertices.bi:
self.assertEquals(rates.infectionProbability(vertexInd1, vertexInd2, t), rates.infectProb)
else:
self.assertEquals(rates.infectionProbability(vertexInd1, vertexInd2, t), 0.0)
示例4: testPickle
def testPickle(self):
numVertices = 10
graph = HIVGraph(numVertices)
graph[0, 0] = 1
graph[3, 5] = 0.1
output = pickle.dumps(graph)
newGraph = pickle.loads(output)
graph[2, 2] = 1
self.assertEquals(newGraph[0, 0], 1)
self.assertEquals(newGraph[3, 5], 0.1)
self.assertEquals(newGraph[2, 2], 0.0)
self.assertEquals(newGraph.getNumEdges(), 2)
self.assertEquals(newGraph.getNumVertices(), numVertices)
self.assertEquals(newGraph.isUndirected(), True)
self.assertEquals(graph[0, 0], 1)
self.assertEquals(graph[3, 5], 0.1)
self.assertEquals(graph[2, 2], 1)
self.assertEquals(graph.getNumEdges(), 3)
self.assertEquals(graph.getNumVertices(), numVertices)
self.assertEquals(graph.isUndirected(), True)
for i in range(numVertices):
nptst.assert_array_equal(graph.getVertex(i), newGraph.getVertex(i))
示例5: createModel
def createModel(t):
"""
The parameter t is the particle index.
"""
undirected = True
graph = HIVGraph(M, undirected)
alpha = 2
zeroVal = 0.9
p = Util.powerLawProbs(alpha, zeroVal)
hiddenDegSeq = Util.randomChoice(p, graph.getNumVertices())
featureInds= numpy.ones(graph.vlist.getNumFeatures(), numpy.bool)
featureInds[HIVVertices.dobIndex] = False
featureInds[HIVVertices.infectionTimeIndex] = False
featureInds[HIVVertices.hiddenDegreeIndex] = False
featureInds[HIVVertices.stateIndex] = False
featureInds = numpy.arange(featureInds.shape[0])[featureInds]
matcher = GraphMatch("PATH", alpha=0.5, featureInds=featureInds, useWeightM=False)
graphMetrics = HIVGraphMetrics2(targetGraph, breakDist, matcher, endDate)
graphMetrics.breakDist = 0.0
rates = HIVRates(graph, hiddenDegSeq)
model = HIVEpidemicModel(graph, rates, T=float(endDate), T0=float(startDate), metrics=graphMetrics)
model.setRecordStep(recordStep)
return model
示例6: testContructor
def testContructor(self):
numVertices = 10
graph = HIVGraph(numVertices)
self.assertEquals(numVertices, graph.getNumVertices())
self.assertEquals(8, graph.getVertexList().getNumFeatures())
self.assertTrue(graph.isUndirected() == True)
示例7: testGetSusceptibleSet
def testGetSusceptibleSet(self):
numVertices = 10
graph = HIVGraph(numVertices)
self.assertTrue(graph.getSusceptibleSet() == set(range(numVertices)))
for i in range(9):
graph.getVertexList().setInfected(i, 0.0)
self.assertTrue(graph.getSusceptibleSet() == set([9]))
示例8: testRemoveEvent
def testRemoveEvent(self):
undirected = True
numVertices = 10
graph = HIVGraph(numVertices, undirected)
hiddenDegSeq = self.gen.rvs(size=graph.getNumVertices())
rates = HIVRates(graph, hiddenDegSeq)
t = 0.1
V = graph.getVertexList().getVertices()
femaleInds = V[:, HIVVertices.genderIndex]==HIVVertices.female
maleInds = V[:, HIVVertices.genderIndex]==HIVVertices.male
biMaleInds = numpy.logical_and(maleInds, V[:, HIVVertices.orientationIndex]==HIVVertices.bi)
self.assertEquals(rates.expandedDegSeqFemales.shape[0], hiddenDegSeq[femaleInds].sum()*rates.p)
self.assertEquals(rates.expandedDegSeqMales.shape[0], hiddenDegSeq[maleInds].sum()*rates.p)
self.assertEquals(rates.expandedDegSeqBiMales.shape[0], hiddenDegSeq[biMaleInds].sum()*rates.p)
graph.getVertexList().setInfected(4, t)
graph.getVertexList().setInfected(7, t)
graph.getVertexList().setInfected(8, t)
rates.removeEvent(4, HIVVertices.randomDetect, t)
rates.removeEvent(7, HIVVertices.randomDetect, t)
removedInds= list(graph.getRemovedSet())
hiddenDegSeq[removedInds] = 0
#Check the new degree sequences are correct
self.assertEquals(rates.expandedDegSeqFemales.shape[0], hiddenDegSeq[femaleInds].sum()*rates.p)
self.assertEquals(rates.expandedDegSeqMales.shape[0], hiddenDegSeq[maleInds].sum()*rates.p)
self.assertEquals(rates.expandedDegSeqBiMales.shape[0], hiddenDegSeq[biMaleInds].sum()*rates.p)
示例9: testRandomDetectionRates
def testRandomDetectionRates(self):
undirected = True
numVertices = 10
graph = HIVGraph(numVertices, undirected)
t = 0.1
graph.getVertexList().setInfected(0, t)
hiddenDegSeq = self.gen.rvs(size=graph.getNumVertices())
rates = HIVRates(graph, hiddenDegSeq)
infectedList = [0, 2, 9]
rdRates = rates.randomDetectionRates(infectedList, float(graph.size - len(graph.getRemovedSet())))
nptst.assert_array_almost_equal(rdRates, numpy.ones(len(infectedList))*rates.randDetectRate*len(infectedList)/float(graph.size - len(graph.getRemovedSet())))
示例10: testSummary
def testSummary(self):
numVertices = 10
graph = HIVGraph(numVertices)
graph.getVertexList().setInfected(1, 0.0)
graph.getVertexList().setInfected(2, 2.0)
graph.getVertexList().setInfected(7, 3.0)
times = numpy.array([0, 1.0, 3.0, 4.0])
metrics = HIVGraphMetrics(times)
summary = metrics.summary(graph)
summaryReal = numpy.array([[1,0], [1,0], [3, 0], [3,0]])
nptst.assert_array_equal(summaryReal, summary)
示例11: __init__
def __init__(self):
#Total number of people in population
self.M = 1000
numInitialInfected = 5
#The graph is one in which edges represent a contact
undirected = True
self.graph = HIVGraph(self.M, undirected)
for i in range(self.M):
vertex = self.graph.getVertex(i)
#Set the infection time of a number of individuals to 0
if i < numInitialInfected:
vertex[HIVVertices.stateIndex] = HIVVertices.infected
p = 0.01
generator = ErdosRenyiGenerator(p)
self.graph = generator.generate(self.graph)
perm1 = numpy.random.permutation(self.M)
perm2 = numpy.random.permutation(self.M)
sizes = [200, 300, 500, 1000]
self.summary1 = []
self.summary2 = []
for size in sizes:
self.summary1.append(self.graph.subgraph(perm1[0:size]))
self.summary2.append(self.graph.subgraph(perm2[0:int(size/10)]))
print(self.graph)
示例12: simulate
def simulate(theta, startDate, endDate, recordStep, M, graphMetrics=None):
undirected = True
graph = HIVGraph(M, undirected)
logging.debug("Created graph: " + str(graph))
alpha = 2
zeroVal = 0.9
p = Util.powerLawProbs(alpha, zeroVal)
hiddenDegSeq = Util.randomChoice(p, graph.getNumVertices())
rates = HIVRates(graph, hiddenDegSeq)
model = HIVEpidemicModel(graph, rates, endDate, startDate, metrics=graphMetrics)
model.setRecordStep(recordStep)
model.setParams(theta)
logging.debug("Theta = " + str(theta))
return model.simulate(True)
示例13: HIVGraphMetricsProfile
class HIVGraphMetricsProfile():
def __init__(self):
#Total number of people in population
self.M = 1000
numInitialInfected = 5
#The graph is one in which edges represent a contact
undirected = True
self.graph = HIVGraph(self.M, undirected)
for i in range(self.M):
vertex = self.graph.getVertex(i)
#Set the infection time of a number of individuals to 0
if i < numInitialInfected:
vertex[HIVVertices.stateIndex] = HIVVertices.infected
p = 0.01
generator = ErdosRenyiGenerator(p)
self.graph = generator.generate(self.graph)
perm1 = numpy.random.permutation(self.M)
perm2 = numpy.random.permutation(self.M)
sizes = [200, 300, 500, 1000]
self.summary1 = []
self.summary2 = []
for size in sizes:
self.summary1.append(self.graph.subgraph(perm1[0:size]))
self.summary2.append(self.graph.subgraph(perm2[0:int(size/10)]))
print(self.graph)
def profileDistance(self):
times = numpy.arange(len(self.summary1))
#metrics = HIVGraphMetrics2(times, GraphMatch("RANK"))
metrics = HIVGraphMetrics2(times, GraphMatch("U"))
#Can try RANK and Umeyama algorithm - Umeyama is faster
self.summary2 = self.summary2[0:2]
ProfileUtils.profile('metrics.distance(self.summary1, self.summary2)', globals(), locals())
示例14: testInfectedIndsAt
def testInfectedIndsAt(self):
numVertices = 10
graph = HIVGraph(numVertices)
self.assertTrue(graph.getRemovedSet() == set([]))
graph.getVertexList().setInfected(1, 0.0)
graph.getVertexList().setInfected(2, 2.0)
graph.getVertexList().setInfected(7, 3.0)
inds = graph.infectedIndsAt(10)
nptst.assert_array_equal(inds, numpy.array([1, 2, 7]))
graph.getVertexList().setInfected(5, 12.0)
nptst.assert_array_equal(inds, numpy.array([1, 2, 7]))
示例15: testContactRates3
def testContactRates3(self):
#Figure out why infection does not explode when we set infection probability
#to a high value and do not detect
undirected = True
numVertices = 20
graph = HIVGraph(numVertices, undirected)
hiddenDegSeq = self.gen.rvs(size=graph.getNumVertices())
rates = HIVRates(graph, hiddenDegSeq)
t = 0.1
for i in range(10):
graph.getVertexList().setInfected(i, t)
t = 0.2
infectedList = graph.infectedIndsAt(t)
contactList = range(0, numVertices)
contactRateInds, contactRates = rates.contactRates(infectedList, contactList, t)
print(contactRateInds, contactRates)