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
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 p.curatedTeams = True elif i == 1: p.aiRange = 70 p.aiScore = 95 p.curatedTeams = False
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))
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")
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) print('next')
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'] teamsDict = { i:teams[i] for i in range(10)} 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)
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))