Example #1
0
 def testFromCoefficients(self):
     '''Test we can create a generating function from explicit coefficients.'''
     coeffs = [0, 0.05, 0.7, 0.25]
     gf = gf_from_coefficients(coeffs)
     self.assertEqual(gf(1.0), 1.0)
     for k in range(len(coeffs)):
         self.assertEqual(coeffs[k], gf[k])
     self.assertEqual(gf[k + 1], 0.0)
Example #2
0
    def testFromFunction(self):
        '''Test we can create a generating function from a function returning the coefficients.'''
        coeffs = [0, 0.05, 0.7, 0.25]

        def f(k):
            if k < len(coeffs):
                return coeffs[k]
            else:
                return 0

        gf = gf_from_coefficient_function(f)
        self.assertEqual(gf(1.0), 1.0)
        for k in range(len(coeffs)):
            self.assertEqual(coeffs[k], gf[k])
        self.assertEqual(gf[k + 1], 0.0)
Example #3
0
 def testDiscreteProbabilities(self):
     '''Test that the coefficients of a discrete GF sum to 1.'''
     g = networkx.gnp_random_graph(5000, 0.005)
     gf = DiscreteGF(g=g)
     self.assertAlmostEqual(gf(1.0), 1.0, places=2)
Example #4
0
 def testPLCProbabilities(self):
     '''Test that the PLC GF evaluates to 1.'''
     gf = gf_plc(3.0, 60)
     self.assertAlmostEqual(gf(1.0), 1.0, places=2)
Example #5
0
 def testPLProbabilities(self):
     '''Test that the powerlaw GF evaluates to 1.'''
     gf = gf_powerlaw(3.0)
     self.assertAlmostEqual(gf(1.0), 1.0, places=2)
Example #6
0
 def testERProbabilities(self):
     '''Test that the ER GF evaluates to 1.'''
     gf = gf_er(5000, 0.005)
     self.assertAlmostEqual(gf(1.0), 1.0, places=2)