本文整理汇总了Python中sandbox.util.Util.Util.fitDiscretePowerLaw方法的典型用法代码示例。如果您正苦于以下问题:Python Util.fitDiscretePowerLaw方法的具体用法?Python Util.fitDiscretePowerLaw怎么用?Python Util.fitDiscretePowerLaw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sandbox.util.Util.Util
的用法示例。
在下文中一共展示了Util.fitDiscretePowerLaw方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testFitDiscretePowerLaw2
# 需要导入模块: from sandbox.util.Util import Util [as 别名]
# 或者: from sandbox.util.Util.Util import fitDiscretePowerLaw [as 别名]
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)
示例2: testFitDiscretePowerLaw
# 需要导入模块: from sandbox.util.Util import Util [as 别名]
# 或者: from sandbox.util.Util.Util import fitDiscretePowerLaw [as 别名]
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)