def testChildrenListLastEntry_k_Mod_m(self): rootPrefix = tp.typePrefix(100) childrenWhichAre2Mod10 = rootPrefix.childrenListLastEntry_k_Mod_m( 2, 10) prefixes = [prefix.data for prefix in childrenWhichAre2Mod10] self.failUnlessEqual( prefixes, [[2], [12], [22], [32], [42], [52], [62], [72], [82], [92]])
def testProcess(self): rootPrefix = tp.typePrefix(3) totalNumberOfTypesLen4Size3 = rootPrefix.numDescendants() globalList = [] rootPrefix.DFSProcess(globalList.append) ExpectedGlobalList = [[0, 0, 0, 3], [0, 0, 1, 2], [0, 0, 2, 1], [0, 0, 3, 0], [0, 1, 0, 2], [0, 1, 1, 1], [0, 1, 2, 0], [0, 2, 0, 1], [0, 2, 1, 0], [0, 3, 0, 0], [1, 0, 0, 2], [1, 0, 1, 1], [1, 0, 2, 0], [1, 1, 0, 1], [1, 1, 1, 0], [1, 2, 0, 0], [2, 0, 0, 1], [2, 0, 1, 0], [2, 1, 0, 0], [3, 0, 0, 0]] self.failUnlessEqual(globalList, ExpectedGlobalList) self.failUnlessEqual(len(globalList), totalNumberOfTypesLen4Size3) #20 globalList = [] fullPrefix = tp.typePrefix(3,[3,0,0,0]) fullPrefix.DFSProcess(globalList.append) self.failUnlessEqual(globalList,[[3,0,0,0]]) self.failUnless(len(globalList),fullPrefix.numDescendants()) #1
def testAccountForAllTypesWithTwoElementPrefix(self): p_eta = pdf.probabilityDistributionFactory(2,2).get_p_eta(0.1) self.CDF.referenceDistribution = p_eta self.CDF.setN(5) prefix = tp.typePrefix(5,data=[2,1],n=4) self.CDF.accountForTypesWithPrefix(prefix) self.failUnlessAlmostEqual(self.CDF.Dictionary, {0.013844293808390619: 0.054900966738391482, 0.11849392256130019: 0.065587032834470232, 0.2911031660323688: 0.13610213450308134} )
def accountForAllTypesRobbins(self): """ Generate all the type classes of size N and account for all types in the CDF: currently assumes the random variable whose CDF we are generating is the MI r.v. """ if not self.N or not self.n: raise ValueError("Cannot generate types unless both n and N are set.") rootPrefix = tp.typePrefix(self.N, [], self.n) self.accountForTypesWithPrefixRobbins(rootPrefix)
def accountForAllTypesRobbins(self): """ Generate all the type classes of size N and account for all types in the CDF: currently assumes the random variable whose CDF we are generating is the MI r.v. """ if not self.N or not self.n: raise ValueError( "Cannot generate types unless both n and N are set.") rootPrefix = tp.typePrefix(self.N, [], self.n) self.accountForTypesWithPrefixRobbins(rootPrefix)
def testProcess(self): rootPrefix = tp.typePrefix(3) totalNumberOfTypesLen4Size3 = rootPrefix.numDescendants() globalList = [] rootPrefix.DFSProcess(globalList.append) ExpectedGlobalList = [[0, 0, 0, 3], [0, 0, 1, 2], [0, 0, 2, 1], [0, 0, 3, 0], [0, 1, 0, 2], [0, 1, 1, 1], [0, 1, 2, 0], [0, 2, 0, 1], [0, 2, 1, 0], [0, 3, 0, 0], [1, 0, 0, 2], [1, 0, 1, 1], [1, 0, 2, 0], [1, 1, 0, 1], [1, 1, 1, 0], [1, 2, 0, 0], [2, 0, 0, 1], [2, 0, 1, 0], [2, 1, 0, 0], [3, 0, 0, 0]] self.failUnlessEqual(globalList, ExpectedGlobalList) self.failUnlessEqual(len(globalList), totalNumberOfTypesLen4Size3) #20 globalList = [] fullPrefix = tp.typePrefix(3, [3, 0, 0, 0]) fullPrefix.DFSProcess(globalList.append) self.failUnlessEqual(globalList, [[3, 0, 0, 0]]) self.failUnless(len(globalList), fullPrefix.numDescendants()) #1
def accountForAllTypesParallelizedRobbins(self, modulus): """ Break the job into account for all types which have the prefix (0), (1),...(modulus - 1) % modulus """ if not self.N or not self.n: raise ValueError("Cannot generate types unless both n and N are set.") rootPrefix = tp.typePrefix(self.N, [], self.n) rootsForParallelJobs = [rootPrefix.childrenListLastEntry_k_Mod_m(k, modulus) for k in range(modulus)] ListOfCDFs = Parallel(n_jobs=-1, verbose=50)(delayed(accountForListOfTypePrefixesRobbins)( aRootList,self.N, self.n, self.referenceDistribution) for aRootList in rootsForParallelJobs) self.mergeListInto(ListOfCDFs)
def testAccountForAllTypesWithTwoElementPrefix(self): p_eta = pdf.probabilityDistributionFactory(2, 2).get_p_eta(0.1) self.CDF.referenceDistribution = p_eta self.CDF.setN(5) prefix = tp.typePrefix(5, data=[2, 1], n=4) self.CDF.accountForTypesWithPrefix(prefix) self.failUnlessAlmostEqual( self.CDF.Dictionary, { 0.013844293808390619: 0.054900966738391482, 0.11849392256130019: 0.065587032834470232, 0.2911031660323688: 0.13610213450308134 })
def accountForAllTypesParallelizedRobbins(self, modulus): """ Break the job into account for all types which have the prefix (0), (1),...(modulus - 1) % modulus """ if not self.N or not self.n: raise ValueError( "Cannot generate types unless both n and N are set.") rootPrefix = tp.typePrefix(self.N, [], self.n) rootsForParallelJobs = [ rootPrefix.childrenListLastEntry_k_Mod_m(k, modulus) for k in range(modulus) ] ListOfCDFs = Parallel(n_jobs=-1, verbose=50)( delayed(accountForListOfTypePrefixesRobbins)( aRootList, self.N, self.n, self.referenceDistribution) for aRootList in rootsForParallelJobs) self.mergeListInto(ListOfCDFs)
def testHasChildren(self): rootPrefix = tp.typePrefix( 3) #root prefix is [] and has children [0],[1],[2],[3] self.failUnless(rootPrefix.hasChildren()) fullPrefix = tp.typePrefix(3, [3, 0, 0, 0]) self.failIf(fullPrefix.hasChildren())
def testChildrenListLastEntry_k_Mod_m(self): rootPrefix = tp.typePrefix(100) childrenWhichAre2Mod10 = rootPrefix.childrenListLastEntry_k_Mod_m(2, 10) prefixes = [prefix.data for prefix in childrenWhichAre2Mod10] self.failUnlessEqual(prefixes, [[2], [12], [22], [32], [42], [52], [62], [72], [82], [92]] )
def testHasChildren(self): rootPrefix = tp.typePrefix(3) #root prefix is [] and has children [0],[1],[2],[3] self.failUnless(rootPrefix.hasChildren()) fullPrefix = tp.typePrefix(3,[3,0,0,0]) self.failIf(fullPrefix.hasChildren())