piegy 1.1.5__tar.gz → 2.0.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: piegy
3
- Version: 1.1.5
3
+ Version: 2.0.0
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 = '1.1.5'
7
+ version = '2.0.0'
8
8
  description = 'Payoff-Driven Stochastic Spatial Model for Evolutionary Game Theory'
9
9
  readme = 'README.md'
10
10
  requires-python = '>=3.6'
@@ -19,5 +19,7 @@ version history:
19
19
  1.1.3: update README.
20
20
  1.1.4: changed name: ``model`` module to ``simulation``, and ``model.simulation`` class to ``simulation.model``. Bug fix in videos.
21
21
  1.1.5: update README.
22
+ 1.1.6: change name of variables in model class -- for compatability with the new C core. 1.1.6 is the last verion of v1. From v2 on, the piegy package has C core.
22
23
 
24
+ 2.0.0: update simulation core to C-based.
23
25
  '''
@@ -183,7 +183,7 @@ def combine_sim(mod1, mod2):
183
183
 
184
184
  Returns:
185
185
 
186
- - sim3: a new model object whose U, V, U_pi, V_pi are weighted averages of mod1 and mod2
186
+ - sim3: a new model object whose U, V, Upi, Vpi are weighted averages of mod1 and mod2
187
187
  (weighted by sim_time).
188
188
  sim3.print_pct is set to mod1's, seed set to None, sim_time set to sum of mod1's and mod2's. All other params same as mod1
189
189
  '''
@@ -213,8 +213,8 @@ def combine_sim(mod1, mod2):
213
213
  for k in range(sim3.max_record):
214
214
  sim3.U[i][j][k] = (mod1.U[i][j][k] * mod1.sim_time + mod2.U[i][j][k] * mod2.sim_time) / combined_sim_time
215
215
  sim3.V[i][j][k] = (mod1.V[i][j][k] * mod1.sim_time + mod2.V[i][j][k] * mod2.sim_time) / combined_sim_time
216
- sim3.U_pi[i][j][k] = (mod1.U_pi[i][j][k] * mod1.sim_time + mod2.U_pi[i][j][k] * mod2.sim_time) / combined_sim_time
217
- sim3.V_pi[i][j][k] = (mod1.V_pi[i][j][k] * mod1.sim_time + mod2.V_pi[i][j][k] * mod2.sim_time) / combined_sim_time
216
+ sim3.Upi[i][j][k] = (mod1.Upi[i][j][k] * mod1.sim_time + mod2.Upi[i][j][k] * mod2.sim_time) / combined_sim_time
217
+ sim3.Vpi[i][j][k] = (mod1.Vpi[i][j][k] * mod1.sim_time + mod2.Vpi[i][j][k] * mod2.sim_time) / combined_sim_time
218
218
 
219
219
  return sim3
220
220
 
@@ -38,24 +38,19 @@ def save_data(mod, dirs = '', print_msg = True):
38
38
 
39
39
  data = []
40
40
 
41
- inputs1 = []
42
- inputs1.append(mod.N)
43
- inputs1.append(mod.M)
44
- inputs1.append(mod.maxtime)
45
- inputs1.append(mod.record_itv)
46
- inputs1.append(mod.sim_time)
47
- inputs1.append(mod.boundary)
48
- inputs1.append(mod.I.tolist())
49
- inputs1.append(mod.X.tolist())
50
- inputs1.append(mod.P.tolist())
51
- data.append(inputs1)
52
-
53
- inputs2 = []
54
- inputs2.append(mod.print_pct)
55
- inputs2.append(mod.seed)
56
- inputs2.append(mod.UV_dtype)
57
- inputs2.append(mod.pi_dtype)
58
- data.append(inputs2)
41
+ inputs = []
42
+ inputs.append(mod.N)
43
+ inputs.append(mod.M)
44
+ inputs.append(mod.maxtime)
45
+ inputs.append(mod.record_itv)
46
+ inputs.append(mod.sim_time)
47
+ inputs.append(mod.boundary)
48
+ inputs.append(mod.I.tolist())
49
+ inputs.append(mod.X.tolist())
50
+ inputs.append(mod.P.tolist())
51
+ inputs.append(mod.print_pct)
52
+ inputs.append(mod.seed)
53
+ data.append(inputs)
59
54
 
60
55
  # skipped rng
61
56
 
@@ -64,9 +59,9 @@ def save_data(mod, dirs = '', print_msg = True):
64
59
  outputs.append(mod.compress_itv)
65
60
  outputs.append(mod.U.tolist())
66
61
  outputs.append(mod.V.tolist())
67
- outputs.append(mod.U_pi.tolist())
68
- outputs.append(mod.V_pi.tolist())
69
- # H&V_pi_total are not saved, will be calculated when reading the data
62
+ outputs.append(mod.Upi.tolist())
63
+ outputs.append(mod.Vpi.tolist())
64
+ # H&Vpi_total are not saved, will be calculated when reading the data
70
65
  data.append(outputs)
71
66
 
72
67
  data_json = json.dumps(data)
@@ -112,14 +107,14 @@ def read_data(dirs):
112
107
  try:
113
108
  mod = simulation.model(N = data[0][0], M = data[0][1], maxtime = data[0][2], record_itv = data[0][3],
114
109
  sim_time = data[0][4], boundary = data[0][5], I = data[0][6], X = data[0][7], P = data[0][8],
115
- print_pct = data[1][0], seed = data[1][1], UV_dtype = data[1][2], pi_dtype = data[1][3])
110
+ print_pct = data[0][9], seed = data[0][10])
116
111
  except:
117
112
  raise ValueError('Invalid input parameters saved in data')
118
113
 
119
114
  # outputs
120
115
  try:
121
- mod.set_data(data_empty = False, max_record = data[2][0], compress_itv = data[2][1],
122
- U = data[2][2], V = data[2][3], U_pi = data[2][4], V_pi = data[2][5])
116
+ mod.set_data(data_empty = False, max_record = data[1][0], compress_itv = data[1][1],
117
+ U = data[1][2], V = data[1][3], Upi = data[1][4], Vpi = data[1][5])
123
118
  except:
124
119
  raise ValueError('Invalid model results saved in data')
125
120
 
@@ -14,13 +14,13 @@ Plots for population:
14
14
 
15
15
 
16
16
  Plots for payoff:
17
- - pi_heatmap: Used for 2D space, plot distribution of U_pi & V_pi within a specified time interval.
17
+ - pi_heatmap: Used for 2D space, plot distribution of Upi & Vpiwithin a specified time interval.
18
18
  Average payoff over that interval is taken.
19
19
  - pi_bar: Used for 1D space, counterpart of pi_heatmap.
20
- Plot average distribution of U_pi & V_pi in a specified time interval in a bar plot.
21
- - pi_dyna: Plot change of total U_pi, V_pi overtime.
22
- - pi_hist: Make a histogram of U_pi, V_pi in a specified time interval.
23
- - pi_std: Plot change of standard deviation of U_pi, V_pi over time.
20
+ Plot average distribution of Upi & Vpiin a specified time interval in a bar plot.
21
+ - pi_dyna: Plot change of total Upi, Vpiovertime.
22
+ - pi_hist: Make a histogram of Upi, Vpiin a specified time interval.
23
+ - pi_std: Plot change of standard deviation of Upi, Vpiover time.
24
24
 
25
25
 
26
26
  Popu-payoff correlation:
@@ -329,15 +329,15 @@ def pi_heatmap(mod, ax_U = None, ax_V = None, U_color = 'BuPu', V_color = 'YlGn'
329
329
  start_index = int(mod.max_record * start)
330
330
  end_index = int(mod.max_record * end)
331
331
 
332
- U_pi_ave = figure_t.ave_interval(mod.U_pi, start_index, end_index)
333
- V_pi_ave = figure_t.ave_interval(mod.V_pi, start_index, end_index)
332
+ Upi_ave = figure_t.ave_interval(mod.Upi, start_index, end_index)
333
+ V_pi_ave = figure_t.ave_interval(mod.Vpi, start_index, end_index)
334
334
 
335
335
  U_title = figure_t.gen_title('Payoff ' + r'$p_U$', start, end)
336
- U_text = figure_t.gen_text(np.mean(U_pi_ave), np.std(U_pi_ave))
336
+ U_text = figure_t.gen_text(np.mean(Upi_ave), np.std(Upi_ave))
337
337
  V_title = figure_t.gen_title('Payoff ' + r'$p_V$', start, end)
338
338
  V_text = figure_t.gen_text(np.mean(V_pi_ave), np.std(V_pi_ave))
339
339
 
340
- ax_U = figure_t.heatmap(U_pi_ave, ax_U, U_color, annot, fmt, U_title, U_text)
340
+ ax_U = figure_t.heatmap(Upi_ave, ax_U, U_color, annot, fmt, U_title, U_text)
341
341
  ax_V = figure_t.heatmap(V_pi_ave, ax_V, V_color, annot, fmt, V_title, V_text)
342
342
 
343
343
  return ax_U, ax_V
@@ -357,15 +357,15 @@ def pi_bar(mod, ax_U = None, ax_V = None, U_color = 'violet', V_color = 'yellowg
357
357
  start_index = int(mod.max_record * start)
358
358
  end_index = int(mod.max_record * end)
359
359
 
360
- U_pi_ave = figure_t.ave_interval_1D(mod.U_pi, start_index, end_index)
361
- V_pi_ave = figure_t.ave_interval_1D(mod.V_pi, start_index, end_index)
360
+ Upi_ave = figure_t.ave_interval_1D(mod.Upi, start_index, end_index)
361
+ V_pi_ave = figure_t.ave_interval_1D(mod.Vpi, start_index, end_index)
362
362
 
363
363
  U_title = figure_t.gen_title(r'$p_U$', start, end)
364
- U_text = figure_t.gen_text(np.mean(U_pi_ave), np.std(U_pi_ave))
364
+ U_text = figure_t.gen_text(np.mean(Upi_ave), np.std(Upi_ave))
365
365
  V_title = figure_t.gen_title(r'$p_V$', start, end)
366
366
  V_text = figure_t.gen_text(np.mean(V_pi_ave), np.std(V_pi_ave))
367
367
 
368
- ax_U = figure_t.bar(U_pi_ave, ax_U, U_color, 'Patches', 'Payoff ' + r'$p_U$', U_title, U_text)
368
+ ax_U = figure_t.bar(Upi_ave, ax_U, U_color, 'Patches', 'Payoff ' + r'$p_U$', U_title, U_text)
369
369
  ax_V = figure_t.bar(V_pi_ave, ax_V, V_color, 'Patches', 'Payoff ' + r'$p_V$', V_title, V_text)
370
370
 
371
371
  return ax_U, ax_V
@@ -389,8 +389,8 @@ def pi_dyna(mod, ax = None, interval = 20, grid = True):
389
389
  interval_num = int(mod.max_record / interval)
390
390
 
391
391
  for i in range(interval_num):
392
- U_ave = figure_t.ave_interval(mod.U_pi, i * interval, (i + 1) * interval)
393
- V_ave = figure_t.ave_interval(mod.V_pi, i * interval, (i + 1) * interval)
392
+ U_ave = figure_t.ave_interval(mod.Upi, i * interval, (i + 1) * interval)
393
+ V_ave = figure_t.ave_interval(mod.Vpi, i * interval, (i + 1) * interval)
394
394
 
395
395
  U_curve.append(np.sum(U_ave))
396
396
  V_curve.append(np.sum(V_ave))
@@ -427,8 +427,8 @@ def pi_hist(mod, ax_U = None, ax_V = None, U_color = 'violet', V_color = 'yellow
427
427
  start_index = int(start * mod.max_record)
428
428
  end_index = int(end * mod.max_record)
429
429
 
430
- U_pi_ave = figure_t.ave_interval_1D(mod.U_pi, start_index, end_index)
431
- V_pi_ave = figure_t.ave_interval_1D(mod.V_pi, start_index, end_index)
430
+ Upi_ave = figure_t.ave_interval_1D(mod.Upi, start_index, end_index)
431
+ V_pi_ave = figure_t.ave_interval_1D(mod.Vpi, start_index, end_index)
432
432
 
433
433
  #### plot ####
434
434
 
@@ -436,7 +436,7 @@ def pi_hist(mod, ax_U = None, ax_V = None, U_color = 'violet', V_color = 'yellow
436
436
  _, ax_U = plt.subplots()
437
437
  ax_U.set_xlabel('Payoff ' + r'$p_U$')
438
438
  ax_U.set_ylabel('Density')
439
- ax_U.hist(U_pi_ave, color = U_color, density = True)
439
+ ax_U.hist(Upi_ave, color = U_color, density = True)
440
440
  ax_U.set_title(figure_t.gen_title('Payoff ' + r'$p_U$' + ' Hist', start, end))
441
441
 
442
442
  if ax_V == None:
@@ -463,23 +463,23 @@ def pi_std(mod, ax = None, interval = 20, grid = True):
463
463
  interval = figure_t.scale_interval(interval, mod.compress_itv)
464
464
  interval_num = int(mod.max_record / interval)
465
465
 
466
- U_pi_std = []
466
+ Upi_std = []
467
467
  V_pi_std = []
468
468
 
469
469
  for i in range(interval_num):
470
- U_pi_ave = figure_t.ave_interval(mod.U_pi, i * interval, (i + 1) * interval)
471
- V_pi_ave = figure_t.ave_interval(mod.V_pi, i * interval, (i + 1) * interval)
470
+ Upi_ave = figure_t.ave_interval(mod.Upi, i * interval, (i + 1) * interval)
471
+ V_pi_ave = figure_t.ave_interval(mod.Vpi, i * interval, (i + 1) * interval)
472
472
 
473
- U_pi_std.append(np.std(U_pi_ave))
473
+ Upi_std.append(np.std(Upi_ave))
474
474
  V_pi_std.append(np.std(V_pi_ave))
475
475
 
476
476
  #### plot ####
477
- xaxis = np.linspace(0, mod.maxtime, len(U_pi_std))
477
+ xaxis = np.linspace(0, mod.maxtime, len(Upi_std))
478
478
 
479
479
  if ax == None:
480
480
  _, ax = plt.subplots()
481
481
  ax.grid(grid)
482
- ax.plot(xaxis, U_pi_std, CURVE_TYPE, label = r'$p_U$' + ' std')
482
+ ax.plot(xaxis, Upi_std, CURVE_TYPE, label = r'$p_U$' + ' std')
483
483
  ax.plot(xaxis, V_pi_std, CURVE_TYPE, label = r'$p_V$' + ' std')
484
484
  ax.legend()
485
485
  ax.set_xlabel('Time')
@@ -506,11 +506,11 @@ def UV_pi(mod, ax_U = None, ax_V = None, U_color = 'violet', V_color = 'yellowgr
506
506
  U_ave = figure_t.ave_interval_1D(mod.U, start_index, end_index)
507
507
  V_ave = figure_t.ave_interval_1D(mod.V, start_index, end_index)
508
508
 
509
- U_pi_ave = figure_t.ave_interval(mod.U_pi, start_index, end_index)
510
- V_pi_ave = figure_t.ave_interval(mod.V_pi, start_index, end_index)
509
+ Upi_ave = figure_t.ave_interval(mod.Upi, start_index, end_index)
510
+ V_pi_ave = figure_t.ave_interval(mod.Vpi, start_index, end_index)
511
511
 
512
512
 
513
- ax_U = figure_t.scatter(U_ave, U_pi_ave, ax_U, U_color, alpha, xlabel = 'U', ylabel = 'Payoff ' + r'$p_U$', title = 'U - ' + r'$p_U$')
513
+ 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$')
514
514
  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$')
515
515
 
516
516
  return ax_U, ax_V