Пример #1
0
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")
Пример #2
0
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)
Пример #3
0
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
Пример #4
0
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
Пример #5
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(carTeamWorkProcess,
                                    zip(range(p.reps), itertools.repeat(p)))
            scoresA.append([t.getBestScore() for t in allTeams])
            teams.append(allTeams)
            print('finished one set: ' + str(timer.time() - t0))
        pool.close()
        pool.join()
    resultMatrix.append(scoresA)
    teamObjects.append(teams)
    print("completed one composition type")
print("time to complete: " + str(timer.time() - t0))

for i in range(3):
Пример #6
0
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))
Пример #7
0
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")
Пример #8
0
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")
Пример #9
0
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")
Пример #11
0

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)
p.agentTeams = m.specializedTeams(p.nAgents,p.nTeams)
p.teamDims = teamDimensions_semantic
   

aiScores = [45,135]
#ts = []
#for k in aiScores:
#    ts.append(teamWorkCustomTeams(0,p,0,k))
#
##request @ 32 nodes 4gb: 800 sec per [100 step simulation of 32 agents x 32 reps ]
##request: 800 sec * 7*3 = 4.7 hours -> request 6 hrs
allSubTeams = []
for teamNo in range(len(teams)):
    compareStyles = []
    for aiScore in aiScores:
        teamObjects = []
        if __name__ == '__main__':# or 'kaboom.test.viii_specialization_composition':
Пример #12
0
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")
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")
Пример #14
0
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")
Пример #15
0
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))