當前位置: 首頁>>代碼示例>>Python>>正文


Python HIVGraph.setVertex方法代碼示例

本文整理匯總了Python中exp.viroscopy.model.HIVGraph.HIVGraph.setVertex方法的典型用法代碼示例。如果您正苦於以下問題:Python HIVGraph.setVertex方法的具體用法?Python HIVGraph.setVertex怎麽用?Python HIVGraph.setVertex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在exp.viroscopy.model.HIVGraph.HIVGraph的用法示例。


在下文中一共展示了HIVGraph.setVertex方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testContactRates2

# 需要導入模塊: from exp.viroscopy.model.HIVGraph import HIVGraph [as 別名]
# 或者: from exp.viroscopy.model.HIVGraph.HIVGraph import setVertex [as 別名]
    def testContactRates2(self):
        undirected = True
        numVertices = 10
        graph = HIVGraph(numVertices, undirected)

        maleVertex = graph.getVertex(0)
        maleVertex[HIVVertices.genderIndex] = HIVVertices.male
        femaleVertex = maleVertex.copy()
        femaleVertex[HIVVertices.genderIndex] = HIVVertices.female

        for i in range(5): 
            graph.setVertex(i, maleVertex)
            graph.setVertex(i+5, femaleVertex)

        V = graph.getVertexList().getVertices()

        contactList = range(numVertices)

        #Test that the parameters alpha and C do the right thing
        hiddenDegSeq = self.gen.rvs(size=graph.getNumVertices())
        rates = HIVRates(graph, hiddenDegSeq)
        t = 0.2
        logging.debug("Rates with no existing contacts")
        contactRateInds, contactRates = rates.contactRates(range(numVertices), contactList, t)

        #When there are no contacts the choice is easy and some random new contacts
        #are chosen.
        #Now test differences in choice between existing and new contact.
        t = 0.3
        for i in range(5):
            rates.contactEvent(i, i+5, t)

        rates.alpha = 1.0
        logging.debug("Rates with default alpha=" + str(rates.alpha))
        contactRateInds, contactRates = rates.contactRates(range(numVertices), contactList, 0.4)


        for i in range(5):
            self.assertTrue(contactRates[i] == rates.contactRate)
            self.assertTrue(contactRateInds[i] == i+5)

        #Now try changing alpha
        logging.debug("Rates with alpha=0.5")
        rates.setAlpha(0.5)
        contactRateInds, contactRates = rates.contactRates(range(numVertices), contactList, 0.4)
        #Observed probabilities change as expected


        #Now increase time and observe probabilities
        logging.debug("Rates with t=20")
        contactRateInds, contactRates = rates.contactRates(range(numVertices), contactList, 20)


        #Test we don't pick from removed
        graph.getVertexList().setInfected(0, t)
        graph.getVertexList().setInfected(4, t)
        graph.getVertexList().setInfected(7, t)
        graph.getVertexList().setInfected(8, t)
        #graph.getVertexList().setDetected(4, t, HIVVertices.randomDetect)
        #graph.getVertexList().setDetected(7, t, HIVVertices.randomDetect)
        rates.removeEvent(4, HIVVertices.randomDetect, t)
        rates.removeEvent(7, HIVVertices.randomDetect, t)

        infectedSet = graph.getInfectedSet()
        susceptibleSet = graph.getSusceptibleSet()
        removedSet = graph.getRemovedSet()
        contactSet = infectedSet.union(susceptibleSet)

        infectedList = list(infectedSet)
        removedList = list(removedSet)
        contactList = list(contactSet)

        contactRateInds, contactRates = rates.contactRates(infectedList, contactList, 20)
        
        #Contacts cannot be in removed set 
        self.assertTrue(numpy.intersect1d(contactRateInds, numpy.array(removedList)).shape[0]==0)        
開發者ID:charanpald,項目名稱:wallhack,代碼行數:78,代碼來源:HIVRatesTest.py


注:本文中的exp.viroscopy.model.HIVGraph.HIVGraph.setVertex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。