def test_observed_otus(self): obs = observed_otus(np.array([4, 3, 4, 0, 1, 0, 2])) self.assertEqual(obs, 5) obs = observed_otus(np.array([0, 0, 0])) self.assertEqual(obs, 0) obs = observed_otus(self.counts) self.assertEqual(obs, 9)
def main(): agents = [1, 2, 3, 4, 5, 6, 7, 8] signals = ['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8'] network = group(agents) pairs = [list(elem) for elem in network] menLen = 3 condition = "Heterogeneity PR R" ####SIGMAS#### s1 = rand.sample([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0], 8) s2 = rand.sample([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0], 8) sigmas = {1: s1, 2: s1, 3: s1, 4: s1, 5: s2, 6: s2, 7: s2, 8: s2} #samples = [{"b": 1.0, "x": 0.5, "m": 0.02}] samples = [ # {'cont': 0.0, 'coord': 0.0, 'mut': 0.02}, # {'cont': 0.1, 'coord': 0.0, 'mut': 0.02}, # {'cont': 0.2, 'coord': 0.0, 'mut': 0.02}, # {'cont': 0.3, 'coord': 0.0, 'mut': 0.02}, # {'cont': 0.4, 'coord': 0.0, 'mut': 0.02}, # {'cont': 0.5, 'coord': 0.0, 'mut': 0.02}, # {'cont': 0.6, 'coord': 0.0, 'mut': 0.02}, # {'cont': 0.7, 'coord': 0.0, 'mut': 0.02}, # {'cont': 0.8, 'coord': 0.0, 'mut': 0.02}, # {'cont': 0.9, 'coord': 0.0, 'mut': 0.02}, # {'cont': 1.0, 'coord': 0.0, 'mut': 0.02}] # {'cont': 0.0, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.1, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.2, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.3, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.4, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.5, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.6, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.7, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.8, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.9, 'coord': 0.1, 'mut': 0.02}, # {'cont': 1.0, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.0, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.1, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.2, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.3, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.4, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.5, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.6, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.7, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.8, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.9, 'coord': 0.2, 'mut': 0.02}, # {'cont': 1.0, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.0, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.1, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.2, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.3, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.4, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.5, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.6, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.7, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.8, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.9, 'coord': 0.3, 'mut': 0.02}, # {'cont': 1.0, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.0, 'coord': 0.4, 'mut': 0.02}, # {'cont': 0.1, 'coord': 0.4, 'mut': 0.02}, # {'cont': 0.2, 'coord': 0.4, 'mut': 0.02}, # {'cont': 0.3, 'coord': 0.4, 'mut': 0.02}, # {'cont': 0.4, 'coord': 0.4, 'mut': 0.02}, # {'cont': 0.5, 'coord': 0.4, 'mut': 0.02}, # {'cont': 0.6, 'coord': 0.4, 'mut': 0.02}, # {'cont': 0.7, 'coord': 0.4, 'mut': 0.02}, # {'cont': 0.8, 'coord': 0.4, 'mut': 0.02}, # {'cont': 0.9, 'coord': 0.4, 'mut': 0.02}, # {'cont': 1.0, 'coord': 0.4, 'mut': 0.02}, { 'cont': 0.0, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 0.1, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 0.2, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 0.3, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 0.4, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 0.5, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 0.6, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 0.7, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 0.8, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 0.9, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 1.0, 'coord': 0.5, 'mut': 0.02 } ] # {'cont': 0.0, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.1, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.2, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.3, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.4, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.5, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.6, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.7, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.8, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.9, 'coord': 0.6, 'mut': 0.02}, # {'cont': 1.0, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.0, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.1, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.2, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.3, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.4, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.5, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.6, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.7, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.8, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.9, 'coord': 0.7, 'mut': 0.02}, # {'cont': 1.0, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.0, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.1, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.2, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.3, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.4, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.5, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.6, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.7, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.8, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.9, 'coord': 0.8, 'mut': 0.02}, # {'cont': 1.0, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.0, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.1, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.2, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.3, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.4, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.5, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.6, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.7, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.8, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.9, 'coord': 0.9, 'mut': 0.02}, # {'cont': 1.0, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.0, 'coord': 1.0, 'mut': 0.02}, # {'cont': 0.1, 'coord': 1.0, 'mut': 0.02}, # {'cont': 0.2, 'coord': 1.0, 'mut': 0.02}, # {'cont': 0.3, 'coord': 1.0, 'mut': 0.02}, # {'cont': 0.4, 'coord': 1.0, 'mut': 0.02}, # {'cont': 0.5, 'coord': 1.0, 'mut': 0.02}, # {'cont': 0.6, 'coord': 1.0, 'mut': 0.02}, # {'cont': 0.7, 'coord': 1.0, 'mut': 0.02}, # {'cont': 0.8, 'coord': 1.0, 'mut': 0.02}, # {'cont': 0.9, 'coord': 1.0, 'mut': 0.02}, # {'cont': 1.0, 'coord': 1.0, 'mut': 0.02}] samples = [d for d in samples for _ in range(1)] simulations = 250 statistics = { sim: { agent: { sample: { signal: [0 for round in range(1, len(pairs) + 1)] for signal in signals } for sample in range(len(samples)) } for agent in agents } for sim in range(simulations) } for sim in range(simulations): network = group(agents) pairs = [list(elem) for elem in network] s1 = rand.sample([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0], 8) s2 = rand.sample([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0], 8) sigmas = {1: s1, 2: s1, 3: s1, 4: s1, 5: s2, 6: s2, 7: s2, 8: s2} for mu in range(len(samples)): game = Match(agents, pairs, signals, sigmas, samples[mu]["cont"], samples[mu]["coord"], samples[mu]["mut"], menLen) game.play() for n, round in enumerate(game.memory): for agent, signal in round.items(): statistics[sim][agent][mu][signal][n] += 1 with open('heterogeneity_PR_R.csv', 'w', newline='') as csvfile: writer = csv.writer(csvfile, delimiter=';', quotechar='"', quoting=csv.QUOTE_MINIMAL) writer.writerow([ 'Simulation', 'Sample', 'Agent', 'Memory', 'Generation', 'Condition', 'Content bias', 'Coordination bias', 'Mutation rate' ] + signals + ['Population signals'] + ['Entropy_population'] + ['Entropy_subpopulation_1'] + ['Entropy_subpopulation_2'] + ['Subpopulation_1 signals'] + ['Subpopulation_2 signals'] + ['Brillouin_population'] + ['Margalef_population'] + ['Simpson_population'] + ['Simpson_e_population'] + ['Richness']) # Creando listas que contienen la produccion de cada senal: para toda la poblacion (aux) y para cada jugador (auxn) for agent in agents: for sim in range(simulations): for mu in range(len(samples)): for round in range(1, len(pairs) + 1): aux = [ statistics[sim][agent][mu][signal][round - 1] for signal in signals ] aux1 = [ statistics[sim][1][mu][signal][round - 1] for signal in signals ] aux2 = [ statistics[sim][2][mu][signal][round - 1] for signal in signals ] aux3 = [ statistics[sim][3][mu][signal][round - 1] for signal in signals ] aux4 = [ statistics[sim][4][mu][signal][round - 1] for signal in signals ] aux5 = [ statistics[sim][5][mu][signal][round - 1] for signal in signals ] aux6 = [ statistics[sim][6][mu][signal][round - 1] for signal in signals ] aux7 = [ statistics[sim][7][mu][signal][round - 1] for signal in signals ] aux8 = [ statistics[sim][8][mu][signal][round - 1] for signal in signals ] # Lista que contiene los sumatorios de cada tipo de senales producidas a nivel de la poblacion global en cada muestra y ronda summation_pop = [] # Lista que contiene los sumatorios de cada tipo de senales producidas a nivel de subpoblacion en cada muestra y ronda summation_subpop_1 = [] summation_subpop_2 = [] # Sumando las senales de cada tipo for i in range(len(aux1)): # A nivel de la poblacion summation_pop.append(aux1[i] + aux2[i] + aux3[i] + aux4[i] + aux5[i] + aux6[i] + aux7[i] + aux8[i]) # A nivel de las subpoblaciones for i in range(len(aux1)): summation_subpop_1.append(aux1[i] + aux2[i] + aux3[i] + aux4[i]) summation_subpop_2.append(aux5[i] + aux6[i] + aux7[i] + aux8[i]) writer.writerow([ sim + 1, mu + 1, agent, menLen, round, condition, samples[mu] ['cont'], samples[mu]['coord'], samples[mu]['mut'] ] + aux + [summation_pop] + [entropy(summation_pop)] + [entropy(summation_subpop_1)] + [entropy(summation_subpop_2)] + [summation_subpop_1] + [summation_subpop_2] + [brillouin_d(summation_pop)] + [margalef(summation_pop)] + [simpson(summation_pop)] + [simpson_e(summation_pop)] + [observed_otus(summation_pop) / 8])
def main(menLen, i_power, sigmas, samples, simulations, condition): agents = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] #agents = list(range(1, 101)) signals = ['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10'] network = group(agents) pairs = [list(elem) for elem in network] # i_power = 1 # menLen = 3 ####SIGMAS: Agents' value system#### #s1 = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0] #s2 = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0] #sigmas = {1: s1, 2: s1, 3: s1, 4: s1, 5: s1, 6: s2, 7: s2, 8: s2, 9:s2, 10:s2} # samples = [ # {'cont': 1.0, 'coord': 0.5, 'conform': 1, 'confirm':0, 'mut': 0.02}] # samples = [d for d in samples for _ in range(1)] #simulations = 1 statistics = { sim: { agent: { sample: { signal: [0 for round in range(1, len(pairs) + 1)] for signal in signals } for sample in range(len(samples)) } for agent in agents } for sim in range(simulations) } for sim in range(simulations): #network = group(agents) #pairs = [list(elem) for elem in network] for mu in range(len(samples)): game = Match( agents, pairs, signals, sigmas, samples[mu]["cont"], samples[mu]["coord"], samples[mu]["mut"], menLen, i_power, ) game.play() for n, round in enumerate(game.memory): for agent, signal in round.items(): statistics[sim][agent][mu][signal][n] += 1 with open('PRep_heterogeneity_R_I005.csv', 'w', newline='') as csvfile: writer = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) writer.writerow([ 'Simulation', 'Sample', 'Agent', 'Memory', 'Generation', 'Condition', 'Inst_power', 'Content bias', 'Coordination bias', 'Mutation rate' ] + signals + ['Population signals'] + ['Entropy_population'] + ['Entropy_subpopulation_1'] + ['Entropy_subpopulation_2'] + ['Subpopulation_1 signals'] + ['Subpopulation_2 signals'] + ['Brillouin_population'] + ['Margalef_population'] + ['Simpson_population'] + ['Simpson_e_population'] + ['Richness']) # Creando listas que contienen la produccion de cada senal: para toda la poblacion (aux) y para cada jugador (auxn) #for agent in agents: for sim in range(simulations): for mu in range(len(samples)): for round in range(1, len(pairs) + 1): aux = [ statistics[sim][agent][mu][signal][round - 1] for signal in signals ] aux1 = [ statistics[sim][1][mu][signal][round - 1] for signal in signals ] aux2 = [ statistics[sim][2][mu][signal][round - 1] for signal in signals ] aux3 = [ statistics[sim][3][mu][signal][round - 1] for signal in signals ] aux4 = [ statistics[sim][4][mu][signal][round - 1] for signal in signals ] aux5 = [ statistics[sim][5][mu][signal][round - 1] for signal in signals ] aux6 = [ statistics[sim][6][mu][signal][round - 1] for signal in signals ] aux7 = [ statistics[sim][7][mu][signal][round - 1] for signal in signals ] aux8 = [ statistics[sim][8][mu][signal][round - 1] for signal in signals ] aux9 = [ statistics[sim][9][mu][signal][round - 1] for signal in signals ] aux10 = [ statistics[sim][10][mu][signal][round - 1] for signal in signals ] # aux11 = [statistics[sim][11][mu][signal][round - 1] for signal in signals] # aux12 = [statistics[sim][12][mu][signal][round - 1] for signal in signals] # aux13 = [statistics[sim][13][mu][signal][round - 1] for signal in signals] # aux14 = [statistics[sim][14][mu][signal][round - 1] for signal in signals] # aux15 = [statistics[sim][15][mu][signal][round - 1] for signal in signals] # aux16 = [statistics[sim][16][mu][signal][round - 1] for signal in signals] # aux17 = [statistics[sim][17][mu][signal][round - 1] for signal in signals] # aux18 = [statistics[sim][18][mu][signal][round - 1] for signal in signals] # aux19 = [statistics[sim][19][mu][signal][round - 1] for signal in signals] # aux20 = [statistics[sim][20][mu][signal][round - 1] for signal in signals] # aux21 = [statistics[sim][21][mu][signal][round - 1] for signal in signals] # aux22 = [statistics[sim][22][mu][signal][round - 1] for signal in signals] # aux23 = [statistics[sim][23][mu][signal][round - 1] for signal in signals] # aux24 = [statistics[sim][24][mu][signal][round - 1] for signal in signals] # aux25 = [statistics[sim][25][mu][signal][round - 1] for signal in signals] # aux26 = [statistics[sim][26][mu][signal][round - 1] for signal in signals] # aux27 = [statistics[sim][27][mu][signal][round - 1] for signal in signals] # aux28 = [statistics[sim][28][mu][signal][round - 1] for signal in signals] # aux29 = [statistics[sim][29][mu][signal][round - 1] for signal in signals] # aux30 = [statistics[sim][30][mu][signal][round - 1] for signal in signals] # aux31 = [statistics[sim][31][mu][signal][round - 1] for signal in signals] # aux32 = [statistics[sim][32][mu][signal][round - 1] for signal in signals] # aux33 = [statistics[sim][33][mu][signal][round - 1] for signal in signals] # aux34 = [statistics[sim][34][mu][signal][round - 1] for signal in signals] # aux35 = [statistics[sim][35][mu][signal][round - 1] for signal in signals] # aux36 = [statistics[sim][36][mu][signal][round - 1] for signal in signals] # aux37 = [statistics[sim][37][mu][signal][round - 1] for signal in signals] # aux38 = [statistics[sim][38][mu][signal][round - 1] for signal in signals] # aux39 = [statistics[sim][39][mu][signal][round - 1] for signal in signals] # aux40 = [statistics[sim][40][mu][signal][round - 1] for signal in signals] # aux41 = [statistics[sim][41][mu][signal][round - 1] for signal in signals] # aux42 = [statistics[sim][42][mu][signal][round - 1] for signal in signals] # aux43 = [statistics[sim][43][mu][signal][round - 1] for signal in signals] # aux44 = [statistics[sim][44][mu][signal][round - 1] for signal in signals] # aux45 = [statistics[sim][45][mu][signal][round - 1] for signal in signals] # aux46 = [statistics[sim][46][mu][signal][round - 1] for signal in signals] # aux47 = [statistics[sim][47][mu][signal][round - 1] for signal in signals] # aux48 = [statistics[sim][48][mu][signal][round - 1] for signal in signals] # aux49 = [statistics[sim][49][mu][signal][round - 1] for signal in signals] # aux50 = [statistics[sim][50][mu][signal][round - 1] for signal in signals] # aux51 = [statistics[sim][51][mu][signal][round - 1] for signal in signals] # aux52 = [statistics[sim][52][mu][signal][round - 1] for signal in signals] # aux53 = [statistics[sim][53][mu][signal][round - 1] for signal in signals] # aux54 = [statistics[sim][54][mu][signal][round - 1] for signal in signals] # aux55 = [statistics[sim][55][mu][signal][round - 1] for signal in signals] # aux56 = [statistics[sim][56][mu][signal][round - 1] for signal in signals] # aux57 = [statistics[sim][57][mu][signal][round - 1] for signal in signals] # aux58 = [statistics[sim][58][mu][signal][round - 1] for signal in signals] # aux59 = [statistics[sim][59][mu][signal][round - 1] for signal in signals] # aux60 = [statistics[sim][50][mu][signal][round - 1] for signal in signals] # aux61 = [statistics[sim][61][mu][signal][round - 1] for signal in signals] # aux62 = [statistics[sim][62][mu][signal][round - 1] for signal in signals] # aux63 = [statistics[sim][63][mu][signal][round - 1] for signal in signals] # aux64 = [statistics[sim][64][mu][signal][round - 1] for signal in signals] # aux65 = [statistics[sim][65][mu][signal][round - 1] for signal in signals] # aux66 = [statistics[sim][66][mu][signal][round - 1] for signal in signals] # aux67 = [statistics[sim][67][mu][signal][round - 1] for signal in signals] # aux68 = [statistics[sim][68][mu][signal][round - 1] for signal in signals] # aux69 = [statistics[sim][69][mu][signal][round - 1] for signal in signals] # aux70 = [statistics[sim][70][mu][signal][round - 1] for signal in signals] # aux71 = [statistics[sim][71][mu][signal][round - 1] for signal in signals] # aux72 = [statistics[sim][72][mu][signal][round - 1] for signal in signals] # aux73 = [statistics[sim][73][mu][signal][round - 1] for signal in signals] # aux74 = [statistics[sim][74][mu][signal][round - 1] for signal in signals] # aux75 = [statistics[sim][75][mu][signal][round - 1] for signal in signals] # aux76 = [statistics[sim][76][mu][signal][round - 1] for signal in signals] # aux77 = [statistics[sim][77][mu][signal][round - 1] for signal in signals] # aux78 = [statistics[sim][78][mu][signal][round - 1] for signal in signals] # aux79 = [statistics[sim][79][mu][signal][round - 1] for signal in signals] # aux80 = [statistics[sim][80][mu][signal][round - 1] for signal in signals] # aux81 = [statistics[sim][81][mu][signal][round - 1] for signal in signals] # aux82 = [statistics[sim][82][mu][signal][round - 1] for signal in signals] # aux83 = [statistics[sim][83][mu][signal][round - 1] for signal in signals] # aux84 = [statistics[sim][84][mu][signal][round - 1] for signal in signals] # aux85 = [statistics[sim][85][mu][signal][round - 1] for signal in signals] # aux86 = [statistics[sim][86][mu][signal][round - 1] for signal in signals] # aux87 = [statistics[sim][87][mu][signal][round - 1] for signal in signals] # aux88 = [statistics[sim][88][mu][signal][round - 1] for signal in signals] # aux89 = [statistics[sim][89][mu][signal][round - 1] for signal in signals] # aux90 = [statistics[sim][90][mu][signal][round - 1] for signal in signals] # aux91 = [statistics[sim][91][mu][signal][round - 1] for signal in signals] # aux92 = [statistics[sim][92][mu][signal][round - 1] for signal in signals] # aux93 = [statistics[sim][93][mu][signal][round - 1] for signal in signals] # aux94 = [statistics[sim][94][mu][signal][round - 1] for signal in signals] # aux95 = [statistics[sim][95][mu][signal][round - 1] for signal in signals] # aux96 = [statistics[sim][96][mu][signal][round - 1] for signal in signals] # aux97 = [statistics[sim][97][mu][signal][round - 1] for signal in signals] # aux98 = [statistics[sim][98][mu][signal][round - 1] for signal in signals] # aux99 = [statistics[sim][99][mu][signal][round - 1] for signal in signals] # aux100 = [statistics[sim][100][mu][signal][round - 1] for signal in signals] # Lista que contiene los sumatorios de cada tipo de senales producidas a nivel de la poblacion global en cada muestra y ronda summation_pop = [] # Lista que contiene los sumatorios de cada tipo de senales producidas a nivel de subpoblacion en cada muestra y ronda summation_subpop_1 = [] summation_subpop_2 = [] # Sumando las senales de cada tipo for i in range(len(aux1)): # A nivel de la poblacion summation_pop.append(aux1[i] + aux2[i] + aux3[i] + aux4[i] + aux5[i] + aux6[i] + aux7[i] + aux8[i] + aux9[i] + aux10[i]) # + # aux11[i] + aux12[i] + aux13[i] + aux14[i] + aux15[i] + aux16[i] + aux17[i] + aux18[ # i] + aux19[i] + aux20[i] + # aux21[i] + aux22[i] + aux23[i] + aux24[i] + aux25[i] + aux26[i] + aux27[i] + aux28[ # i] + aux29[i] + aux30[i] + # aux31[i] + aux32[i] + aux33[i] + aux34[i] + aux35[i] + aux36[i] + aux37[i] + aux38[ # i] + aux39[i] + aux40[i] + # aux41[i] + aux42[i] + aux43[i] + aux44[i] + aux45[i] + aux46[i] + aux47[i] + aux48[ # i] + aux49[i] + aux50[i] + # aux51[i] + aux52[i] + aux53[i] + aux54[i] + aux55[i] + aux56[i] + aux57[i] + aux58[ # i] + aux59[i] + aux60[i] + # aux61[i] + aux62[i] + aux63[i] + aux64[i] + aux65[i] + aux66[i] + aux67[i] + aux68[ # i] + aux69[i] + aux70[i] + # aux71[i] + aux72[i] + aux73[i] + aux74[i] + aux75[i] + aux76[i] + aux77[i] + aux78[ # i] + aux79[i] + aux80[i] + # aux81[i] + aux82[i] + aux83[i] + aux84[i] + aux85[i] + aux86[i] + aux87[i] + aux88[ # i] + aux89[i] + aux90[i] + # aux91[i] + aux92[i] + aux93[i] + aux94[i] + aux95[i] + aux96[i] + aux97[i] + aux98[ # i] + aux99[i] + aux100[i]) # A nivel de las subpoblaciones for i in range(len(aux1)): summation_subpop_1.append(aux1[i] + aux2[i] + aux3[i] + aux4[i] + aux5[i]) summation_subpop_2.append(+aux6[i] + aux7[i] + aux8[i] + aux9[i] + aux10[i]) #print(aux1) #output.append(shannon(summation_pop)) #print(output) writer.writerow([ sim + 1, mu + 1, agent, menLen, round, condition, i_power, samples[mu]['cont'], samples[mu]['coord'], samples[mu]['mut'] ] + aux + [summation_pop] + [shannon(summation_pop)] + [shannon(summation_subpop_1)] + [shannon(summation_subpop_2)] + [summation_subpop_1] + [summation_subpop_2] + [brillouin_d(summation_pop)] + [margalef(summation_pop)] + [simpson(summation_pop)] + [simpson_e(summation_pop)] + [observed_otus(summation_pop) / 10])
dis_len = len(dissolved) # Counting language dominance, menhinick diversity and simpson index print('[INFO] - Calculating variables..') for i, row in dissolved.iterrows(): print("[INFO] - Calculating grid cell {}/{}...".format(i, dis_len)) lang_counts = list(Counter( row[args['language']]).values()) # occurence counts lang_counts = np.asarray(lang_counts) # cast as numpy array for skbio dissolved.at[i, 'dominance'] = sk.dominance(lang_counts) dissolved.at[i, 'menhinick'] = sk.menhinick(lang_counts) dissolved.at[i, 'simpson'] = sk.simpson(lang_counts) dissolved.at[i, 'berger'] = sk.berger_parker_d(lang_counts) dissolved.at[i, 'singles'] = sk.singles(lang_counts) dissolved.at[i, 'shannon'] = np.exp(sk.shannon(lang_counts, base=np.e)) dissolved.at[i, 'unique'] = sk.observed_otus(lang_counts) # Select columns for output cols = [ 'geometry', 'dominance', 'menhinick', 'simpson', 'berger', 'singles', 'shannon', 'unique' ] output = dissolved[cols] # Save the output to pickle print('[INFO] - Saving to shapefile') output.to_file(args['output'], encoding='utf-8') # Print status print("[INFO] - ... Done.")
def observed_species(counts): return alph.observed_otus(counts)
areas.at[i, colname4] = (int(lposts) / int(lpostsum)) * 100 # get dominant language from selected columns areas['propmax'] = areas[['fi_prop','en_prop','et_prop','ru_prop','sv_prop','es_prop','ja_prop','fr_prop','pt_prop','de_prop']].idxmax(axis=1) areas['mean_propmax'] = areas[['fi_mean_prop','en_mean_prop','et_mean_prop','ru_mean_prop','sv_mean_prop','es_mean_prop','ja_mean_prop','fr_mean_prop','pt_mean_prop','de_mean_prop']].idxmax(axis=1) areas['sum_propmax'] = areas[['fi_sum_prop','en_sum_prop','et_sum_prop','ru_sum_prop','sv_sum_prop','es_sum_prop','ja_sum_prop','fr_sum_prop','pt_sum_prop','de_sum_prop']].idxmax(axis=1) # get all language column names cols = list(areas[langlist].columns) # loop over areas print('[INFO] - Calculating diversity metrics per area..') for i, row in areas.iterrows(): # get counts of languages otus = list(row[cols]) # drop zeros otus = [i for i in otus if i != 0] # calculate diversity metrics areas.at[i, 'dominance'] = sk.dominance(otus) areas.at[i, 'berger'] = sk.berger_parker_d(otus) areas.at[i, 'menhinick'] = sk.menhinick(otus) areas.at[i, 'singletons'] = sk.singles(otus) areas.at[i, 'shannon'] = np.exp(sk.shannon(otus, base=np.e)) areas.at[i, 'unique'] = sk.observed_otus(otus) # save to file print('[INFO] - Saving output geopackage...') areas.to_file(args['output'], driver='GPKG') print('[INFO] - ... done!')
def main(menLen, i_power, sigmas, samples, simulations, condition): agents = [1,2,3,4,5,6,7,8,9,10] signals = ['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10'] network = group(agents) pairs = [list(elem) for elem in network] statistics = { sim: { agent: { sample: { signal: [0 for round in range(1, len(pairs) + 1)] for signal in signals } for sample in range(len(samples)) } for agent in agents } for sim in range(simulations) } for sim in range(simulations): #network = group(agents) #pairs = [list(elem) for elem in network] for mu in range(len(samples)): game = Match( agents, pairs, signals, sigmas, samples[mu]["cont"], samples[mu]["coord"], samples[mu]["mut"], menLen, i_power ) game.play() for n, round in enumerate(game.memory): for agent, signal in round.items(): statistics[sim][agent][mu][signal][n] += 1 with open('homogeneity_C_0.csv', 'w', newline='') as csvfile: writer = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) writer.writerow(['Simulation', 'Sample', 'Agent', 'Memory', 'Generation', 'Condition', 'Inst_power','Content bias', 'Coordination bias','Mutation rate'] + signals + ['Population signals'] + ['Entropy_population'] + ['Entropy_subpopulation_1'] + [ 'Entropy_subpopulation_2'] + ['Subpopulation_1 signals'] + ['Subpopulation_2 signals'] + ['Brillouin_population'] + ['Margalef_population'] + ['Simpson_population'] + [ 'Simpson_e_population'] + ['Richness']) # Creando listas que contienen la produccion de cada senal: para toda la poblacion (aux) y para cada jugador (auxn) #for agent in agents: for sim in range(simulations): for mu in range(len(samples)): for round in range(1, len(pairs) + 1): aux = [statistics[sim][agent][mu][signal][round - 1] for signal in signals] aux1 = [statistics[sim][1][mu][signal][round - 1] for signal in signals] aux2 = [statistics[sim][2][mu][signal][round - 1] for signal in signals] aux3 = [statistics[sim][3][mu][signal][round - 1] for signal in signals] aux4 = [statistics[sim][4][mu][signal][round - 1] for signal in signals] aux5 = [statistics[sim][5][mu][signal][round - 1] for signal in signals] aux6 = [statistics[sim][6][mu][signal][round - 1] for signal in signals] aux7 = [statistics[sim][7][mu][signal][round - 1] for signal in signals] aux8 = [statistics[sim][8][mu][signal][round - 1] for signal in signals] aux9 = [statistics[sim][9][mu][signal][round - 1] for signal in signals] aux10 = [statistics[sim][10][mu][signal][round - 1] for signal in signals] # Lista que contiene los sumatorios de cada tipo de senales producidas a nivel de la poblacion global en cada muestra y ronda summation_pop = [] # Lista que contiene los sumatorios de cada tipo de senales producidas a nivel de subpoblacion en cada muestra y ronda summation_subpop_1 = [] summation_subpop_2 = [] # Sumando las senales de cada tipo for i in range(len(aux1)): # A nivel de la poblacion summation_pop.append( aux1[i] + aux2[i] + aux3[i] + aux4[i] + aux5[i] + aux6[i] + aux7[i] + aux8[i] + aux9[i] + aux10[i]) # A nivel de las subpoblaciones for i in range(len(aux1)): summation_subpop_1.append(aux1[i] + aux2[i] + aux3[i] + aux4[i] + aux5[i]) summation_subpop_2.append(+ aux6[i] + aux7[i] + aux8[i] + aux9[i] + aux10[i]) #print(aux1) #output.append(shannon(summation_pop)) #print(output) writer.writerow([sim + 1, mu + 1, agent, menLen, round, condition, i_power, samples[mu]['cont'], samples[mu]['coord'], samples[mu]['mut']] + aux + [summation_pop] + [shannon(summation_pop)] + [ shannon(summation_subpop_1)] + [shannon(summation_subpop_2)] + [ summation_subpop_1] + [summation_subpop_2] + [brillouin_d(summation_pop)] + [margalef(summation_pop)] + [ simpson(summation_pop)] + [simpson_e(summation_pop)] + [ observed_otus(summation_pop) / 10])
def main(): # Agents agents = [1, 2, 3, 4, 5, 6, 7, 8] # Variants signals = ['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8'] # Pair composition # Randomize pair composition: network = group(agents) pairs = [list(elem) for elem in network] # Memory length menLen = 3 # Condition condition = "Heterogeneity C W" #### STRUCTURE OF VALUE SYSTEMS IN THE MICRO-SOCIETY (each value system (s1, s2, etc...) is assigned an agent): #### class Match, in the initialization, creates "agents" and passes the parameters to each agent, #### (including their sigmas). For this reason, a dictionary containig keys (agents' names ("name") and #### values (sigmas), is required s1 = [1, 1, 0, 0, 0, 0, 0, 0] s2 = [0, 0, 0, 0, 0, 0, 1, 1] sigmas = {1: s1, 2: s1, 3: s1, 4: s1, 5: s2, 6: s2, 7: s2, 8: s2} # Content bias ('cont'): no content bias=0.0, fully content biased population=1.0 # Coordination bias ('coord'): fully egocentric=0.0, fully allocentric=1.0, neutral=0.5 # mutation rate ('mut') # Setup for one parameter combination: #samples = [{'cont': 0.2, 'coord': 0.5, 'mut': 0.02} for _ in range(100)] # Setup for all parameter combinations (content bias and coordination bias): samples = [ # {'cont': 0.0, 'coord': 0.0, 'mut': 0.02}, # {'cont': 0.1, 'coord': 0.0, 'mut': 0.02}, # {'cont': 0.2, 'coord': 0.0, 'mut': 0.02}, # {'cont': 0.3, 'coord': 0.0, 'mut': 0.02}, # {'cont': 0.4, 'coord': 0.0, 'mut': 0.02}, # {'cont': 0.5, 'coord': 0.0, 'mut': 0.02}, # {'cont': 0.6, 'coord': 0.0, 'mut': 0.02}, # {'cont': 0.7, 'coord': 0.0, 'mut': 0.02}, # {'cont': 0.8, 'coord': 0.0, 'mut': 0.02}, # {'cont': 0.9, 'coord': 0.0, 'mut': 0.02}, # {'cont': 1.0, 'coord': 0.0, 'mut': 0.02}] # {'cont': 0.0, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.1, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.2, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.3, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.4, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.5, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.6, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.7, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.8, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.9, 'coord': 0.1, 'mut': 0.02}, # {'cont': 1.0, 'coord': 0.1, 'mut': 0.02}, # {'cont': 0.0, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.1, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.2, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.3, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.4, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.5, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.6, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.7, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.8, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.9, 'coord': 0.2, 'mut': 0.02}, # {'cont': 1.0, 'coord': 0.2, 'mut': 0.02}, # {'cont': 0.0, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.1, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.2, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.3, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.4, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.5, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.6, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.7, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.8, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.9, 'coord': 0.3, 'mut': 0.02}, # {'cont': 1.0, 'coord': 0.3, 'mut': 0.02}, # {'cont': 0.0, 'coord': 0.4, 'mut': 0.02}, # {'cont': 0.1, 'coord': 0.4, 'mut': 0.02}, # {'cont': 0.2, 'coord': 0.4, 'mut': 0.02}, # {'cont': 0.3, 'coord': 0.4, 'mut': 0.02}, # {'cont': 0.4, 'coord': 0.4, 'mut': 0.02}, # {'cont': 0.5, 'coord': 0.4, 'mut': 0.02}, # {'cont': 0.6, 'coord': 0.4, 'mut': 0.02}, # {'cont': 0.7, 'coord': 0.4, 'mut': 0.02}, # {'cont': 0.8, 'coord': 0.4, 'mut': 0.02}, # {'cont': 0.9, 'coord': 0.4, 'mut': 0.02}, # {'cont': 1.0, 'coord': 0.4, 'mut': 0.02}, { 'cont': 0.0, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 0.1, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 0.2, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 0.3, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 0.4, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 0.5, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 0.6, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 0.7, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 0.8, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 0.9, 'coord': 0.5, 'mut': 0.02 }, { 'cont': 1.0, 'coord': 0.5, 'mut': 0.02 } ] # {'cont': 0.0, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.1, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.2, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.3, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.4, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.5, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.6, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.7, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.8, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.9, 'coord': 0.6, 'mut': 0.02}, # {'cont': 1.0, 'coord': 0.6, 'mut': 0.02}, # {'cont': 0.0, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.1, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.2, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.3, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.4, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.5, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.6, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.7, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.8, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.9, 'coord': 0.7, 'mut': 0.02}, # {'cont': 1.0, 'coord': 0.7, 'mut': 0.02}, # {'cont': 0.0, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.1, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.2, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.3, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.4, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.5, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.6, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.7, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.8, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.9, 'coord': 0.8, 'mut': 0.02}, # {'cont': 1.0, 'coord': 0.8, 'mut': 0.02}, # {'cont': 0.0, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.1, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.2, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.3, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.4, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.5, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.6, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.7, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.8, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.9, 'coord': 0.9, 'mut': 0.02}, # {'cont': 1.0, 'coord': 0.9, 'mut': 0.02}, # {'cont': 0.0, 'coord': 1.0, 'mut': 0.02}, # {'cont': 0.1, 'coord': 1.0, 'mut': 0.02}, # {'cont': 0.2, 'coord': 1.0, 'mut': 0.02}, # {'cont': 0.3, 'coord': 1.0, 'mut': 0.02}, # {'cont': 0.4, 'coord': 1.0, 'mut': 0.02}, # {'cont': 0.5, 'coord': 1.0, 'mut': 0.02}, # {'cont': 0.6, 'coord': 1.0, 'mut': 0.02}, # {'cont': 0.7, 'coord': 1.0, 'mut': 0.02}, # {'cont': 0.8, 'coord': 1.0, 'mut': 0.02}, # {'cont': 0.9, 'coord': 1.0, 'mut': 0.02}, # {'cont': 1.0, 'coord': 1.0, 'mut': 0.02}] samples = [d for d in samples for _ in range(1)] # Number of runs (simulations) simulations = 250 # Generating statistics statistics = { sim: { agent: { sample: { signal: [0 for round in range(1, len(pairs) + 1)] for signal in signals } for sample in range(len(samples)) } for agent in agents } for sim in range(simulations) } # Running The Game (game.play) for sim in range(simulations): network = group(agents) pairs = [list(elem) for elem in network] for mu in range(len(samples)): game = Match(agents, pairs, signals, sigmas, samples[mu]["cont"], samples[mu]["coord"], samples[mu]["mut"], menLen) game.play() for n, round in enumerate(game.memory): for agent, signal in round.items(): statistics[sim][agent][mu][signal][n] += 1 # Writing data with open('heterogeneity_C_W.csv', 'w', newline='') as csvfile: writer = csv.writer(csvfile, delimiter=';', quotechar='"', quoting=csv.QUOTE_MINIMAL) writer.writerow([ 'Simulation', 'Sample', 'Agent', 'Memory', 'Generation', 'Condition', 'Content bias', 'Coordination bias', 'Mutation rate' ] + signals + ['Population signals'] + ['Entropy_population'] + ['Entropy_subpopulation_1'] + ['Entropy_subpopulation_2'] + ['Subpopulation_1 signals'] + ['Subpopulation_2 signals'] + ['Brillouin_population'] + ['Margalef_population'] + ['Simpson_population'] + ['Simpson_e_population'] + ['Richness']) # Creating lists that contain signals' production for agent in agents: for sim in range(simulations): for mu in range(len(samples)): for round in range(1, len(pairs) + 1): aux = [ statistics[sim][agent][mu][signal][round - 1] for signal in signals ] aux1 = [ statistics[sim][1][mu][signal][round - 1] for signal in signals ] aux2 = [ statistics[sim][2][mu][signal][round - 1] for signal in signals ] aux3 = [ statistics[sim][3][mu][signal][round - 1] for signal in signals ] aux4 = [ statistics[sim][4][mu][signal][round - 1] for signal in signals ] aux5 = [ statistics[sim][5][mu][signal][round - 1] for signal in signals ] aux6 = [ statistics[sim][6][mu][signal][round - 1] for signal in signals ] aux7 = [ statistics[sim][7][mu][signal][round - 1] for signal in signals ] aux8 = [ statistics[sim][8][mu][signal][round - 1] for signal in signals ] # List that contains the sum of produced variants in the population for each simulation and round summation_pop = [] # List that contains the sum of produced vatiants in each population for each simulation and round summation_subpop_1 = [] summation_subpop_2 = [] # Summing variants for i in range(len(aux1)): # In teh population summation_pop.append(aux1[i] + aux2[i] + aux3[i] + aux4[i] + aux5[i] + aux6[i] + aux7[i] + aux8[i]) # In each subpopulation for i in range(len(aux1)): summation_subpop_1.append(aux1[i] + aux2[i] + aux3[i] + aux4[i]) summation_subpop_2.append(aux5[i] + aux6[i] + aux7[i] + aux8[i]) writer.writerow([ sim + 1, mu + 1, agent, menLen, round, condition, samples[mu] ['cont'], samples[mu]['coord'], samples[mu]['mut'] ] + aux + [summation_pop] + [entropy(summation_pop)] + [entropy(summation_subpop_1)] + [entropy(summation_subpop_2)] + [summation_subpop_1] + [summation_subpop_2] + [brillouin_d(summation_pop)] + [margalef(summation_pop)] + [simpson(summation_pop)] + [simpson_e(summation_pop)] + [observed_otus(summation_pop) / 8])
def main(): # Agents names (and number of agents): agents = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # Variants signals = ['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10'] # Social network (order in which agents pair over time) network = group(agents) pairs = [list(elem) for elem in network] # Memory length (amount of hisotry (in rounds) that agents are able to recall) menLen = 3 # Condition (type name according to value system structure, sigmas) condition = "Homogeneity" # Scenario (type name according to value system structure sigmas) scenario = "OTA" # Institutional power (type number according to value assinged to institutional power in "choose" method i_power = 0 ####SIGMAS: Agents' value system at the initial state. That is, the value that an agent assigns to each signal in the initial state#### ### Homogeneity and hegemony (OTA) s1 = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0] s2 = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0] ### Heterogeneity and pseudo-random (PR) #s1 = np.random.uniform(low=0, high=1, size=(10,)) #s2 = np.random.uniform(low=0, high=1, size=(10,)) ### Dictionary of agents' value systems sigmas = {1: s1, 2: s1, 3: s1, 4: s1, 5: s1, 6: s2, 7: s2, 8: s2, 9:s2, 10:s2} # Samples: agents' content bias, coordination bias, conformity bias, confirmation bias, innovation rate. # Content bias ('cont'): no content bias=0.0, fully content biased population=1.0 # Coordination bias ('coord'): fully egocentric=0.0, fully allocentric=1.0, neutral=0.5 # Compliance bias ('conform'): null compliance=0.0, fully compliant=1.0 # Conformity bias ('conformity'): null conformity=0.0, full conformity=1.0 # Innovation rate('mut') # Setup for different parameter combinations: samples = [ {'cont': 0.0, 'coord': 0.5, 'conform': 0, 'confirm':0, 'mut': 0.02}, {'cont': 0.2, 'coord': 0.5, 'conform': 0, 'confirm':0, 'mut': 0.02}, {'cont': 0.4, 'coord': 0.5, 'conform': 0, 'confirm':0, 'mut': 0.02}, {'cont': 0.5, 'coord': 0.5, 'conform': 0, 'confirm':0, 'mut': 0.02}, {'cont': 0.6, 'coord': 0.5, 'conform': 0, 'confirm':0, 'mut': 0.02}, {'cont': 0.8, 'coord': 0.5, 'conform': 0, 'confirm':0, 'mut': 0.02}, {'cont': 1.0, 'coord': 0.5, 'conform': 0, 'confirm':0, 'mut': 0.02}, {'cont': 0.0, 'coord': 0.5, 'conform': 0, 'confirm': 0.5, 'mut': 0.02}, {'cont': 0.2, 'coord': 0.5, 'conform': 0, 'confirm': 0.5, 'mut': 0.02}, {'cont': 0.4, 'coord': 0.5, 'conform': 0, 'confirm': 0.5, 'mut': 0.02}, {'cont': 0.5, 'coord': 0.5, 'conform': 0, 'confirm': 0.5, 'mut': 0.02}, {'cont': 0.6, 'coord': 0.5, 'conform': 0, 'confirm': 0.5, 'mut': 0.02}, {'cont': 0.8, 'coord': 0.5, 'conform': 0, 'confirm': 0.5, 'mut': 0.02}, {'cont': 1.0, 'coord': 0.5, 'conform': 0, 'confirm': 0.5, 'mut': 0.02}, {'cont': 0.0, 'coord': 0.5, 'conform': 0, 'confirm': 1, 'mut': 0.02}, {'cont': 0.2, 'coord': 0.5, 'conform': 0, 'confirm': 1, 'mut': 0.02}, {'cont': 0.4, 'coord': 0.5, 'conform': 0, 'confirm': 1, 'mut': 0.02}, {'cont': 0.5, 'coord': 0.5, 'conform': 0, 'confirm': 1, 'mut': 0.02}, {'cont': 0.6, 'coord': 0.5, 'conform': 0, 'confirm': 1, 'mut': 0.02}, {'cont': 0.8, 'coord': 0.5, 'conform': 0, 'confirm': 1, 'mut': 0.02}, {'cont': 1.0, 'coord': 0.5, 'conform': 0, 'confirm': 1, 'mut': 0.02}, {'cont': 0.0, 'coord': 0.5, 'conform': 0.5, 'confirm': 0, 'mut': 0.02}, {'cont': 0.2, 'coord': 0.5, 'conform': 0.5, 'confirm': 0, 'mut': 0.02}, {'cont': 0.4, 'coord': 0.5, 'conform': 0.5, 'confirm': 0, 'mut': 0.02}, {'cont': 0.5, 'coord': 0.5, 'conform': 0.5, 'confirm': 0, 'mut': 0.02}, {'cont': 0.6, 'coord': 0.5, 'conform': 0.5, 'confirm': 0, 'mut': 0.02}, {'cont': 0.8, 'coord': 0.5, 'conform': 0.5, 'confirm': 0, 'mut': 0.02}, {'cont': 1.0, 'coord': 0.5, 'conform': 0.5, 'confirm': 0, 'mut': 0.02}, {'cont': 0.0, 'coord': 0.5, 'conform': 0.5, 'confirm': 0.5, 'mut': 0.02}, {'cont': 0.2, 'coord': 0.5, 'conform': 0.5, 'confirm': 0.5, 'mut': 0.02}, {'cont': 0.4, 'coord': 0.5, 'conform': 0.5, 'confirm': 0.5, 'mut': 0.02}, {'cont': 0.5, 'coord': 0.5, 'conform': 0.5, 'confirm': 0.5, 'mut': 0.02}, {'cont': 0.6, 'coord': 0.5, 'conform': 0.5, 'confirm': 0.5, 'mut': 0.02}, {'cont': 0.8, 'coord': 0.5, 'conform': 0.5, 'confirm': 0.5, 'mut': 0.02}, {'cont': 1.0, 'coord': 0.5, 'conform': 0.5, 'confirm': 0.5, 'mut': 0.02}, {'cont': 0.0, 'coord': 0.5, 'conform': 0.5, 'confirm': 1, 'mut': 0.02}, {'cont': 0.2, 'coord': 0.5, 'conform': 0.5, 'confirm': 1, 'mut': 0.02}, {'cont': 0.4, 'coord': 0.5, 'conform': 0.5, 'confirm': 1, 'mut': 0.02}, {'cont': 0.5, 'coord': 0.5, 'conform': 0.5, 'confirm': 1, 'mut': 0.02}, {'cont': 0.6, 'coord': 0.5, 'conform': 0.5, 'confirm': 1, 'mut': 0.02}, {'cont': 0.8, 'coord': 0.5, 'conform': 0.5, 'confirm': 1, 'mut': 0.02}, {'cont': 1.0, 'coord': 0.5, 'conform': 0.5, 'confirm': 1, 'mut': 0.02}, {'cont': 0.0, 'coord': 0.5, 'conform': 1, 'confirm': 0, 'mut': 0.02}, {'cont': 0.2, 'coord': 0.5, 'conform': 1, 'confirm': 0, 'mut': 0.02}, {'cont': 0.4, 'coord': 0.5, 'conform': 1, 'confirm': 0, 'mut': 0.02}, {'cont': 0.5, 'coord': 0.5, 'conform': 1, 'confirm': 0, 'mut': 0.02}, {'cont': 0.6, 'coord': 0.5, 'conform': 1, 'confirm': 0, 'mut': 0.02}, {'cont': 0.8, 'coord': 0.5, 'conform': 1, 'confirm': 0, 'mut': 0.02}, {'cont': 1.0, 'coord': 0.5, 'conform': 1, 'confirm': 0, 'mut': 0.02}, {'cont': 0.0, 'coord': 0.5, 'conform': 1, 'confirm': 0.5, 'mut': 0.02}, {'cont': 0.2, 'coord': 0.5, 'conform': 1, 'confirm': 0.5, 'mut': 0.02}, {'cont': 0.4, 'coord': 0.5, 'conform': 1, 'confirm': 0.5, 'mut': 0.02}, {'cont': 0.5, 'coord': 0.5, 'conform': 1, 'confirm': 0.5, 'mut': 0.02}, {'cont': 0.6, 'coord': 0.5, 'conform': 1, 'confirm': 0.5, 'mut': 0.02}, {'cont': 0.8, 'coord': 0.5, 'conform': 1, 'confirm': 0.5, 'mut': 0.02}, {'cont': 1.0, 'coord': 0.5, 'conform': 1, 'confirm': 0.5, 'mut': 0.02}, {'cont': 0.0, 'coord': 0.5, 'conform': 1, 'confirm': 1, 'mut': 0.02}, {'cont': 0.2, 'coord': 0.5, 'conform': 1, 'confirm': 1, 'mut': 0.02}, {'cont': 0.4, 'coord': 0.5, 'conform': 1, 'confirm': 1, 'mut': 0.02}, {'cont': 0.5, 'coord': 0.5, 'conform': 1, 'confirm': 1, 'mut': 0.02}, {'cont': 0.6, 'coord': 0.5, 'conform': 1, 'confirm': 1, 'mut': 0.02}, {'cont': 0.8, 'coord': 0.5, 'conform': 1, 'confirm': 1, 'mut': 0.02}, {'cont': 1.0, 'coord': 0.5, 'conform': 1, 'confirm': 1, 'mut': 0.02}] # Number of samples of each parameter combination samples = [d for d in samples for _ in range(1)] # Number of simulations simulations = 1 # Statistics statistics = { sim: { agent: { sample: { signal: [0 for round in range(1, len(pairs) + 1)] for signal in signals } for sample in range(len(samples)) } for agent in agents } for sim in range(simulations) } # Piece of code to run each instance of the game (game.play) for the specified number of samples and simulations for sim in range(simulations): network = group(agents) pairs = [list(elem) for elem in network] for mu in range(len(samples)): game = Match( agents, pairs, signals, sigmas, samples[mu]["cont"], samples[mu]["coord"], samples[mu]["conform"], samples[mu]["confirm"], samples[mu]["mut"], menLen ) game.play() for n, round in enumerate(game.memory): for agent, signal in round.items(): statistics[sim][agent][mu][signal][n] += 1 # Write csv file with open('Test_COEVO_Hom_OTA_R_I00_F.csv', 'w', newline='') as csvfile: writer = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) writer.writerow(['Simulation', 'Sample', 'Agent', 'Memory', 'Generation', 'Condition', 'Scenario', 'Inst_power','Content bias', 'Coordination bias','Conformity bias','Confirmation bias', 'Mutation rate'] + signals + ['Population signals'] + ['Entropy_population'] + ['Entropy_subpopulation_1'] + [ 'Entropy_subpopulation_2'] + ['Subpopulation_1 signals'] + ['Subpopulation_2 signals'] + ['Brillouin_population'] + ['Margalef_population'] + ['Simpson_population'] + [ 'Simpson_e_population'] + ['Richness']) # Creating lists that contain the the production of signals at each round: for the whole population (aux) and each agent (auxn) for agent in agents: for sim in range(simulations): for mu in range(len(samples)): for round in range(1, len(pairs) + 1): aux = [statistics[sim][agent][mu][signal][round - 1] for signal in signals] aux1 = [statistics[sim][1][mu][signal][round - 1] for signal in signals] aux2 = [statistics[sim][2][mu][signal][round - 1] for signal in signals] aux3 = [statistics[sim][3][mu][signal][round - 1] for signal in signals] aux4 = [statistics[sim][4][mu][signal][round - 1] for signal in signals] aux5 = [statistics[sim][5][mu][signal][round - 1] for signal in signals] aux6 = [statistics[sim][6][mu][signal][round - 1] for signal in signals] aux7 = [statistics[sim][7][mu][signal][round - 1] for signal in signals] aux8 = [statistics[sim][8][mu][signal][round - 1] for signal in signals] aux9 = [statistics[sim][9][mu][signal][round - 1] for signal in signals] aux10 = [statistics[sim][10][mu][signal][round - 1] for signal in signals] # List that contains the summation of produced signals at the level of the population summation_pop = [] # # List that contains the summation of produced signals at the level of each subpopulation summation_subpop_1 = [] summation_subpop_2 = [] # Piece of code to append the lists of signals for i in range(len(aux1)): # At the population level summation_pop.append( aux1[i] + aux2[i] + aux3[i] + aux4[i] + aux5[i] + aux6[i] + aux7[i] + aux8[i] + aux9[i] + aux10[i]) # At the subpopulation level for i in range(len(aux1)): summation_subpop_1.append(aux1[i] + aux2[i] + aux3[i] + aux4[i]) summation_subpop_2.append(aux5[i] + aux6[i] + aux7[i] + aux8[i]) # Writing csv file writer.writerow([sim + 1, mu + 1, agent, menLen, round, condition, scenario, i_power, samples[mu]['cont'], samples[mu]['coord'], samples[mu]['conform'], samples[mu]['confirm'], samples[mu]['mut']] + aux + [summation_pop] + [shannon(summation_pop)] + [ shannon(summation_subpop_1)] + [shannon(summation_subpop_2)] + [ summation_subpop_1] + [summation_subpop_2] + [brillouin_d(summation_pop)] + [margalef(summation_pop)] + [ simpson(summation_pop)] + [simpson_e(summation_pop)] + [ observed_otus(summation_pop) / 8])