piegy 2.2.3__tar.gz → 2.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. {piegy-2.2.3/src/piegy.egg-info → piegy-2.3.1}/PKG-INFO +1 -1
  2. {piegy-2.2.3 → piegy-2.3.1}/pyproject.toml +1 -1
  3. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/C_core/patch.h +6 -6
  4. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/C_core/sim_funcs.c +7 -7
  5. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/C_core/sim_funcs.h +12 -12
  6. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/__init__.py +2 -2
  7. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/__version__.py +3 -1
  8. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/figures.py +74 -17
  9. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/test_var.py +8 -2
  10. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/tools/figure_tools.py +1 -1
  11. {piegy-2.2.3 → piegy-2.3.1/src/piegy.egg-info}/PKG-INFO +1 -1
  12. {piegy-2.2.3 → piegy-2.3.1}/LICENSE.txt +0 -0
  13. {piegy-2.2.3 → piegy-2.3.1}/MANIFEST.in +0 -0
  14. {piegy-2.2.3 → piegy-2.3.1}/README.md +0 -0
  15. {piegy-2.2.3 → piegy-2.3.1}/setup.cfg +0 -0
  16. {piegy-2.2.3 → piegy-2.3.1}/setup.py +0 -0
  17. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/C_core/Makefile +0 -0
  18. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/C_core/model.c +0 -0
  19. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/C_core/model.h +0 -0
  20. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/C_core/patch.c +0 -0
  21. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/C_core/runner.c +0 -0
  22. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/analysis.py +0 -0
  23. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/build_info.py +0 -0
  24. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/data_tools.py +0 -0
  25. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/simulation.py +0 -0
  26. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/simulation_py.py +0 -0
  27. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/tools/__init__.py +0 -0
  28. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/tools/file_tools.py +0 -0
  29. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/tools/find_C.py +0 -0
  30. {piegy-2.2.3 → piegy-2.3.1}/src/piegy/videos.py +0 -0
  31. {piegy-2.2.3 → piegy-2.3.1}/src/piegy.egg-info/SOURCES.txt +0 -0
  32. {piegy-2.2.3 → piegy-2.3.1}/src/piegy.egg-info/dependency_links.txt +0 -0
  33. {piegy-2.2.3 → piegy-2.3.1}/src/piegy.egg-info/requires.txt +0 -0
  34. {piegy-2.2.3 → piegy-2.3.1}/src/piegy.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: piegy
3
- Version: 2.2.3
3
+ Version: 2.3.1
4
4
  Summary: Payoff-Driven Stochastic Spatial Model for Evolutionary Game Theory
5
5
  Author-email: Chenning Xu <cxu7@caltech.edu>
6
6
  License: BSD 3-Clause License
@@ -4,7 +4,7 @@ build-backend = 'setuptools.build_meta'
4
4
 
5
5
  [project]
6
6
  name = 'piegy'
7
- version = '2.2.3'
7
+ version = '2.3.1'
8
8
  description = 'Payoff-Driven Stochastic Spatial Model for Evolutionary Game Theory'
9
9
  readme = 'README.md'
10
10
  requires-python = '>=3.7'
@@ -23,14 +23,14 @@ typedef struct patch_t {
23
23
  double V_pi;
24
24
 
25
25
  struct patch_t* nb[4];
26
- long double U_weight[4]; // stores migration weight of each of the 4 neighbors
27
- long double V_weight[4];
28
- long double sum_U_weight; // sum of U_weight
29
- long double sum_V_weight;
26
+ double U_weight[4]; // stores migration weight of each of the 4 neighbors
27
+ double V_weight[4];
28
+ double sum_U_weight; // sum of U_weight
29
+ double sum_V_weight;
30
30
  double pi_death_rates[4];
31
- long double mig_rates[8];
31
+ double mig_rates[8];
32
32
  double sum_pi_death_rates;
33
- long double sum_mig_rates;
33
+ double sum_mig_rates;
34
34
  } patch_t;
35
35
 
36
36
  // in .c
@@ -69,7 +69,7 @@ static void find_nb_periodical(size_t* restrict nb, size_t i, size_t j, size_t N
69
69
 
70
70
  // single_init function: initializes world, runs 1 event, returns updated variables
71
71
  static double single_init(const model_t* mod, patch_t* world, size_t* nb_indices,
72
- long double* patch_rates, long double* sum_rates_by_row, long double* sum_rates_p, signal_t* sig_p, patch_picked_t* picked_p) {
72
+ double* patch_rates, double* sum_rates_by_row, double* sum_rates_p, signal_t* sig_p, patch_picked_t* picked_p) {
73
73
 
74
74
  size_t N = mod->N;
75
75
  size_t M = mod->M;
@@ -141,7 +141,7 @@ static double single_init(const model_t* mod, patch_t* world, size_t* nb_indices
141
141
  }
142
142
 
143
143
  // pick the first random event
144
- long double expected_sum = random01() * *sum_rates_p;
144
+ double expected_sum = random01() * *sum_rates_p;
145
145
  find_patch(picked_p, expected_sum, patch_rates, sum_rates_by_row, *sum_rates_p, N, M);
146
146
  size_t picked_idx = picked_p->i * M + picked_p->j;
147
147
  size_t e0 = find_event(&world[picked_idx], expected_sum - picked_p->current_sum);
@@ -223,9 +223,9 @@ static uint8_t single_test(model_t* restrict mod, uint32_t update_sum_freq, char
223
223
  patch_t* world = (patch_t*) calloc(NM, sizeof(patch_t));
224
224
  size_t* nb_indices = (size_t*) calloc(NM * 4, sizeof(size_t));
225
225
 
226
- long double* patch_rates = (long double*) calloc(NM, sizeof(long double));
227
- long double* sum_rates_by_row = (long double*) calloc(N, sizeof(long double));
228
- long double sum_rates = 0;
226
+ double* patch_rates = (double*) calloc(NM, sizeof(double));
227
+ double* sum_rates_by_row = (double*) calloc(N, sizeof(double));
228
+ double sum_rates = 0;
229
229
 
230
230
  signal_t signal;
231
231
  patch_picked_t picked;
@@ -399,7 +399,7 @@ static uint8_t single_test(model_t* restrict mod, uint32_t update_sum_freq, char
399
399
 
400
400
 
401
401
  // pick a random event
402
- long double expected_sum = random01() * sum_rates;
402
+ double expected_sum = random01() * sum_rates;
403
403
  find_patch(&picked, expected_sum, patch_rates, sum_rates_by_row, sum_rates, N, M);
404
404
  size_t picked_idx = picked.i * M + picked.j;
405
405
  uint8_t e0 = find_event(&world[picked_idx], expected_sum - picked.current_sum);
@@ -477,7 +477,7 @@ static uint8_t single_test(model_t* restrict mod, uint32_t update_sum_freq, char
477
477
 
478
478
 
479
479
 
480
- static void single_test_free(patch_t** world, size_t** nb_indices, long double** patch_rates, long double** sum_rates_by_row) {
480
+ static void single_test_free(patch_t** world, size_t** nb_indices, double** patch_rates, double** sum_rates_by_row) {
481
481
  free(*world);
482
482
  free(*nb_indices);
483
483
  free(*patch_rates);
@@ -37,7 +37,7 @@
37
37
 
38
38
  // where exp(x) is considered overflow
39
39
  // below the actual bound (709) because the large numbers will be computed with close-to-0 ones (payoff rates), so higher accuracy is needed
40
- #define EXP_OVERFLOW_BOUND 600
40
+ #define EXP_OVERFLOW_BOUND 500
41
41
 
42
42
 
43
43
  static uint64_t pcg_state = 0;
@@ -83,9 +83,9 @@ typedef struct signal_t {
83
83
  static void find_nb_zero_flux(size_t* restrict nb, size_t i, size_t j, size_t N, size_t M, size_t NM);
84
84
  static void find_nb_periodical(size_t* restrict nb, size_t i, size_t j, size_t N, size_t M, size_t NM);
85
85
  static double single_init(const model_t* mod, patch_t* world, size_t* nb_indices,
86
- long double* patch_rates, long double* sum_rates_by_row, long double* sum_rates, signal_t* sig_p, patch_picked_t* picked_p) ;
86
+ double* patch_rates, double* sum_rates_by_row, double* sum_rates, signal_t* sig_p, patch_picked_t* picked_p) ;
87
87
  static uint8_t single_test(model_t* restrict mod, uint32_t update_sum_frequency, char* message);
88
- static void single_test_free(patch_t** world, size_t** nb_indices, long double** patch_rates, long double** sum_rates_by_row);
88
+ static void single_test_free(patch_t** world, size_t** nb_indices, double** patch_rates, double** sum_rates_by_row);
89
89
  uint8_t run(model_t* mod, char* message, size_t msg_len, uint32_t update_sum_freq);
90
90
 
91
91
 
@@ -94,12 +94,12 @@ uint8_t run(model_t* mod, char* message, size_t msg_len, uint32_t update_sum_fre
94
94
  * Inline Functions
95
95
  */
96
96
 
97
- static inline long double random01() {
97
+ static inline double random01() {
98
98
  // generate a 24 bit random int, then convert to a (0, 1) ranged double
99
99
  uint32_t r1 = rand() & 0x7fff; // RAND_MAX is different across machines, ensure 15 bits
100
100
  uint32_t r2 = rand() & 0x7fff;
101
101
 
102
- long double r_combined = (r1 << 15) + r2; // discard the lower 3 bits, which are unstable
102
+ double r_combined = (r1 << 15) + r2; // discard the lower 3 bits, which are unstable
103
103
  return (r_combined + 1) / RAND_UPPER_PLUS_2;
104
104
  }
105
105
 
@@ -155,8 +155,8 @@ static inline uint8_t update_mig_one(patch_t* restrict p, const double* restrict
155
155
 
156
156
  double mu1_U = P_start[0] * (double)p->U;
157
157
  double mu2_V = P_start[1] * (double)p->V;
158
- long double* p_U_weight = p->U_weight;
159
- long double* p_V_weight = p->V_weight;
158
+ double* p_U_weight = p->U_weight;
159
+ double* p_V_weight = p->V_weight;
160
160
 
161
161
  patch_t* nbi = p->nb[nb_loc];
162
162
  p->sum_U_weight -= p_U_weight[nb_loc];
@@ -210,8 +210,8 @@ static inline uint8_t update_mig_all(patch_t* restrict p, const double* restrict
210
210
  double mu1_U = P_start[0] * (double)p->U;
211
211
  double mu2_V = P_start[1] * (double)p->V;
212
212
 
213
- long double* p_U_weight = p->U_weight;
214
- long double* p_V_weight = p->V_weight;
213
+ double* p_U_weight = p->U_weight;
214
+ double* p_V_weight = p->V_weight;
215
215
 
216
216
  p->sum_U_weight = 0.0;
217
217
  p->sum_V_weight = 0.0;
@@ -255,7 +255,7 @@ static inline uint8_t update_mig_all(patch_t* restrict p, const double* restrict
255
255
 
256
256
 
257
257
 
258
- static inline uint8_t find_event(const patch_t* restrict p, long double expected_sum) {
258
+ static inline uint8_t find_event(const patch_t* restrict p, double expected_sum) {
259
259
  size_t event = 0;
260
260
  double current_sum;
261
261
 
@@ -330,8 +330,8 @@ static inline void change_popu(patch_t* restrict p, uint8_t s) {
330
330
  * Main Simulation Functions
331
331
  */
332
332
 
333
- static inline void find_patch(patch_picked_t* restrict picked, long double expected_sum,
334
- const long double* restrict patch_rates, const long double* restrict sum_rates_by_row, long double sum_rates, size_t N, size_t M) {
333
+ static inline void find_patch(patch_picked_t* restrict picked, double expected_sum,
334
+ const double* restrict patch_rates, const double* restrict sum_rates_by_row, double sum_rates, size_t N, size_t M) {
335
335
  double current_sum = 0;
336
336
  size_t row = 0;
337
337
  size_t col = 0;
@@ -28,7 +28,7 @@ from .data_tools import save_data, read_data
28
28
  from .analysis import rounds_expected, scale_maxtime, check_convergence, combine_sim
29
29
 
30
30
  from .figures import (UV_hmap, UV_bar, UV_dyna, UV_hist, UV_std, UV_expected,
31
- pi_hmap, pi_bar, pi_dyna, pi_hist, pi_std, UV_pi)
31
+ pi_hmap, pi_bar, pi_dyna, pi_hist, pi_std, UV_pi, video_fig)
32
32
 
33
33
  from .test_var import (test_var1, var_UV1, var_pi1, var_convergence1, get_dirs1,
34
34
  test_var2, var_UV2, var_pi2, var_convergence2, get_dirs2)
@@ -43,7 +43,7 @@ data_members = ['save_data', 'read_data']
43
43
  analysis_members = ['expected_rounds', 'scale_maxtime', 'check_convergence', 'combine_mod']
44
44
 
45
45
  figures_members = ['UV_hmap', 'UV_bar', 'UV_dyna', 'UV_hist', 'UV_std', 'UV_expected_val', 'UV_expected',
46
- 'pi_hmap', 'pi_bar', 'pi_dyna', 'pi_hist', 'pi_std', 'UV_pi']
46
+ 'pi_hmap', 'pi_bar', 'pi_dyna', 'pi_hist', 'pi_std', 'UV_pi', 'video_fig']
47
47
 
48
48
  test_var_members = ['test_var1', 'var_UV1', 'var_pi1', 'var_convergence1', 'get_dirs1',
49
49
  'test_var2', 'var_UV2', 'var_pi2', 'var_convergence2', 'get_dirs2']
@@ -1,4 +1,4 @@
1
- __version__ = '2.2.3'
1
+ __version__ = '2.3.1'
2
2
 
3
3
  '''
4
4
  version history:
@@ -35,4 +35,6 @@ version history:
35
35
  2.2.1: change heatmap plotting tool from Seaborn to Matplotlib. Change video maker to cv2 (opencv-python).
36
36
  2.2.2: impose stricter overflow error check. Used update_mig_one function (already written before, didn't use). This gives 30% speed improvement.
37
37
  2.2.3: raised rate calculation to higher accuracy (long double), and switched to 30-bit random number generator.
38
+ 2.3.1: roll back accuracy update. Decrease toleratable bound for exponent of exp() to 500.
39
+ Add video_fig function to figures module, which plots change of patch popu/payoff overtime in a 2D figure. Add auto-sorting for values passed to test_var plot functions.
38
40
  '''
@@ -306,9 +306,9 @@ def pi_hmap(mod, ax_U = None, ax_V = None, U_color = 'BuPu', V_color = 'YlGn', s
306
306
  Upi_ave = figure_t.ave_interval(mod.Upi, start_index, end_index)
307
307
  V_pi_ave = figure_t.ave_interval(mod.Vpi, start_index, end_index)
308
308
 
309
- U_title = figure_t.gen_title('Payoff ' + r'$p_U$', start, end)
309
+ U_title = figure_t.gen_title('Payoff ' + r'$p_H$', start, end)
310
310
  U_text = figure_t.gen_text(np.mean(Upi_ave), np.std(Upi_ave))
311
- V_title = figure_t.gen_title('Payoff ' + r'$p_V$', start, end)
311
+ V_title = figure_t.gen_title('Payoff ' + r'$p_D$', start, end)
312
312
  V_text = figure_t.gen_text(np.mean(V_pi_ave), np.std(V_pi_ave))
313
313
 
314
314
  figure_t.hmap(Upi_ave, ax_U, U_color, U_title, U_text, vmin = vrange_U[0], vmax = vrange_U[1])
@@ -334,13 +334,13 @@ def pi_bar(mod, ax_U = None, ax_V = None, U_color = 'violet', V_color = 'yellowg
334
334
  Upi_ave = figure_t.ave_interval_1D(mod.Upi, start_index, end_index)
335
335
  V_pi_ave = figure_t.ave_interval_1D(mod.Vpi, start_index, end_index)
336
336
 
337
- U_title = figure_t.gen_title(r'$p_U$', start, end)
337
+ U_title = figure_t.gen_title(r'$p_H$', start, end)
338
338
  U_text = figure_t.gen_text(np.mean(Upi_ave), np.std(Upi_ave))
339
- V_title = figure_t.gen_title(r'$p_V$', start, end)
339
+ V_title = figure_t.gen_title(r'$p_D$', start, end)
340
340
  V_text = figure_t.gen_text(np.mean(V_pi_ave), np.std(V_pi_ave))
341
341
 
342
- ax_U = figure_t.bar(Upi_ave, ax_U, U_color, 'Patches', 'Payoff ' + r'$p_U$', U_title, U_text)
343
- ax_V = figure_t.bar(V_pi_ave, ax_V, V_color, 'Patches', 'Payoff ' + r'$p_V$', V_title, V_text)
342
+ ax_U = figure_t.bar(Upi_ave, ax_U, U_color, 'Patches', 'Payoff ' + r'$p_H$', U_title, U_text)
343
+ ax_V = figure_t.bar(V_pi_ave, ax_V, V_color, 'Patches', 'Payoff ' + r'$p_D$', V_title, V_text)
344
344
 
345
345
  return ax_U, ax_V
346
346
 
@@ -376,12 +376,12 @@ def pi_dyna(mod, ax = None, interval = 20, grid = True):
376
376
  if ax == None:
377
377
  _, ax = plt.subplots()
378
378
  ax.grid(grid)
379
- ax.plot(xaxis, U_curve, CURVE_TYPE, label = r'$p_U$')
380
- ax.plot(xaxis, V_curve, CURVE_TYPE, label = r'$p_V$')
379
+ ax.plot(xaxis, U_curve, CURVE_TYPE, label = r'$p_H$')
380
+ ax.plot(xaxis, V_curve, CURVE_TYPE, label = r'$p_D$')
381
381
  ax.plot(xaxis, total_curve, CURVE_TYPE, label = 'total')
382
382
  ax.set_xlabel('Time')
383
383
  ax.set_ylabel('Payoff')
384
- ax.set_title('Payoff ' + r'$p_U$' + ' & ' + r'$p_V$' + ' over time')
384
+ ax.set_title('Payoff ' + r'$p_H$' + ' & ' + r'$p_D$' + ' over time')
385
385
  ax.legend()
386
386
 
387
387
  return ax
@@ -408,17 +408,17 @@ def pi_hist(mod, ax_U = None, ax_V = None, U_color = 'violet', V_color = 'yellow
408
408
 
409
409
  if ax_U == None:
410
410
  _, ax_U = plt.subplots()
411
- ax_U.set_xlabel('Payoff ' + r'$p_U$')
411
+ ax_U.set_xlabel('Payoff ' + r'$p_H$')
412
412
  ax_U.set_ylabel('Density')
413
413
  ax_U.hist(Upi_ave, color = U_color, density = True)
414
- ax_U.set_title(figure_t.gen_title('Payoff ' + r'$p_U$' + ' Hist', start, end))
414
+ ax_U.set_title(figure_t.gen_title('Payoff ' + r'$p_H$' + ' Hist', start, end))
415
415
 
416
416
  if ax_V == None:
417
417
  _, ax_V = plt.subplots()
418
- ax_V.set_xlabel('Payoff ' + r'$p_V$')
418
+ ax_V.set_xlabel('Payoff ' + r'$p_D$')
419
419
  ax_V.set_ylabel('Density')
420
420
  ax_V.hist(V_pi_ave, color = V_color, density = True)
421
- ax_V.set_title(figure_t.gen_title('Payoff ' + r'$p_V$' + ' Hist', start, end))
421
+ ax_V.set_title(figure_t.gen_title('Payoff ' + r'$p_D$' + ' Hist', start, end))
422
422
 
423
423
  return ax_U, ax_V
424
424
 
@@ -453,8 +453,8 @@ def pi_std(mod, ax = None, interval = 20, grid = True):
453
453
  if ax == None:
454
454
  _, ax = plt.subplots()
455
455
  ax.grid(grid)
456
- ax.plot(xaxis, Upi_std, CURVE_TYPE, label = r'$p_U$' + ' std')
457
- ax.plot(xaxis, V_pi_std, CURVE_TYPE, label = r'$p_V$' + ' std')
456
+ ax.plot(xaxis, Upi_std, CURVE_TYPE, label = r'$p_H$' + ' std')
457
+ ax.plot(xaxis, V_pi_std, CURVE_TYPE, label = r'$p_D$' + ' std')
458
458
  ax.legend()
459
459
  ax.set_xlabel('Time')
460
460
  ax.set_ylabel('Std Dev')
@@ -484,9 +484,66 @@ def UV_pi(mod, ax_U = None, ax_V = None, U_color = 'violet', V_color = 'yellowgr
484
484
  V_pi_ave = figure_t.ave_interval(mod.Vpi, start_index, end_index)
485
485
 
486
486
 
487
- ax_U = figure_t.scatter(U_ave, Upi_ave, ax_U, U_color, alpha, xlabel = 'U', ylabel = 'Payoff ' + r'$p_U$', title = 'U - ' + r'$p_U$')
488
- ax_V = figure_t.scatter(V_ave, V_pi_ave, ax_V, V_color, alpha, xlabel = 'V', ylabel = 'Payoff ' + r'$p_V$', title = 'V - ' + r'$p_V$')
487
+ ax_U = figure_t.scatter(U_ave, Upi_ave, ax_U, U_color, alpha, xlabel = 'U', ylabel = 'Payoff ' + r'$p_H$', title = 'U - ' + r'$p_H$')
488
+ ax_V = figure_t.scatter(V_ave, V_pi_ave, ax_V, V_color, alpha, xlabel = 'V', ylabel = 'Payoff ' + r'$p_D$', title = 'V - ' + r'$p_D$')
489
489
 
490
490
  return ax_U, ax_V
491
491
 
492
492
 
493
+
494
+ def video_fig(mod, ax_list = None, num_itv = 100, U_color = 'Purples', V_color = 'Greens'):
495
+ '''
496
+ Plot distribution dynamics over time, of U, V population and payoff.
497
+
498
+ mod: simulation.model object
499
+ ax_list: a 2*2 list of ax, or None (a new 2*2 ax_list will be created)
500
+ num_itv: how many time intervals to plot
501
+ U_color & V_color: matplotlib color map, color for U, V population and payoff.
502
+ '''
503
+
504
+ if num_itv > mod.max_record:
505
+ raise ValueError('num_itv too large, larger than mod.max_record')
506
+ idx_step = int(mod.max_record / num_itv)
507
+ ave_U = []
508
+ ave_V = []
509
+ ave_Upi = []
510
+ ave_Vpi = []
511
+
512
+ for lower_idx in range(0, mod.max_record, idx_step):
513
+ ave_U.append(figure_t.ave_interval_1D(mod.U, lower_idx, lower_idx + idx_step))
514
+ ave_V.append(figure_t.ave_interval_1D(mod.V, lower_idx, lower_idx + idx_step))
515
+ ave_Upi.append(figure_t.ave_interval_1D(mod.Upi, lower_idx, lower_idx + idx_step))
516
+ ave_Vpi.append(figure_t.ave_interval_1D(mod.Vpi, lower_idx, lower_idx + idx_step))
517
+
518
+ if ax_list == None:
519
+
520
+ _, ax_list = plt.subplots(2, 2, figsize = (9.6, 12.8), dpi = 300)
521
+
522
+ for i in range(2):
523
+ for j in range(2):
524
+ ax_list[i, j].spines['top'].set_visible(False)
525
+ ax_list[i, j].spines['right'].set_visible(False)
526
+ ax_list[i, j].set_xlabel('Patches')
527
+ ax_list[i, j].set_ylabel('Time')
528
+ ax_list[i, j].set_xlim([0, mod.M - 1])
529
+ ax_list[i, j].set_ylim([0, mod.maxtime])
530
+
531
+
532
+ im = ax_list[0, 0].imshow(ave_U, cmap = U_color)
533
+ ax_list[0, 0].get_figure().colorbar(im, ax = ax_list[0, 0])
534
+ ax_list[0, 0].set_title('Population U over time')
535
+
536
+ im = ax_list[0, 1].imshow(ave_V, cmap = V_color)
537
+ ax_list[0, 1].get_figure().colorbar(im, ax = ax_list[0, 1])
538
+ ax_list[0, 1].set_title('Population V over time')
539
+
540
+ im = ax_list[1, 0].imshow(ave_Upi, cmap = U_color)
541
+ ax_list[1, 0].get_figure().colorbar(im, ax = ax_list[1, 0])
542
+ ax_list[1, 0].set_title('Payoff ' + r'$p_H$' + ' over time')
543
+
544
+ im = ax_list[1, 1].imshow(ave_Vpi, cmap = V_color)
545
+ ax_list[1, 1].get_figure().colorbar(im, ax = ax_list[1, 1])
546
+ ax_list[1, 1].set_title('Payoff ' + r'$p_D$' + ' over time')
547
+
548
+ return ax_list
549
+
@@ -169,6 +169,7 @@ def var_UV1(var, values, var_dirs, ax_U = None, ax_V = None, start = 0.95, end =
169
169
  # average value of U, V over the interval. One entry for one value of var
170
170
  U_ave = []
171
171
  V_ave = []
172
+ values = sorted(values)
172
173
 
173
174
  for k in range(len(var_dirs)):
174
175
  try:
@@ -234,6 +235,8 @@ def var_UV2(var1, var2, values1, values2, var_dirs, ax_U = None, ax_V = None, va
234
235
  # average value of U, V over the interval. One entry for one values of var1, var2
235
236
  U_ave = [[] for k1 in range(len(var_dirs))]
236
237
  V_ave = [[] for k1 in range(len(var_dirs))]
238
+ values1 = sorted(values1)
239
+ values2 = sorted(values2)
237
240
 
238
241
  for k1 in range(len(var_dirs)):
239
242
  for k2 in range(len(var_dirs[k1])):
@@ -321,6 +324,7 @@ def var_pi1(var, values, var_dirs, ax_U = None, ax_V = None, start = 0.95, end =
321
324
  # take average value of payoff over an interval of time
322
325
  U_ave = []
323
326
  V_ave = []
327
+ values = sorted(values)
324
328
 
325
329
  for k in range(len(var_dirs)):
326
330
  try:
@@ -347,12 +351,12 @@ def var_pi1(var, values, var_dirs, ax_U = None, ax_V = None, start = 0.95, end =
347
351
  var_disp = PATCH_VAR_DISP[var]
348
352
 
349
353
  ax_U.set_xlabel(var_disp)
350
- ax_U.set_ylabel('Payoff ' + r'$p_U$')
354
+ ax_U.set_ylabel('Payoff ' + r'$p_H$')
351
355
  ax_U.plot(values, U_ave, DOTTED_CURVE_TYPE, color = U_color)
352
356
  ax_U.set_title(figure_t.gen_title(var_disp + r'$\,-\,p_U$', start, end))
353
357
 
354
358
  ax_V.set_xlabel(var_disp)
355
- ax_V.set_ylabel('Payoff ' + r'$p_V$')
359
+ ax_V.set_ylabel('Payoff ' + r'$p_D$')
356
360
  ax_V.plot(values, V_ave, DOTTED_CURVE_TYPE, color = V_color)
357
361
  ax_V.set_title(figure_t.gen_title(var_disp + r'$\,-\,p_V$', start, end))
358
362
 
@@ -384,6 +388,8 @@ def var_pi2(var1, var2, values1, values2, var_dirs, ax_U = None, ax_V = None, va
384
388
  # take average value of payoff over an interval of time
385
389
  U_ave = [[] for k1 in range(len(var_dirs))]
386
390
  V_ave = [[] for k1 in range(len(var_dirs))]
391
+ values1 = sorted(values1)
392
+ values2 = sorted(values2)
387
393
 
388
394
  for k1 in range(len(var_dirs)):
389
395
  for k2 in range(len(var_dirs[k1])):
@@ -172,7 +172,7 @@ def ave_interval(data, start_index, end_index):
172
172
  def ave_interval_1D(data, start_index, end_index):
173
173
  '''
174
174
  Calculate average value of data over an interval. Return a 1D np.array.
175
- Assume data is 3D and has shape (1 x M x K) or (N x 1 x K). Then implicitly 'compress' that 1 and takes average on the 3rd axis.
175
+ Assume data is 3D and has shape (N x M x K). Then implicitly 'compress' that N x M to 1D (NM) and takes average on the 3rd axis K.
176
176
 
177
177
  Input:
178
178
  data: 3D np.array or list. One of its dimensions must have size 1. Will take average on the 3rd axis.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: piegy
3
- Version: 2.2.3
3
+ Version: 2.3.1
4
4
  Summary: Payoff-Driven Stochastic Spatial Model for Evolutionary Game Theory
5
5
  Author-email: Chenning Xu <cxu7@caltech.edu>
6
6
  License: BSD 3-Clause License
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes