Example #1
0
    def testFitDiscretePowerLaw2(self):
        try:
            import networkx
        except ImportError:
            logging.debug("Networkx not found, can't run test")
            return

        nxGraph = networkx.barabasi_albert_graph(1000, 2)
        graph = SparseGraph.fromNetworkXGraph(nxGraph)
        degreeSeq = graph.outDegreeSequence()

        output = Util.fitDiscretePowerLaw(degreeSeq)
Example #2
0
    def testFitDiscretePowerLaw2(self):
        try:
            import networkx
        except ImportError:
            logging.debug("Networkx not found, can't run test")
            return

        nxGraph = networkx.barabasi_albert_graph(1000, 2)
        graph = SparseGraph.fromNetworkXGraph(nxGraph)
        degreeSeq = graph.outDegreeSequence()

        output = Util.fitDiscretePowerLaw(degreeSeq)
Example #3
0
    def testFitDiscretePowerLaw(self):
        #Test with small x
        x = numpy.array([5])
        ks, alpha2, xmin = Util.fitDiscretePowerLaw(x)

        self.assertEquals(ks, -1)
        self.assertEquals(alpha2, -1)

        x = numpy.array([5, 2])
        ks, alpha2, xmin = Util.fitDiscretePowerLaw(x)

        #Test with a large vector x 
        alpha = 2.5
        exponent = (1/(alpha-1))
        numPoints = 15000
        x = 10*numpy.random.rand(numPoints)**-exponent
        x = numpy.array(numpy.round(x), numpy.int)
        x = x[x<=500]
        x = x[x>=1]

        xmins = numpy.arange(1, 15)

        ks, alpha2, xmin = Util.fitDiscretePowerLaw(x, xmins)
        self.assertAlmostEqual(alpha, alpha2, places=1)
Example #4
0
    def testFitDiscretePowerLaw(self):
        #Test with small x
        x = numpy.array([5])
        ks, alpha2, xmin = Util.fitDiscretePowerLaw(x)

        self.assertEquals(ks, -1)
        self.assertEquals(alpha2, -1)

        x = numpy.array([5, 2])
        ks, alpha2, xmin = Util.fitDiscretePowerLaw(x)

        #Test with a large vector x
        alpha = 2.5
        exponent = (1 / (alpha - 1))
        numPoints = 15000
        x = 10 * numpy.random.rand(numPoints)**-exponent
        x = numpy.array(numpy.round(x), numpy.int)
        x = x[x <= 500]
        x = x[x >= 1]

        xmins = numpy.arange(1, 15)

        ks, alpha2, xmin = Util.fitDiscretePowerLaw(x, xmins)
        self.assertAlmostEqual(alpha, alpha2, places=1)