本文整理汇总了Python中exp.viroscopy.model.HIVGraph.HIVGraph.getNumEdges方法的典型用法代码示例。如果您正苦于以下问题:Python HIVGraph.getNumEdges方法的具体用法?Python HIVGraph.getNumEdges怎么用?Python HIVGraph.getNumEdges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exp.viroscopy.model.HIVGraph.HIVGraph
的用法示例。
在下文中一共展示了HIVGraph.getNumEdges方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testPickle
# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import getNumEdges [as 别名]
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))
示例2: testSimulate2
# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import getNumEdges [as 别名]
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)
self.assertEquals(graph.getNumEdges(), 0)
heteroContactRate = 0.1
meanTheta = numpy.array([100, 0.95, 1, 1, 0, 0, heteroContactRate, 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)
edges = graph.getAllEdges()
for i, j in edges:
self.assertNotEqual(graph.vlist.V[i, HIVVertices.genderIndex], graph.vlist.V[j, HIVVertices.genderIndex])
#Number of conacts = rate*people*time
infectedSet = graph.getInfectedSet()
numHetero = (graph.vlist.V[list(infectedSet), HIVVertices.orientationIndex] == HIVVertices.hetero).sum()
self.assertTrue(abs(numHetero*endDate*heteroContactRate- model.getNumContacts()) < 100)
heteroContactRate = 0.01
meanTheta = numpy.array([100, 0.95, 1, 1, 0, 0, heteroContactRate, 0, 0, 0, 0], numpy.float)
times, infectedIndices, removedIndices, graph, model = runModel(meanTheta)
infectedSet = graph.getInfectedSet()
numHetero = (graph.vlist.V[list(infectedSet), HIVVertices.orientationIndex] == HIVVertices.hetero).sum()
self.assertAlmostEqual(numHetero*endDate*heteroContactRate/100, model.getNumContacts()/100.0, 0)
示例3: HIVRatesProfile
# 需要导入模块: from exp.viroscopy.model.HIVGraph import HIVGraph [as 别名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import getNumEdges [as 别名]
class HIVRatesProfile():
def __init__(self):
#Total number of people in population
self.M = 10000
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
outputDirectory = PathDefaults.getOutputDir()
directory = outputDirectory + "test/"
self.profileFileName = directory + "profile.cprof"
def profileContactRate(self):
susceptibleList = list(range(1, self.graph.getNumVertices()))
t = 10
s = 3
gen = scipy.stats.zipf(s)
hiddenDegSeq = gen.rvs(size=self.graph.getNumVertices())
rates = HIVRates(self.graph, hiddenDegSeq)
numContactEvents = 5000
for i in range(numContactEvents):
vertexInd1 = numpy.random.randint(0, self.graph.getNumVertices())
vertexInd2 = numpy.random.randint(0, self.graph.getNumVertices())
rates.contactEvent(vertexInd1, vertexInd2, 5)
print((self.graph.getNumEdges()))
infectedList = range(0, 100)
contactList = range(100, self.M)
t = 10
def runContactRates():
for i in range(100):
rates.contactRates(infectedList, contactList, t)
ProfileUtils.profile('runContactRates()', globals(), locals())
def profileInfectionProbability(self):
s = 3
gen = scipy.stats.zipf(s)
hiddenDegSeq = gen.rvs(size=self.graph.getNumVertices())
rates = HIVRates(self.graph, hiddenDegSeq)
t = 5
#Getting vertices and checking parameters takes the most time
def runInfectionProbs():
for i in range(10000):
vertexInd1 = numpy.random.randint(0, self.graph.getNumVertices())
vertexInd2 = numpy.random.randint(0, self.graph.getNumVertices())
rates.infectionProbability(vertexInd1, vertexInd2, t)
ProfileUtils.profile('runInfectionProbs()', globals(), locals())
def profileContactTracingRate(self):
s = 3
gen = scipy.stats.zipf(s)
hiddenDegSeq = gen.rvs(size=self.graph.getNumVertices())
rates = HIVRates(self.graph, hiddenDegSeq)
#Create a network of sexual contacts
numContactEvents = 10000
for i in range(numContactEvents):
vertexInd1 = numpy.random.randint(0, self.graph.getNumVertices())
vertexInd2 = numpy.random.randint(0, self.graph.getNumVertices())
rates.contactEvent(vertexInd1, vertexInd2, 5)
print((self.graph))
print((self.graph.degreeDistribution()))
#Choose some individuals as being infected and then detected
p = 0.3
q = 0.4
for i in range(self.graph.getNumVertices()):
if numpy.random.rand() < p and not self.graph.getVertex(i)[HIVVertices.stateIndex] == HIVVertices.infected:
self.graph.getVertexList().setInfected(i, 5.0)
if numpy.random.rand() < q:
self.graph.getVertexList().setDetected(i, 6.0, HIVVertices.randomDetect)
infectedSet = self.graph.getInfectedSet()
print((len(infectedSet)))
print((len(self.graph.getRemovedSet())))
removedSet = self.graph.getRemovedSet()
t = 200
def runContactTracingRate():
#.........这里部分代码省略.........