예제 #1
0
def showResults(allTeamObjects, pComms, p):

    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, c=[.9, .9, .9])
    c = m.plotCategoricalMeans(pC, allScores)

    #domain = m.saveResults(allTeamObjects,"A1.1_sharingRate_12agents")

    # reload results
    # domain = '/Users/samlapp/SAE_ABM/results/A1.1_optimalSharingRate_long_largerTeam'
    # f = open(domain+'/results.obj','rb')
    # r = pickle.load(f)
    # pComms = np.linspace(0,1,6)
    # reps = 16
    # r0 = r[0]

    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')
    #    plt.savefig('./pcomm.pdf')
    plt.show()
예제 #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 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 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")
예제 #5
0
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")
#    plt.savefig('./results/viii_structure_composition.pdf')

#    return teamObjects
예제 #6
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")
예제 #7
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")
예제 #8
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")
예제 #10
0
        t= teamWorkSharing(p,BeamDesigner)
        scores.append(t.getBestScore())
    allScores.append(scores)
    print('next')


allScoresFlipped = np.array(allScores)*-1
allAiScores = [ai for ai in aiScores for i in range(p.reps)]
allScoresFlat= [ s for r in allScoresFlipped for s in r]
for i,aiScore in enumerate(aiScores):
    plt.scatter(np.ones(p.reps)*aiScore, allScoresFlipped[i])
    

plt.scatter(allAiScores,allScoresFlat,c=[.9,.9,.9])
    
m.plotCategoricalMeans(allAiScores,allScoresFlat)

qm = np.polyfit(allAiScores,allScoresFlat, 2)
qmodel = np.poly1d(qm)
x = np.linspace(45,145,101)
y = qmodel(x)
bestStyle = x[np.argmin(y)]
print("Best style:" +str(bestStyle))
plt.plot(x, qmodel(x))
#plt.ylim([-17,-14])
    
plt.savefig("/Users/samlapp/SAE_ABM/figs/beamDesigners_quadratic.pdf")


#for each pair
for pair in itertools.combinations(range(len(allScores)),2):
예제 #11
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")
예제 #13
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")