本文整理汇总了Python中sandbox.util.Util.Util.entropy方法的典型用法代码示例。如果您正苦于以下问题:Python Util.entropy方法的具体用法?Python Util.entropy怎么用?Python Util.entropy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sandbox.util.Util.Util
的用法示例。
在下文中一共展示了Util.entropy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testEntropy
# 需要导入模块: from sandbox.util.Util import Util [as 别名]
# 或者: from sandbox.util.Util.Util import entropy [as 别名]
def testEntropy(self):
v = numpy.array([0, 0, 0, 1, 1, 1])
self.assertEquals(Util.entropy(v), 1)
v = numpy.array([0, 0, 0])
self.assertEquals(Util.entropy(v), 0)
v = numpy.array([1, 1, 1])
self.assertEquals(Util.entropy(v), 0)
示例2: plotTreeStats
# 需要导入模块: from sandbox.util.Util import Util [as 别名]
# 或者: from sandbox.util.Util.Util import entropy [as 别名]
def plotTreeStats():
logging.info("Computing tree stats")
resultsFileName = resultsDir + "InfectGrowthTreeStats.pkl"
if saveResults:
statsDictList = []
for j in range(len(subgraphIndicesList2)):
Util.printIteration(j, 1, len(subgraphIndicesList2))
subgraphIndices = subgraphIndicesList2[j]
subgraph = sGraph.subgraph(subgraphIndices)
logging.info("Finding trees")
trees = subgraph.findTrees()
logging.info("Computing tree statistics")
statsDict = {}
locationEntropy = []
orientEntropy = []
detectionRanges = []
for i in range(len(trees)):
if len(trees[i]) > 1:
treeGraph = subgraph.subgraph(trees[i])
vertexArray = treeGraph.getVertexList().getVertices(list(range(treeGraph.getNumVertices())))
locationEntropy.append(Util.entropy(vertexArray[:, locationIndex]))
orientEntropy.append(Util.entropy(vertexArray[:, orientationIndex]))
detections = vertexArray[:, detectionIndex]
detectionRanges.append(numpy.max(detections) - numpy.min(detections))
statsDict["locationEnt"] = numpy.array(locationEntropy)
statsDict["orientEnt"] = numpy.array(orientEntropy)
statsDict["detectRanges"] = numpy.array(detectionRanges)
statsDictList.append(statsDict)
Util.savePickle(statsDictList, resultsFileName, True)
else:
statsDictList = Util.loadPickle(resultsFileName)
locBins = numpy.arange(0, 2.4, 0.2)
detectBins = numpy.arange(0, 6500, 500)
locationEntDists = []
orientEntDists = []
detectionDists = []
for j in range(0, len(dayList2)):
dateStr = (str(DateUtils.getDateStrFromDay(dayList2[j], startYear)))
logging.info(dateStr)
statsDict = statsDictList[j]
plotInd2 = plotInd
locationEntDists.append(statsDict["locationEnt"])
orientEntDists.append(statsDict["orientEnt"])
detectionDists.append(statsDict["detectRanges"])
#for j in range(len(orientEntDists)):
# print(numpy.sum(numpy.histogram(orientEntDists[j])[0]))
# print(numpy.histogram(orientEntDists[j])[0]/float(orientEntDists[j].shape[0]))
dateStrs = [DateUtils.getDateStrFromDay(dayList2[i], startYear) for i in range(1, len(dayList2))]
plt.figure(plotInd2)
histOut = plt.hist(locationEntDists, locBins, normed=True)
plt.xlabel("Location Entropy")
plt.ylabel("Probability Density")
plt.savefig(figureDir + "LocationEnt" + ".eps")
#plt.legend()
plotInd2 += 1
plt.figure(plotInd2)
histOut = plt.hist(orientEntDists, normed=True)
plt.xlabel("Orientation Entropy")
plt.ylabel("Probability Density")
plt.savefig(figureDir + "OrientEnt" + ".eps")
#plt.legend()
plotInd2 += 1
plt.figure(plotInd2)
histOut = plt.hist(detectionDists, detectBins, normed=True)
plt.xlabel("Detection Range (days)")
plt.ylabel("Probability Density")
plt.savefig(figureDir + "DetectionRanges" + ".eps")
#plt.legend()
plotInd2 += 1