def run(): # A 1.6 composition vs commRate p = Params() p.nAgents = 20 p.nTeams = 4 p.nDims = 20 p.agentTeams = m.specializedTeams(p.nAgents, p.nTeams) p.teamDims = m.teamDimensions(p.nDims, p.nTeams) #np.ones([nTeams,nDims]) #p.reps=1 pComms = np.linspace(0, 1, 11) p.aiScore = 95 #meetingTimes = 100 t0 = timer.time() resultsA16 = [] for i in range(3): if i == 0: #homogeneous p.aiScore = 95 p.aiRange = 0 p.curatedTeams = False elif i == 1: #hetero70 p.aiScore = 95 p.aiRange = 70 p.curatedTeams = True elif i == 2: #organic p.aiScore = None p.aiRange = None p.curatedTeams = False allTeamObjects = [] for pComm in pComms: p.pComm = pComm if __name__ == '__main__' or 'kaboom.designScienceStudies.ix_composition_structure': pool = multiprocessing.Pool(processes=4) allTeams = pool.starmap( teamWorkProcess, zip(range(p.reps), itertools.repeat(p))) print('next. time: ' + str(timer.time() - t0)) for team in allTeams: allTeamObjects.append(team) pool.close() pool.join() resultsA16.append(allTeamObjects) scores = [t.getBestScore() for t in allTeamObjects] pcs = [pc for pc in pComms for i in range(p.reps)] m.plotCategoricalMeans(pcs, np.array(scores) * -1) plt.show() # allTeams = [t for tl in allTeamObjects for t in tl] print("time to complete: " + str(timer.time() - t0)) comps = ['homogeneous', 'heterogeneous70', 'organic'] for i in range(3): allTeamObjects = resultsA16[i] allScores = np.array([t.getBestScore() for t in allTeamObjects]) * -1 nS = [t.nMeetings for t in allTeamObjects] # plt.scatter(nS,allScores, c=[.9,.9,.9]) pC = [pc for pc in pComms for i in range(p.reps)] # plt.show() # plt.scatter(pC,allScores, label=kai) c = m.plotCategoricalMeans(pC, allScores) # name="A1.6_commRate_vStyle_"+comps[i] # directory = saveResults(allTeamObjects,name) plt.legend(comps) myPath = os.path.dirname(__file__) plt.savefig(myPath + "/results/ix_composition_specialization.pdf")
def run(): t0 = timer.time() p = Params() teamSizes = [32] #[8,16,32] nAgentsPerTeam = [1, 2, 3, 4, 8, 16, 32] #range(1,8+1) p.nDims = 32 p.pComm = 0.2 # np.linspace(0,.5,10) #choose one problem (middle, favors mid-range) roughnesses = np.logspace(-1, .7, num=6, base=10) speeds = np.logspace(-1, .7, num=6, base=10) / 100 p.amplitude = roughnesses[3] p.AVG_SPEED = speeds[3] resultMatrixOrganic = [] teamObjectsOrganic = [] for nAgents in teamSizes: p.nAgents = nAgents scoresA = [] teams = [] for subteamSize in nAgentsPerTeam: p.nTeams = int(p.nAgents / subteamSize) p.agentTeams = m.specializedTeams(p.nAgents, p.nTeams) p.teamDims = m.teamDimensions(p.nDims, p.nTeams) if __name__ == '__main__' or 'kaboom.designScienceStudies.iv_specialization_organic': pool = multiprocessing.Pool(processes=4) allTeams = pool.starmap( teamWorkProcess, zip(range(p.reps), itertools.repeat(p))) scoresA.append([t.getBestScore() for t in allTeams]) teams.append(allTeams) pool.close() pool.join() resultMatrixOrganic.append(scoresA) teamObjectsOrganic.append(teams) print("completed one") print("time to complete: " + str(timer.time() - t0)) #plot score vs structure for different team sizes for i in range(len(teamSizes)): nAgents = [ len(team.agents) for teamSet in teamObjectsOrganic[i] for team in teamSet ] nTeams = [ len(team.specializations) for teamSet in teamObjectsOrganic[i] for team in teamSet ] subTeamSize = [ int(len(team.agents) / len(team.specializations)) for teamSet in teamObjectsOrganic[i] for team in teamSet ] teamScore = [ team.getBestScore() for teamSet in teamObjectsOrganic[i] for team in teamSet ] print("Diverse team, size %s in %s dim space: " % (teamSizes[i], p.nDims)) # plt.scatter(subTeamSize,teamScore,label='team size: '+str(teamSizes[i])) invY = np.array(teamScore) * -1 m.plotCategoricalMeans(subTeamSize, invY) plt.xlabel("subteam size") plt.xscale('log', basex=2) plt.xticks([1, 2, 3, 4, 8, 16, 32]) plt.ylabel("performance") # plt.show() plt.legend(teamSizes) #Save results: # np.savetxt("./results/C1.1_organicSpecialization/params.txt",[makeParamString()], fmt='%s') # scoreMatrix = [ [ [t.getBestScore() for t in eachStructure] for eachStructure in eachSize] for eachSize in teamObjectsOrganic] # rFile = './results/C1.1_organicSpecialization/'+'scoreMatrix.obj' # rPickle = open(rFile, 'wb') # pickle.dump(scoreMatrix, rPickle) myPath = os.path.dirname(__file__) plt.savefig(myPath + "/results/iv_specialization_organicTeams.pdf")