def run(): t0 = timer.time() p = Params() #change team size and specialization p.nAgents = 12 p.nTeams = 4 p.nDims = 12 p.agentTeams = m.specializedTeams(p.nAgents, p.nTeams) p.teamDims = m.teamDimensions(p.nDims, p.nTeams) pComms = np.linspace(0, 1, 6) roughnesses = np.logspace(-1, .7, num=6, base=10) p.amplitude = roughnesses[3] speeds = np.logspace(-1, .7, num=6, base=10) / 100 p.AVG_SPEED = speeds[3] allTeamObjects = [] for pComm in pComms: if __name__ == '__main__' or 'kaboom.designScienceStudies.i_optimalCommRate': 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() print('finished one communication frequency') else: print(__name__) # allTeams = [t for tl in allTeamObjects for t in tl] print("time to complete: " + str(timer.time() - t0)) #save results object to file # name="sharingRate" # directory = saveResults(allTeamObjects,name) r = allTeamObjects pC = [prob for prob in pComms for i in range(p.reps)] perf = np.array([t.getBestScore() for t in r]) * -1 nMeetings = [t.nMeetings for t in r] plt.scatter(pC, perf, c=[.9, .9, .9]) m.plotCategoricalMeans(pC, perf) plt.xlabel('prob of communication (c)') plt.ylabel('performance') myPath = os.path.dirname(__file__) plt.savefig(myPath + "/results/i_communicationFrequency.pdf") plt.show() #alternatively, plot performance vs the actual number of pairwise interactions plt.scatter(nMeetings, perf)
def run(): # # A 3.1 # ## Frequency of team meetings t0 = timer.time() 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.curatedTeams = True varyMeetingTimes = [int(p.steps / i) for i in range(1, 10)] varyMeetingTimes.append(100000) meetingStartTimes = [] for meetingTimes in varyMeetingTimes: p.meetingTimes = meetingTimes print("meeting interval: " + str(meetingTimes)) if __name__ == '__main__' or 'kaboom.designScienceStudies.iii_teamMeetings': pool = multiprocessing.Pool(processes=4) allTeams = pool.starmap(teamWorkProcess, zip(range(p.reps), itertools.repeat(p))) pool.close() pool.join() print('next') meetingStartTimes.append(allTeams) print("time to complete: " + str(timer.time() - t0)) allTeams = [t for tt in meetingStartTimes for t in tt] #directory = m.saveResults(allTeams,'numberOfTeamMeetings') teamScores = [t.getBestScore() for t in allTeams] teamScoresGrouped = [[t.getBestScore() for t in tt] for tt in meetingStartTimes] nMeetings = [t.nTeamMeetings for tt in meetingStartTimes for t in tt] perf = np.array(teamScores) * -1 plt.scatter(nMeetings, perf, c=[.9, .9, .9]) means = m.plotCategoricalMeans(nMeetings, perf) plt.xlabel("number of team meetings") plt.ylabel("performance") slope, intercept, r_value, p_value, std_err = scipy.stats.linregress( nMeetings, teamScores) x = np.linspace(0, 10, 10) plt.plot(x, (x * slope + intercept) * -1) myPath = os.path.dirname(__file__) plt.savefig(myPath + "/results/iii_team_meetings_" + str(timer.time()) + ".pdf")
def runBeamDesignProblem(): """ Run an example case of the beam designer problem """ p = Params() p.nAgents = 8 p.nDims = 4 p.nTeams = 2 p.reps = 32 p.steps = 100 p.agentTeams = m.specializedTeams(p.nAgents, p.nTeams) p.teamDims = m.teamDimensions(p.nDims, p.nTeams) t = teamWorkSharing(p, BeamDesigner) return t
def run(): t0 = timer.time() p = Params() # p.reps=2 # selfBias = 0.5 # curatedTeams = False # shareAcrossTeams = True #change team size and specialization p.nAgents = 12 p.nTeams = 4 p.nDims = 56 p.agentTeams = m.specializedTeams(p.nAgents, p.nTeams) p.teamDims = m.teamDimensions(p.nDims, p.nTeams) p.reps = 16 p.steps = 500 pComms = np.linspace(0, 1, 6) allTeamObjects = [] for pComm in pComms: if __name__ == '__main__' or 'kaboom.designScienceStudies.i_optimalCommRate': pool = multiprocessing.Pool(processes=16) allTeams = pool.starmap(carTeamWorkProcess, 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() print('finished a pComm round') else: print(__name__) # allTeams = [t for tl in allTeamObjects for t in tl] print("time to complete: " + str(timer.time() - t0)) # name="nShares_long_smallTeam" # directory = saveResults(allTeamObjects,name) # plt.savefig(directory+"/"+name+".pdf") # plt.savefig(directory+"/"+name+".png",dpi=300) return allTeamObjects, pComms, p
def run(): """ Experiment to test how KAI style affects car design performance and beam design performance """ t0 = timer.time() p = Params() #change team size and specialization p.nAgents = 33 p.nDims = 56 p.steps = 100 p.reps = 16 myPath = os.path.dirname(__file__) parentPath = os.path.dirname(myPath) paramsDF = pd.read_csv(parentPath + "/SAE/paramDBreduced.csv") paramsDF = paramsDF.drop(["used"], axis=1) paramsDF.head() teams = ['brk', 'c', 'e', 'ft', 'fw', 'ia', 'fsp', 'rsp', 'rt', 'rw', 'sw'] paramTeams = paramsDF.team p.nTeams = len(teams) #in the semantic division of the problem, variables are grouped by parts of #the car (eg, wheel dimensions; engine; brakes) teamDimensions_semantic = [[ 1 if paramTeam == thisTeam else 0 for paramTeam in paramTeams ] for thisTeam in teams] p.agentTeams = m.specializedTeams(p.nAgents, p.nTeams) p.teamDims = teamDimensions_semantic styleTeams = [] flatTeamObjects = [] aiScores = np.linspace(45, 145, 9) for aiScore in aiScores: #use a homogeneous team with KAI style of [aiScore] p.aiScore = aiScore p.aiRange = 0 teamObjects = [] #save results if __name__ == '__main__' or 'kaboom.IDETC_STUDIES.i_teamStyle': pool = multiprocessing.Pool(processes=4) allTeams = pool.starmap( carTeamWorkProcess, zip(range(p.reps), itertools.repeat(p), itertools.repeat(CarDesignerWeighted))) for t in allTeams: teamObjects.append(t) flatTeamObjects.append(t) pool.close() pool.join() print("time to complete: " + str(timer.time() - t0)) styleTeams.append(teamObjects) # saveResults(flatTeamObjects, p, "carProblem_KaiStyle") #invert the scores *-1 to show a maximization (rather than minimization) #objective. (Then, in this plot, higher scores are better) allScores = [t.getBestScore() * -1 for s in styleTeams for t in s] allkai = [kai for kai in aiScores for i in range(p.reps)] m.plotCategoricalMeans(allkai, allScores) plt.scatter(allkai, allScores, c=[0.9, 0.9, 0.9]) qFit = np.polyfit(allkai, allScores, 2) q = np.poly1d(qFit) x = np.linspace(45, 145, 100) plt.plot(x, q(x), c='red') plt.xticks([int(i) for i in aiScores]) plt.xlabel("KAI score of homogeneous team") plt.ylabel("Car Design Performance") plt.savefig(myPath + '/results/i_teamStyle_carProblem.pdf') plt.clf() #Now test the performance on the beam design problem p = Params() p.nAgents = 8 p.nDims = 4 p.nTeams = 2 p.reps = 16 p.steps = 100 p.agentTeams = m.specializedTeams(p.nAgents, p.nTeams) p.teamDims = m.teamDimensions(p.nDims, p.nTeams) beamTeams = [] for aiScore in aiScores: teamSet = [] for i in range(p.reps): t = teamWorkSharing(p, BeamDesigner) teamSet.append(t) beamTeams.append(teamSet) print('next') #flip scores so that higher is better in the plot allScores = [[t.getBestScore() * -1 for t in teams] for teams in beamTeams] allAiScores = [ai for ai in aiScores for i in range(p.reps)] allScoresFlat = [s for r in allScores for s in r] plt.scatter(allAiScores, allScoresFlat, c=[.9, .9, .9]) m.plotCategoricalMeans(allAiScores, allScoresFlat) #quadratic fit qm = np.polyfit(allAiScores, allScoresFlat, 2) qmodel = np.poly1d(qm) x = np.linspace(45, 145, 101) plt.plot(x, qmodel(x), c='red') plt.xlabel("KAI score of homogeneous team") plt.ylabel("Beam Design Performance") plt.savefig(myPath + '/results/i_teamStyle_beamProblem.pdf') plt.show() plt.clf() print("Results figure saved to " + myPath + "/results/i_teamStyle_beamProblem.pdf")
def run(): t0 = timer.time() p = Params() #change team size and specialization p.nAgents = 12 p.nTeams = 4 p.nDims = 12 p.agentTeams = m.specializedTeams(p.nAgents, p.nTeams) p.teamDims = m.teamDimensions(p.nDims, p.nTeams) pComms = np.linspace(0, 1, 11) p.reps = 32 # 10 #$40 #5 aiScores = [60, 95, 130] #100#300 p.aiRange = 0 # aiRanges = np.linspace(0,100,10) # meetingTimes = 100 resultsA14 = [] for aiScore in aiScores: p.aiScore = aiScore allTeamObjects = [] for pComm in pComms: if __name__ == '__main__' or 'kaboom.designScienceStudies.ii_comm_v_style': 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() resultsA14.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)) for allTeamObjects in resultsA14: allScores = np.array([t.getBestScore() for t in allTeamObjects]) * -1 kai = allTeamObjects[0].agents[0].kai.KAI 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) plt.plot(pComms, c) # name="A1.5_commRate_vStyle32_kai"+str(kai) # directory = saveResults(allTeamObjects,name) plt.legend(aiScores) plt.xlabel('prob of communication (c)') plt.ylabel('performance') myPath = os.path.dirname(__file__) plt.savefig(myPath + "/results/ii_commRate_vStyle32_plot.pdf")
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(): 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]) pComms = np.linspace(0, 1, 11) p.aiScore = 95 t0 = timer.time() p = Params() # selfBias = 0.5 # curatedTeams = False # shareAcrossTeams = True p.nAgents = 16 #Homogeneous teams p.nDims = 16 p.aiScore = 100 #300 p.aiRange = 0 #p.reps = 1#8 scoreForNteams = [] for nTeams in [1, 2, 4, 8, 16]: p.nTeams = nTeams p.agentTeams = m.specializedTeams(p.nAgents, p.nTeams) p.teamDims = m.teamDimensions(p.nDims, p.nTeams) pComms = np.linspace(0, 1, 6) meetingTimes = 100 allTeamObjects = [] for pComm in pComms: if __name__ == '__main__' or 'kaboom.designScienceStudies.x_specialization_communication': pool = multiprocessing.Pool(processes=4) allTeams = pool.starmap( teamWorkProcess, zip(range(p.reps), itertools.repeat(p))) print('next. time: ' + str(timer.time() - t0)) allTeamObjects.append(allTeams) # allTeams = [t for tl in allTeamObjects for t in tl] scoreForNteams.append(allTeamObjects) print("time to complete: " + str(timer.time() - t0)) teamShapes = [1, 2, 4, 8, 16] for i in range(len(teamShapes)): nT = scoreForNteams[i] print(np.shape(nT[0:-1])) allTeams = [t for s in nT for t in s] # directory = saveResults(allTeams,'collabTradeoff_'+str(teamShapes[i])+'_team') allScores = np.array( [t.getBestScore() for set in nT[0:-1] for t in set]) * -1 pC = [pc for pc in pComms[0:-1] for i in range(p.reps)] m.plotCategoricalMeans(pC, allScores) plt.legend([ 'flat team of 16', '2 subteams of 8', '4 subteams of 4', '8 subteams of 8', '16 subteams of 1' ]) myPath = os.path.dirname(__file__) plt.savefig(myPath + "/results/x_communication_structure.pdf")
def run(): t0 = timer.time() p = Params() p.curatedTeams = True # pComm = 0.2 # np.linspace(0,.5,10) aiScores = np.linspace(60, 140, 7) p.aiRange = 0 #pick 5 logarithmically spaced values of roughness (amplitude) and speed roughnesses = np.logspace(-1, .7, num=6, base=10) roughnesses = roughnesses[1:] speeds = np.logspace(-1, .7, num=6, base=10) / 100 speeds = speeds[1:] count = 1 roughness_ai_speed_matrix = [] for i in range(len(roughnesses)): p.amplitude = roughnesses[i] #,8,16,32,64]: ai_speed_matrix = [] for j in range(len(speeds)): p.AVG_SPEED = speeds[j] scoresForAI = [] teams = [] for aiScore in aiScores: p.aiScore = aiScore if __name__ == '__main__' or 'kaboom.designScienceStudies.vi_problem_matrix': pool = multiprocessing.Pool(processes=4) allTeams = pool.starmap( teamWorkProcess, zip(range(p.reps), itertools.repeat(p))) scoresForAI.append([t.getBestScore() for t in allTeams]) for t in allTeams: teams.append(t) pool.close() pool.join() ai_speed_matrix.append(scoresForAI) print("completed %s" % count) count += 1 roughness_ai_speed_matrix.append(ai_speed_matrix) print("time to complete: " + str(timer.time() - t0)) # In[416]: # #f = open('/Users/samlapp/SAE_ABM/results/B1_matrix_of_problems/ProblemMatrixScores.obj','rb') #roughness_ai_speed_matrix = pickle.load(f) #np.shape(roughness_ai_speed_matrix) #aiScores = np.linspace(60,140,7) #aiRanges = np.linspace(0,50,5) #reps = 8 # In[420]: index = 0 for i in range(len(roughness_ai_speed_matrix)): r = roughness_ai_speed_matrix[i] for j in range(len(r)): index += 1 plt.subplot(len(roughness_ai_speed_matrix), len(r), index) s = r[j] allScores = [sc for row in s for sc in row] allScores = np.array(allScores) * -1 myKai = [ai for ai in aiScores for i in range(p.reps)] # plt.scatter(myKai,allScores,c=[.9,.9,.9]) # plotCategoricalMeans(myKai,allScores) pl = np.polyfit(myKai, allScores, 2) z = np.poly1d(pl) x1 = np.linspace(min(myKai), max(myKai), 100) plt.plot(x1, z(x1), color='red') # print(roughnesses[i]) # plt.title("roughness %s speed %s" % (roughnesses[i], speeds[i])) # plt.show() # break plt.savefig('./results/vi_problemMatrixDetail' + str(timer.time()) + '.pdf') # In[29]: index = 0 bestScoreImg = np.zeros([len(roughnesses), len(speeds)]) for i in range(len(roughness_ai_speed_matrix)): r = roughness_ai_speed_matrix[i] for j in range(len(r)): index += 1 s = r[j] allScores = [sc for row in s for sc in row] myKai = [ai for ai in aiScores for i in range(p.reps)] # plt.scatter(myKai,allScores,c=[.9,.9,.9]) # plotCategoricalMeans(myKai,allScores) pl = np.polyfit(myKai, allScores, 2) z = np.poly1d(pl) x1 = np.linspace(min(myKai), max(myKai), 100) y = z(x1) bestScore = round(x1[np.argmin(y)]) bestScoreImg[i, j] = bestScore # plt.plot(x1,z(x1),color='red') # plt.title("roughness %s speed %s" % (roughnesses[i], speeds[i])) # plt.show() # break plt.subplot(1, 1, 1) cmapRB = matplotlib.colors.LinearSegmentedColormap.from_list( "", ["blue", "red"]) plt.imshow(bestScoreImg, cmap=cmapRB) plt.xlabel('decreasing solution space size') plt.ylabel('decreasing amplitude of objective function sinusoid') plt.colorbar() myPath = os.path.dirname(__file__) plt.savefig(myPath + "/results/vi_matrixOfProblems_bestStyle.pdf")
def run(): #Strategy 4: Homogenous teams of 3 styles t0 = timer.time() p=Params() # teamSizes =[32] p.nAgents = 32 nAgentsPerTeam = [32,16,8,4,3,2,1] # nTeams = [1,2,4,8,16,32] p.nDims = 32 #p.reps=1 # choose one Team allocation strategy p.aiRange = 0#0 aiScores = [55,95,135]#140# 300 #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] resultMatrixH3 = [] teamObjectsH3 = [] for aiScore in aiScores: p.aiScore = aiScore 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.v_structure_style': 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() resultMatrixH3.append(scoresA) teamObjectsH3.append(teams) print("completed one") print("time to complete: "+str(timer.time()-t0)) # In[ ]: #plot score vs structure for different team sizes for i in range(len(aiScores)): nAgents = [len(team.agents) for teamSet in teamObjectsH3[i] for team in teamSet] nTeams = [len(team.specializations) for teamSet in teamObjectsH3[i] for team in teamSet] subTeamSize = [int(len(team.agents)/len(team.specializations)) for teamSet in teamObjectsH3[i] for team in teamSet] teamScore = [team.getBestScore() for teamSet in teamObjectsH3[i] for team in teamSet] # print("homgeneous team, size %s in %s dim space: " % (teamSizes[i],nDims)) # plt.scatter(subTeamSize,teamScore,label='team size: '+str(teamSizes[i])) m.plotCategoricalMeans(subTeamSize,np.array(teamScore)*-1) # plt.xscale('log') plt.xlabel("subteam size") plt.xticks(nAgentsPerTeam) plt.ylabel("performance") # plt.show() plt.legend(aiScores) plt.title("homogeneous team of 3 styles") #np.savetxt("./results/C_3homog/params.txt",[makeParamString()], fmt='%s') #scoreMatrix = [ [ [t.getBestScore() for t in eachStructure] for eachStructure in eachStyle] for eachStyle in teamObjectsH3] #rFile = './results/C_3homog/'+'scoreMatrix_homo_3styles_32.obj' #rPickle = open(rFile, 'wb') #pickle.dump(scoreMatrix, rPickle) myPath = os.path.dirname(__file__) plt.savefig(myPath+"/results/v_structure_3styles.pdf")
import os import matplotlib.pyplot as plt import time as timer import pickle from kaboom import helperFunctions as h from kaboom.params import Params from kaboom import kaiStyle as kai from kaboom.agent import Steinway from kaboom.team import Team #our virtual population of KAI scores kaiPopulation = kai.makeKAI(100000) #create defaults parameters Params object defaultParams = Params() class Result: """ A Results object stores results of the simulation for one team. Only the best score, best final score, number of meetings, and agent KAI scores are retained. Other information is discarded. """ def __init__(self): self.bestScore = np.inf self.bestCurrentScore = np.inf self.nMeetings = 0 self.agentKAIs = [] def saveResults(teams,p,dirName='',url='./results'):
def run(): t0 = timer.time() p=Params() p.nAgents = 32 nAgentsPerTeam = [1,2,3,4,8,16,32]#[32,16]# [8,4,3,2,1] p.nDims = 32 p.reps = 32 #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] resultMatrix = [] teamObjects = [] for i in range(3): if i == 0: #homogeneous p.aiRange = 0 p.aiScore = 95 p.curatedTeams = True elif i == 1: p.aiRange = 70 p.aiScore = 95 p.curatedTeams = False elif i == 2: p.aiScore = None p.aiRange = None p.curatedTeams = False 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.viii_specialization_composition': 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() resultMatrix.append(scoresA) teamObjects.append(teams) print("completed one") print("time to complete: "+str(timer.time()-t0)) for i in range(3): nAgents = [len(team.agents) for teamSet in teamObjects[i] for team in teamSet] nTeams = [len(team.specializations) for teamSet in teamObjects[i] for team in teamSet] subTeamSize = [int(len(team.agents)/len(team.specializations)) for teamSet in teamObjects[i] for team in teamSet] teamScore = [team.getBestScore() for teamSet in teamObjects[i] for team in teamSet] print("Diverse team, size %s in %s dim space: " % (32,p.nDims)) # plt.scatter(subTeamSize,teamScore,label='team size: '+str(teamSizes[i])) m.plotCategoricalMeans(subTeamSize,np.array(teamScore)*-1) plt.xlabel("subteam size") # plt.xticks([1,4,8,16,32]) plt.ylabel("performance") # plt.show() plt.legend(['homogeneous','heterogeneous70','organic']) plt.title("composition vs structure") myPath = os.path.dirname(__file__) plt.savefig(myPath+"/results/viii_structure_composition.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")
def run(numberOfCores=4): t0 = timer.time() p = Params() #change team size and specialization p.nAgents = 33 p.nDims = 56 p.steps = 100 #100 p.reps = 16 myPath = os.path.dirname(__file__) parentPath = os.path.dirname(myPath) paramsDF = pd.read_csv(parentPath + "/SAE/paramDBreduced.csv") paramsDF = paramsDF.drop(["used"], axis=1) paramsDF.head() teams = ['brk', 'c', 'e', 'ft', 'fw', 'ia', 'fsp', 'rsp', 'rt', 'rw', 'sw'] teamsDict = {i: teams[i] for i in range(10)} paramTeams = paramsDF.team p.nTeams = len(teams) #in the semantic division of the problem, variables are grouped by parts of #the car (eg, wheel dimensions; engine; brakes) teamDimensions_semantic = [[ 1 if paramTeam == thisTeam else 0 for paramTeam in paramTeams ] for thisTeam in teams] p.agentTeams = m.specializedTeams(p.nAgents, p.nTeams) p.teamDims = teamDimensions_semantic if __name__ == '__main__' or 'kaboom.IDETC_studies.iv_problemDecomposition': pool = multiprocessing.Pool(processes=4) teamObjectsSemantic = pool.starmap( carTeamWorkProcess, zip(range(p.reps), itertools.repeat(p), itertools.repeat(CarDesignerWeighted))) pool.close() pool.join() print("finished semantic: " + str(timer.time() - t0)) # name="allocation_semantic" # directory = saveResults(teamObjectsSemantic,p,name) #NOW WITH BLIND TEAM DIMENSIONS INSTEAD OF SEMANTIC #assign dimensions blindly to teams,with even # per team (as possible) teamDimensions_blind = m.teamDimensions(p.nDims, p.nTeams) p.teamDims = teamDimensions_blind if __name__ == '__main__' or 'kaboom.IDETC_studies.iv_problemDecomposition': pool = multiprocessing.Pool(processes=numberOfCores) teamObjectsBlind = pool.starmap( carTeamWorkProcess, zip(range(p.reps), itertools.repeat(p), itertools.repeat(CarDesignerWeighted))) pool.close() pool.join() # name="allocation_blind" # directory = saveResults(teamObjectsBlind,p,name) print("finished blind: " + str(timer.time() - t0)) #inverted scores so that its a maximization problem #(in the plot, higher scores are better) semanticScores = [t.getBestScore() * -1 for t in teamObjectsSemantic] blindScores = [t.getBestScore() * -1 for t in teamObjectsBlind] #Plot results: plt.boxplot([semanticScores, blindScores], labels=["semantic", "blind"], showfliers=True) plt.ylabel("car design performance") plt.savefig(myPath + "/results/iv_problemDecomposition.pdf") plt.show() plt.clf() print("Results figure saved to " + myPath + "/results/iv_problemDecomposition.pdf") print("effect size:") print(h.effectSize(semanticScores, blindScores)) print("ANOVA p score: ") print(h.pScore(semanticScores, blindScores))
myTeam.nMeetings += myTeam.step(p) score = myTeam.getBestCurrentScore() #getBestCurrentScore myTeam.scoreHistory.append(score) if (i+1)%p.meetingTimes == 0: cost = myTeam.haveInterTeamMeeting(p) i += cost #TEAM_MEETING_COST i += 1 return myTeam # Do certain sub-teams have style preference adaptive/innovative? t0 = timer.time() p=Params() #change team size and one sub-teams style: p.nAgents = 33 p.nDims = 56 p.steps = 100 #100 p.reps = 4#16 myPath = os.path.dirname(__file__) paramsDF = pd.read_csv("../SAE/paramDBreduced.csv") paramsDF = paramsDF.drop(["used"],axis=1) paramsDF.head() #assign the actual specialized teams: teams = ['brk', 'c', 'e', 'ft', 'fw', 'ia','fsp','rsp', 'rt', 'rw', 'sw']
#import pickle import itertools #parameters for KABOOM #import kaboom from kaboom.params import Params from kaboom import modelFunctions as m #from kaboom.kaboom import teamWorkProcess from kaboom.carMakers import carTeamWorkProcess # Structure vs Composition # Optimal structure of 32-agent team for 3 allocation strategies t0 = timer.time() p = Params() #change team size and specialization p.nAgents = 16 #32 p.nDims = 56 p.steps = 3 #00 p.reps = 4 nAgentsPerTeam = [1, 2, 3, 4] #,8,16,32]#[32,16]# [8,4,3,2,1] resultMatrix = [] teamObjects = [] for i in range(3): #range(3): if i == 0: #homogeneous p.aiRange = 0 p.aiScore = 95
import numpy as np from matplotlib import pyplot as plt from kaboom import helperFunctions as h from kaboom import modelFunctions as m import itertools import os from kaboom.params import Params from kaboom import modelFunctions as m from kaboom.kaboom import teamWorkSharing p= Params() p.nAgents = 8 p.nDims = 4 p.nTeams = 2 p.reps = 32 p.steps = 50 #p.steps = 50 p.agentTeams = m.specializedTeams(p.nAgents,p.nTeams) p.teamDims = m.teamDimensions(p.nDims,p.nTeams) aiScores = np.linspace(45,145,9) allScores = [] for aiScore in aiScores: scores = [] for i in range(p.reps): t= teamWorkSharing(p,BeamDesigner) scores.append(t.getBestScore()) allScores.append(scores)
def run(): # ## B 2.3 # Robustness on two diagonals # # PROBLEM SET 1 #problems favor a range of styles from adaptive to mid to innovative t0 = timer.time() p = Params() p.curatedTeams = True p.reps = 32 allTeams = [] allTeamScores = [] p.aiScore = 100 aiRanges = np.linspace(0, 100, 6) # pComm = 0.2 #the diagonal across preferred style: roughnesses = np.logspace(-1, .7, num=6, base=10) #[.2,.6,1.8,5.4] roughnesses = roughnesses[1:] speeds = np.logspace(-1, .7, num=6, base=10) / 100 # [.001,.004,.016,.048] speeds = speeds[1:] problemSet = [roughnesses, speeds] for aiRange in aiRanges: p.aiRange = aiRange teams = [] teamScores = [] for i in range(p.reps): scores, t = robustnessTest(p, problemSet) teams.append(t) teamScores.append(scores) allTeams.append(teams) allTeamScores.append(teamScores) print('next') print('time: %s' % (timer.time() - t0)) # #teams = [ t for tt in allTeams for t in tt] #directory = saveResults(teams,'robustnessTest_diag1') #rFile = directory+'/'+'scoreMatrix.obj' #rPickle = open(rFile, 'wb') #pickle.dump(allTeamScores,rPickle) # f = open('/Users/samlapp/SAE_ABM/results/1542634807.0205839robustnessTest/scoreMatrix.obj','rb') # sm = pickle.load(f) # In[67]: #STADARDIZE for each problem! ats = np.array(allTeamScores) problemMeans = [np.mean(ats[:, :, i]) for i in range(len(problemSet[0]))] problemSds = [np.std(ats[:, :, i]) for i in range(len(problemSet[0]))] allTeamScoresStandardized = ats for j in range(len(allTeamScoresStandardized)): for i in range(len(problemSet[0])): for k in range(p.reps): allTeamScoresStandardized[ j, k, i] = (ats[j, k, i] - problemMeans[i]) / problemSds[i] np.shape(allTeamScoresStandardized) meanScores = [ np.mean(t) for teamSet in allTeamScoresStandardized for t in teamSet ] meanGrouped = [[np.mean(t) for t in teamSet] for teamSet in allTeamScoresStandardized] sdScores = [ np.std(t) for teamSet in allTeamScoresStandardized for t in teamSet ] sdGrouped = [[np.std(t) for t in teamSet] for teamSet in allTeamScoresStandardized] ranges = [t.dAI for teamSet in allTeams for t in teamSet] robustness = np.array(meanScores) - np.array(sdScores) robustnessGrouped = np.array(meanGrouped) - np.array(sdGrouped) # meanScores = np.array(meanScores)*-1 plt.scatter(ranges, np.array(meanScores), c=[.9, .9, .9]) # plt.title("9 problem matrix") cms = m.plotCategoricalMeans(ranges, meanScores) #plt.savefig('results/vii_set1_robustnessInv.pdf') stat, pscore = scipy.stats.ttest_ind(meanGrouped[0], meanGrouped[2]) print("significance: p= " + str(pscore)) corr, _ = scipy.stats.pearsonr(ranges[0:p.reps * 4], meanScores[0:p.reps * 4]) print('Pearsons correlation: %.3f' % corr) # In[2] # PROBLEM SET 2 # Now the other diagonal (all 5 problems prefer mid-range style) allTeamsD2 = [] allTeamScoresD2 = [] # aiScore = 100 aiRanges = np.linspace(0, 100, 6) #the diagonal across preferred style: roughnesses = np.logspace(-1, .7, num=6, base=10) #[.2,.6,1.8,5.4] roughnesses = roughnesses[1:] speeds = np.logspace(-1, .7, num=6, base=10) / 100 # [.001,.004,.016,.048] speeds = speeds[1:] #reverse the order: pair large speed (small space) with small roughness speeds = speeds[::-1] problemSet = [roughnesses, speeds] for aiRange in aiRanges: p.aiRange = aiRange teams = [] teamScores = [] for i in range(p.reps): scores, t = robustnessTest(p, problemSet) teams.append(t) teamScores.append(scores) allTeamsD2.append(teams) allTeamScoresD2.append(teamScores) print('next') print('time: %s' % (timer.time() - t0)) #teams = [ t for tt in allTeamsD2 for t in tt] #directory = saveResults(teams,'robustnessTest_diag2') #rFile = directory+'/'+'scoreMatrix.obj' #rPickle = open(rFile, 'wb') #pickle.dump(allTeamScores,rPickle) # f = open('/Users/samlapp/SAE_ABM/results/1542634807.0205839robustnessTest/scoreMatrix.obj','rb') # sm = pickle.load(f) #STADARDIZE for each problem! ats = np.array(allTeamScoresD2) problemMeans = [np.mean(ats[:, :, i]) for i in range(len(problemSet[0]))] problemSds = [np.std(ats[:, :, i]) for i in range(len(problemSet[0]))] allTeamScoresStandardized = ats for j in range(len(allTeamScoresStandardized)): for i in range(len(problemSet[0])): for k in range(p.reps): allTeamScoresStandardized[ j, k, i] = (ats[j, k, i] - problemMeans[i]) / problemSds[i] np.shape(allTeamScoresStandardized) meanScoresD2 = [ np.mean(t) for teamSet in allTeamScoresStandardized for t in teamSet ] meanGroupedD2 = [[np.mean(t) for t in teamSet] for teamSet in allTeamScoresStandardized] sdScoresD2 = [ np.std(t) for teamSet in allTeamScoresStandardized for t in teamSet ] sdGroupedD2 = [[np.std(t) for t in teamSet] for teamSet in allTeamScoresStandardized] ranges = [t.dAI for teamSet in allTeams for t in teamSet] # robustness = np.array(meanScores)-np.array(sdScores) # robustnessGrouped = np.array(meanGrouped)-np.array(sdGrouped) #flip the scores meanScoresD2 = np.array(meanScoresD2) * -1 plt.scatter(ranges, np.array(meanScoresD2), c=[.9, .9, .9]) cms = m.plotCategoricalMeans(ranges, np.array(meanScoresD2)) stat, p = scipy.stats.ttest_ind(meanGroupedD2[0], meanGroupedD2[3]) print("significance: p= " + str(p)) corr, _ = scipy.stats.pearsonr(ranges[0:p.reps * 4], meanScoresD2[0:p.reps * 4]) print('Pearsons correlation: %.3f' % corr) # plt.scatter(ranges,np.array(meanScoresD2),c=[.9,.9,.9]) cms = m.plotCategoricalMeans(ranges, np.array(meanScoresD2)) cms2 = m.plotCategoricalMeans(ranges, np.array(meanScores)) plt.xlabel('maximum cognitive gap (style diversity)') plt.ylabel('performance') plt.legend(['probem set 1', 'problem set 2']) myPath = os.path.dirname(__file__) plt.savefig(myPath + "/results/vii_diverseTeams_2problemsets.pdf")
def run(numberOfCores=4): t0 = timer.time() p = Params() #change team size and one sub-teams style: p.nAgents = 33 p.nDims = 56 p.steps = 100 #100 p.reps = 16 #organic composition: select agents randomly from population p.aiScore = None p.aiRange = None myPath = os.path.dirname(__file__) parentDir = os.path.dirname(myPath) paramsDF = pd.read_csv(parentDir + "/SAE/paramDBreduced.csv") paramsDF = paramsDF.drop(["used"], axis=1) paramsDF.head() #assign the actual specialized teams: teams = ['brk', 'c', 'e', 'ft', 'fw', 'ia', 'fsp', 'rsp', 'rt', 'rw', 'sw'] paramTeams = paramsDF.team p.nTeams = len(teams) teamDimensions_semantic = [[ 1 if paramTeam == thisTeam else 0 for paramTeam in paramTeams ] for thisTeam in teams] #teamDimensions_blind = m.specializedTeams(p.nAgents,p.nTeams) p.agentTeams = m.specializedTeams(p.nAgents, p.nTeams) p.teamDims = teamDimensions_semantic #First run the control group: teams with organic composition if __name__ == '__main__' or 'kaboom.IDETC_studies.iii_strategicTeams': pool = multiprocessing.Pool(processes=numberOfCores) controlTeams = pool.starmap( carTeamWorkProcess, zip(range(p.reps), itertools.repeat(p), itertools.repeat(CarDesignerWeighted))) # scoresA.append([t.getBestScore() for t in allTeams]) # teams.append(allTeams) pool.close() pool.join() controlScores = [t.getBestScore() * -1 for t in controlTeams] #Run strategic teams subteamsSortedByStyle = [7, 8, 0, 10, 3, 2, 6, 4, 1, 5, 9] # namedSortedTeams = [teams[i] for i in subteamsSortedByStyle] strategicTeamObjects = [] if __name__ == '__main__' or 'kaboom.IDETC_studies.iii_strategicTeams': pool = multiprocessing.Pool(processes=4) allTeams = pool.starmap( teamWorkOrganicSuperteam, zip(range(p.reps), itertools.repeat(p), itertools.repeat(subteamsSortedByStyle))) # scoresA.append([t.getBestScore() for t in allTeams]) # teams.append(allTeams) for t in allTeams: strategicTeamObjects.append(t) pool.close() pool.join() print("time to complete: " + str(timer.time() - t0)) strategicScores = [t.getBestScore() * -1 for t in strategicTeamObjects] plt.boxplot([np.array(controlScores), np.array(strategicScores)], labels=["control", "strategic allocation"], showfliers=True) plt.ylabel("car design performance") plt.savefig(myPath + "/results/iii_carStrategicTeamAssignment.pdf") plt.show() plt.clf() print("Results figure saved to " + myPath + "/results/iii_carStrategicTeamAssignment.pdf") print("effect size:") print(h.effectSize(controlScores, strategicScores)) print("ANOVA p score: ") print(h.pScore(controlScores, strategicScores))