|
2090 | 2090 | },
|
2091 | 2091 | {
|
2092 | 2092 | "cell_type": "code",
|
2093 |
| - "execution_count": 2, |
| 2093 | + "execution_count": null, |
2094 | 2094 | "metadata": {},
|
2095 | 2095 | "outputs": [
|
2096 | 2096 | {
|
2097 | 2097 | "name": "stdout",
|
2098 | 2098 | "output_type": "stream",
|
2099 | 2099 | "text": [
|
2100 | 2100 | "Gen 0!\n",
|
2101 |
| - "The current number of sets in pop 0 is 100\n", |
| 2101 | + "The current number of sets in pop 0 is 99\n", |
2102 | 2102 | "The current number of sets in pop 1 is 100\n",
|
2103 | 2103 | "The current number of sets in pop 2 is 100\n",
|
2104 | 2104 | "The current number of sets in pop 3 is 100\n",
|
2105 | 2105 | "Gen 50000!\n",
|
2106 |
| - "The current number of sets in pop 0 is 4\n", |
2107 |
| - "The current number of sets in pop 1 is 7\n", |
2108 |
| - "The current number of sets in pop 2 is 5\n", |
2109 |
| - "The current number of sets in pop 3 is 8\n", |
2110 |
| - "[<bound method Subpopulation.count_deme_origin_id of <metapypulation.subpopulation.Subpopulation object at 0x7d0c293abe00>>\n", |
2111 |
| - " <bound method Subpopulation.count_deme_origin_id of <metapypulation.subpopulation.Subpopulation object at 0x7d0c2940f110>>\n", |
2112 |
| - " <bound method Subpopulation.count_deme_origin_id of <metapypulation.subpopulation.Subpopulation object at 0x7d0c2940f250>>\n", |
2113 |
| - " <bound method Subpopulation.count_deme_origin_id of <metapypulation.subpopulation.Subpopulation object at 0x7d0c2924a3f0>>]\n", |
| 2106 | + "The current number of sets in pop 0 is 10\n", |
| 2107 | + "The current number of sets in pop 1 is 4\n", |
| 2108 | + "The current number of sets in pop 2 is 12\n", |
| 2109 | + "The current number of sets in pop 3 is 2\n", |
| 2110 | + "[[100 0 0 0]\n", |
| 2111 | + " [ 0 100 0 0]\n", |
| 2112 | + " [ 0 0 100 0]\n", |
| 2113 | + " [ 0 0 0 100]]\n", |
2114 | 2114 | "Gen 100000!\n",
|
2115 |
| - "The current number of sets in pop 0 is 7\n", |
2116 |
| - "The current number of sets in pop 1 is 5\n", |
2117 |
| - "The current number of sets in pop 2 is 11\n", |
2118 |
| - "The current number of sets in pop 3 is 7\n", |
| 2115 | + "The current number of sets in pop 0 is 3\n", |
| 2116 | + "The current number of sets in pop 1 is 1\n", |
| 2117 | + "The current number of sets in pop 2 is 8\n", |
| 2118 | + "The current number of sets in pop 3 is 4\n", |
2119 | 2119 | "Gen 150000!\n",
|
2120 |
| - "The current number of sets in pop 0 is 55\n", |
2121 |
| - "The current number of sets in pop 1 is 50\n", |
2122 |
| - "The current number of sets in pop 2 is 58\n", |
2123 |
| - "The current number of sets in pop 3 is 50\n" |
2124 |
| - ] |
2125 |
| - }, |
2126 |
| - { |
2127 |
| - "ename": "KeyboardInterrupt", |
2128 |
| - "evalue": "", |
2129 |
| - "output_type": "error", |
2130 |
| - "traceback": [ |
2131 |
| - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
2132 |
| - "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", |
2133 |
| - "Cell \u001b[0;32mIn[2], line 52\u001b[0m\n\u001b[1;32m 45\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mThe current number of sets in pop \u001b[39m\u001b[38;5;132;01m{\u001b[39;00msubpopulation\u001b[38;5;241m.\u001b[39mid\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m is \u001b[39m\u001b[38;5;132;01m{\u001b[39;00msubpopulation\u001b[38;5;241m.\u001b[39mcount_traits_sets()\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 46\u001b[0m \u001b[38;5;66;03m# sub_id = []\u001b[39;00m\n\u001b[1;32m 47\u001b[0m \u001b[38;5;66;03m# for ind in subpopulation.population.individuals:\u001b[39;00m\n\u001b[1;32m 48\u001b[0m \u001b[38;5;66;03m# sub_id.append(ind.original_deme_id)\u001b[39;00m\n\u001b[1;32m 49\u001b[0m \u001b[38;5;66;03m# indexes, counts = np.unique(sub_id, return_counts=True)\u001b[39;00m\n\u001b[1;32m 50\u001b[0m \u001b[38;5;66;03m# print(f\"The current deme index present in population {subpopulation.id} are {indexes} with {counts} counts.\")\u001b[39;00m\n\u001b[0;32m---> 52\u001b[0m \u001b[43mmetapopulation\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmigrate\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 53\u001b[0m metapopulation\u001b[38;5;241m.\u001b[39mmake_interact()\n\u001b[1;32m 55\u001b[0m spread \u001b[38;5;241m=\u001b[39m metapopulation\u001b[38;5;241m.\u001b[39mcount_origin_id_spread()\n", |
2134 |
| - "File \u001b[0;32m~/Documents/06_Development/03_GRIDH/ArchaeologyMetapopulations/MetapopulationsPython/metapypulation/metapopulation.py:109\u001b[0m, in \u001b[0;36mMetapopulation.migrate\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 106\u001b[0m migration_rate \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmigration_matrix[subpopulation\u001b[38;5;241m.\u001b[39mid][index]\n\u001b[1;32m 107\u001b[0m receiving_subpopulation \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msubpopulations[index]\n\u001b[0;32m--> 109\u001b[0m \u001b[43mreceiving_subpopulation\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mreceive_migrants\u001b[49m\u001b[43m(\u001b[49m\u001b[43msubpopulation\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmigration_rate\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 111\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m subpopulation \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msubpopulations:\n\u001b[1;32m 112\u001b[0m subpopulation\u001b[38;5;241m.\u001b[39mincorporate_migrants_in_population()\n", |
2135 |
| - "File \u001b[0;32m~/Documents/06_Development/03_GRIDH/ArchaeologyMetapopulations/MetapopulationsPython/metapypulation/subpopulation.py:90\u001b[0m, in \u001b[0;36mSubpopulation.receive_migrants\u001b[0;34m(self, giving_subpopulation, migration_rate)\u001b[0m\n\u001b[1;32m 88\u001b[0m number_of_migrants \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mrandom\u001b[38;5;241m.\u001b[39mbinomial(population_size, migration_rate)\n\u001b[1;32m 89\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m number_of_migrants \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[0;32m---> 90\u001b[0m individuals_to_remove \u001b[38;5;241m=\u001b[39m \u001b[43mgiving_subpopulation\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpopulation\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msample_and_remove\u001b[49m\u001b[43m(\u001b[49m\u001b[43mnumber_of_migrants\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 91\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m individual \u001b[38;5;129;01min\u001b[39;00m individuals_to_remove:\n\u001b[1;32m 92\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mincoming_migrants\u001b[38;5;241m.\u001b[39madd(individual)\n", |
2136 |
| - "File \u001b[0;32m~/Documents/06_Development/03_GRIDH/ArchaeologyMetapopulations/MetapopulationsPython/metapypulation/subpopulation.py:332\u001b[0m, in \u001b[0;36mSetOfIndividuals.sample_and_remove\u001b[0;34m(self, number_of_individuals)\u001b[0m\n\u001b[1;32m 322\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21msample_and_remove\u001b[39m(\u001b[38;5;28mself\u001b[39m, number_of_individuals: \u001b[38;5;28mint\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m List[Individual]:\n\u001b[1;32m 323\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 324\u001b[0m \u001b[38;5;124;03m Sample an individual, remove it from the Set and return it in a list.\u001b[39;00m\n\u001b[1;32m 325\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 330\u001b[0m \u001b[38;5;124;03m List[Individual]: List of all the individuals that have been sampled from the population.\u001b[39;00m\n\u001b[1;32m 331\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 332\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mshuffle\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 334\u001b[0m list_of_individuals \u001b[38;5;241m=\u001b[39m []\n\u001b[1;32m 335\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(number_of_individuals):\n", |
2137 |
| - "File \u001b[0;32m~/Documents/06_Development/03_GRIDH/ArchaeologyMetapopulations/MetapopulationsPython/metapypulation/subpopulation.py:320\u001b[0m, in \u001b[0;36mSetOfIndividuals.shuffle\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 316\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mshuffle\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 317\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 318\u001b[0m \u001b[38;5;124;03m Shuffle the Set.\u001b[39;00m\n\u001b[1;32m 319\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 320\u001b[0m \u001b[43mrandom\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mshuffle\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mindividuals\u001b[49m\u001b[43m)\u001b[49m\n", |
2138 |
| - "File \u001b[0;32m~/Software/miniforge3/envs/abm/lib/python3.13/random.py:361\u001b[0m, in \u001b[0;36mRandom.shuffle\u001b[0;34m(self, x)\u001b[0m\n\u001b[1;32m 358\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mreversed\u001b[39m(\u001b[38;5;28mrange\u001b[39m(\u001b[38;5;241m1\u001b[39m, \u001b[38;5;28mlen\u001b[39m(x))):\n\u001b[1;32m 359\u001b[0m \u001b[38;5;66;03m# pick an element in x[:i+1] with which to exchange x[i]\u001b[39;00m\n\u001b[1;32m 360\u001b[0m j \u001b[38;5;241m=\u001b[39m randbelow(i \u001b[38;5;241m+\u001b[39m \u001b[38;5;241m1\u001b[39m)\n\u001b[0;32m--> 361\u001b[0m x[i], x[j] \u001b[38;5;241m=\u001b[39m x[j], x[i]\n", |
2139 |
| - "\u001b[0;31mKeyboardInterrupt\u001b[0m: " |
| 2120 | + "The current number of sets in pop 0 is 48\n", |
| 2121 | + "The current number of sets in pop 1 is 43\n", |
| 2122 | + "The current number of sets in pop 2 is 51\n", |
| 2123 | + "The current number of sets in pop 3 is 51\n", |
| 2124 | + "Gen 200000!\n", |
| 2125 | + "The current number of sets in pop 0 is 13\n", |
| 2126 | + "The current number of sets in pop 1 is 15\n", |
| 2127 | + "The current number of sets in pop 2 is 14\n", |
| 2128 | + "The current number of sets in pop 3 is 16\n", |
| 2129 | + "Gen 250000!\n", |
| 2130 | + "The current number of sets in pop 0 is 14\n", |
| 2131 | + "The current number of sets in pop 1 is 16\n", |
| 2132 | + "The current number of sets in pop 2 is 19\n", |
| 2133 | + "The current number of sets in pop 3 is 19\n", |
| 2134 | + "Gen 300000!\n", |
| 2135 | + "The current number of sets in pop 0 is 9\n", |
| 2136 | + "The current number of sets in pop 1 is 10\n", |
| 2137 | + "The current number of sets in pop 2 is 15\n", |
| 2138 | + "The current number of sets in pop 3 is 12\n", |
| 2139 | + "Gen 350000!\n", |
| 2140 | + "The current number of sets in pop 0 is 17\n", |
| 2141 | + "The current number of sets in pop 1 is 14\n", |
| 2142 | + "The current number of sets in pop 2 is 18\n", |
| 2143 | + "The current number of sets in pop 3 is 15\n", |
| 2144 | + "[[23 21 27 22]\n", |
| 2145 | + " [26 18 25 18]\n", |
| 2146 | + " [24 28 24 27]\n", |
| 2147 | + " [27 33 24 33]]\n" |
2140 | 2148 | ]
|
2141 | 2149 | }
|
2142 | 2150 | ],
|
|
2158 | 2166 | "simulation_time = 300000\n",
|
2159 | 2167 | "for t in range(burn_in):\n",
|
2160 | 2168 | " if t%1000 == 0:\n",
|
2161 |
| - " counts_pop_1.append(metapopulation.subpopulations[0].simpson_diversity())\n", |
2162 |
| - " counts_pop_2.append(metapopulation.subpopulations[1].simpson_diversity())\n", |
2163 |
| - " counts_pop_3.append(metapopulation.subpopulations[2].simpson_diversity())\n", |
2164 |
| - " counts_pop_4.append(metapopulation.subpopulations[3].simpson_diversity())\n", |
2165 |
| - " counts_metapop.append(metapopulation.metapopulation_simpson())\n", |
| 2169 | + " counts_pop_1.append(metapopulation.subpopulations[0].gini_diversity())\n", |
| 2170 | + " counts_pop_2.append(metapopulation.subpopulations[1].gini_diversity())\n", |
| 2171 | + " counts_pop_3.append(metapopulation.subpopulations[2].gini_diversity())\n", |
| 2172 | + " counts_pop_4.append(metapopulation.subpopulations[3].gini_diversity())\n", |
| 2173 | + " counts_metapop.append(metapopulation.metapopulation_gini())\n", |
2166 | 2174 | " if t%50000 == 0:\n",
|
2167 | 2175 | " print(f\"Gen {t}!\")\n",
|
2168 | 2176 | " for subpopulation in metapopulation.subpopulations:\n",
|
|
2177 | 2185 | "metapopulation.migration_matrix = migrations\n",
|
2178 | 2186 | "for t in range(simulation_time):\n",
|
2179 | 2187 | " if t%1000 == 0:\n",
|
2180 |
| - " counts_pop_1.append(metapopulation.subpopulations[0].simpson_diversity())\n", |
2181 |
| - " counts_pop_2.append(metapopulation.subpopulations[1].simpson_diversity())\n", |
2182 |
| - " counts_pop_3.append(metapopulation.subpopulations[2].simpson_diversity())\n", |
2183 |
| - " counts_pop_4.append(metapopulation.subpopulations[3].simpson_diversity())\n", |
2184 |
| - " counts_metapop.append(metapopulation.metapopulation_simpson())\n", |
| 2188 | + " counts_pop_1.append(metapopulation.subpopulations[0].gini_diversity())\n", |
| 2189 | + " counts_pop_2.append(metapopulation.subpopulations[1].gini_diversity())\n", |
| 2190 | + " counts_pop_3.append(metapopulation.subpopulations[2].gini_diversity())\n", |
| 2191 | + " counts_pop_4.append(metapopulation.subpopulations[3].gini_diversity())\n", |
| 2192 | + " counts_metapop.append(metapopulation.metapopulation_gini())\n", |
2185 | 2193 | " if t%50000 == 0:\n",
|
2186 | 2194 | " print(f\"Gen {t + burn_in}!\")\n",
|
2187 | 2195 | " for subpopulation in metapopulation.subpopulations:\n",
|
|
0 commit comments