def biodiversity(step, worldHistory): '''Simpson's definition of diversity: 1 - (probability of two randomly chosen items being in the same group) ''' creatSpec = Analyse.findSpecies(worldHistory[step][0]) specPops = {} for creat in creatSpec: specPops[creat[1]] = specPops.get(creat[1], 0)+1 arr = np.array(specPops.values(), dtype=float) return 1- (np.sum(arr*(arr-1))/(np.sum(arr)*(np.sum(arr)-1)))
def DisplayFrame(worldFrame, resourcesGRMaxE, mapFile, frameNo): creatSpec = Analyse.findSpecies(worldFrame[0]) if np.max(creatSpec[:,1])==0: colours = np.array(creatSpec[:,1]) else: colours = (np.array(creatSpec[:,1]))/float(np.max(creatSpec[:,1])) Analyse.plotForCreatures(speedReprThreshMouth, 1, 111, worldFrame[0], 'Speed', 'Repr Thresh', 'Mouth Size', 'Genetics Plot in %dth step'%(frameNo+1)) plt.show() if mapFile is not None: Graphics(mapFile=mapFile).DisplaySavedMapFrame(worldFrame, resourcesGRMaxE, frameNo, colours, creatSpec) else: Graphics().DisplaySavedMapFrame(worldFrame, resourcesGRMaxE, frameNo, colours, creatSpec)