Пример #1
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)
Пример #2
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()

    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():
    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")
Пример #5
0
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")