piegy 2.0.3__py3-none-any.whl → 2.0.4__py3-none-any.whl
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.
- piegy/C_core/piegyc.so +0 -0
- piegy/__version__.py +2 -1
- piegy/simulation.py +28 -29
- {piegy-2.0.3.dist-info → piegy-2.0.4.dist-info}/METADATA +2 -2
- {piegy-2.0.3.dist-info → piegy-2.0.4.dist-info}/RECORD +8 -8
- {piegy-2.0.3.dist-info → piegy-2.0.4.dist-info}/WHEEL +0 -0
- {piegy-2.0.3.dist-info → piegy-2.0.4.dist-info}/licenses/LICENSE.txt +0 -0
- {piegy-2.0.3.dist-info → piegy-2.0.4.dist-info}/top_level.txt +0 -0
piegy/C_core/piegyc.so
CHANGED
Binary file
|
piegy/__version__.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
__version__ = '2.0.
|
1
|
+
__version__ = '2.0.4'
|
2
2
|
|
3
3
|
'''
|
4
4
|
version history:
|
@@ -25,4 +25,5 @@ version history:
|
|
25
25
|
2.0.1: re-upload, the C core is not included in package.
|
26
26
|
2.0.2: update version number in __version__.py and update README.
|
27
27
|
2.0.3: speed boost & debugging in C core. Add check_overflow feature in simulation module, checks whether overflow/too large numbers might be encountered in simulation.
|
28
|
+
2.0.4: minor debuggings.
|
28
29
|
'''
|
piegy/simulation.py
CHANGED
@@ -5,10 +5,11 @@ Main Module of Stochastic Simulation
|
|
5
5
|
Contains all the necessary tools to build a model and run models based on Gillespie Algorithm.
|
6
6
|
|
7
7
|
Class & Functions:
|
8
|
-
- model:
|
9
|
-
- run:
|
10
|
-
- demo_model:
|
11
|
-
- UV_expected_val:
|
8
|
+
- model: creates a stochastic mode. Run the model by ``simulation.run(mod)``
|
9
|
+
- run: runs stochastic simulation on a model.
|
10
|
+
- demo_model: returns a demo model.
|
11
|
+
- UV_expected_val: calculates the expected population of U, V at steady state, assuming no migration and any stochastic process.
|
12
|
+
- check_overflow_func: check whether an overflow might happen in simulation. This is usually done automatically when init-ing a model.
|
12
13
|
'''
|
13
14
|
|
14
15
|
|
@@ -25,8 +26,8 @@ C_LIB_PATH = os.path.join(os.path.dirname(__file__), 'C_core', 'piegyc.so')
|
|
25
26
|
|
26
27
|
# check whether overflow / too large values might be encountered
|
27
28
|
# these values are considered as exponents in exp()
|
28
|
-
EXP_OVERFLOW_BOUND =
|
29
|
-
EXP_TOO_LARGE_BOUND =
|
29
|
+
EXP_OVERFLOW_BOUND = 709 # where exp(x) reaches overflow bound
|
30
|
+
EXP_TOO_LARGE_BOUND = 88 # where exp(x) reaches 1e20
|
30
31
|
|
31
32
|
|
32
33
|
'''
|
@@ -134,7 +135,10 @@ class model:
|
|
134
135
|
self.I = np.array(I) # N x M x 2 np.array, initial population. Two init-popu for every patch (U and V)
|
135
136
|
self.X = np.array(X) # N x M x 4 np.array, matrices. The '4' comes from 2x2 matrix flattened to 1D
|
136
137
|
self.P = np.array(P) # N x M x 6 np.array, 'patch variables', i.e., mu1&2, w1&2, kappa1&2
|
137
|
-
|
138
|
+
if print_pct == None:
|
139
|
+
self.print_pct = -1
|
140
|
+
else:
|
141
|
+
self.print_pct = print_pct # int, print how much percent is done, need to be non-zero
|
138
142
|
if seed == None:
|
139
143
|
self.seed = -1 # non-negative int, seed for random number generation
|
140
144
|
else:
|
@@ -195,11 +199,12 @@ class model:
|
|
195
199
|
if np.array(P).shape != (N, M, 6):
|
196
200
|
raise ValueError('Please set P as a N x M x 6 shape list or array. 6 is for mu1, mu2, w1, w2, kappa1, kappa2')
|
197
201
|
|
198
|
-
if print_pct
|
202
|
+
if not ((print_pct == None) or (isinstance(print_pct, int) and (print_pct >= -1))):
|
203
|
+
# if not the two acceptable values: None or >= -1 int
|
199
204
|
raise ValueError('Please use an int > 0 for print_pct or None for not printing progress.')
|
200
205
|
|
201
|
-
if
|
202
|
-
raise ValueError('Please use a non-negative int as seed')
|
206
|
+
if not ((seed == None) or (isinstance(seed, int) and (seed >= -1))):
|
207
|
+
raise ValueError('Please use a non-negative int as seed, or use None for no seed.')
|
203
208
|
|
204
209
|
if not isinstance(check_overflow, bool):
|
205
210
|
raise ValueError('Please use a bool for check_overflow')
|
@@ -391,6 +396,9 @@ def run(mod, message = ""):
|
|
391
396
|
C-cored simulation
|
392
397
|
'''
|
393
398
|
|
399
|
+
if not mod.data_empty:
|
400
|
+
raise ValueError('mod has non-empty data.')
|
401
|
+
|
394
402
|
msg_len = len(message)
|
395
403
|
msg_bytes = message.encode('utf-8')
|
396
404
|
msg_buffer = ctypes.create_string_buffer(msg_bytes, msg_len)
|
@@ -404,15 +412,14 @@ def run(mod, message = ""):
|
|
404
412
|
mod.N, mod.M, mod.maxtime, mod.record_itv, mod.sim_time, mod.boundary,
|
405
413
|
I, X, P, mod.print_pct, mod.seed)
|
406
414
|
if not success:
|
407
|
-
raise RuntimeError(
|
415
|
+
raise RuntimeError('mod_init failed')
|
408
416
|
|
409
417
|
lib.run(ctypes.byref(mod_c), msg_buffer, msg_len)
|
410
418
|
|
411
|
-
mod.
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
mod.Vpi = mod_c.get_array('Vpi_1d').reshape(mod.N, mod.M, mod.max_record)
|
419
|
+
mod.set_data(False, mod.max_record, 1, mod_c.get_array('U1d').reshape(mod.N, mod.M, mod.max_record),
|
420
|
+
mod_c.get_array('V1d').reshape(mod.N, mod.M, mod.max_record),
|
421
|
+
mod_c.get_array('Upi_1d').reshape(mod.N, mod.M, mod.max_record),
|
422
|
+
mod_c.get_array('Vpi_1d').reshape(mod.N, mod.M, mod.max_record))
|
416
423
|
|
417
424
|
lib.mod_free_py(ctypes.byref(mod_c))
|
418
425
|
del mod_c
|
@@ -438,7 +445,7 @@ def demo_model():
|
|
438
445
|
X = [[[-1, 4, 0, 2] for _ in range(M)] for _ in range(N)]
|
439
446
|
|
440
447
|
# patch variables
|
441
|
-
P = [[[0.5, 0.5,
|
448
|
+
P = [[[0.5, 0.5, 1, 1, 0.001, 0.001] for _ in range(M)] for _ in range(N)]
|
442
449
|
|
443
450
|
print_pct = 25 # print progress
|
444
451
|
seed = 36 # seed for random number generation
|
@@ -479,23 +486,15 @@ def UV_expected_val(mod):
|
|
479
486
|
|
480
487
|
|
481
488
|
def check_overflow_func(mod):
|
482
|
-
overflow = False # flag for might-overflow
|
483
|
-
too_large = False # flag for might-too-large
|
484
489
|
_, _, pi_expected = UV_expected_val(mod)
|
485
490
|
for i in range(mod.N):
|
486
491
|
for j in range(mod.M):
|
487
492
|
w1_pi = pi_expected[i][j] * mod.P[i][j][2] # w1 * U_pi
|
488
493
|
w2_pi = pi_expected[i][j] * mod.P[i][j][3] # w2 * V_pi
|
489
494
|
if ((w1_pi > EXP_OVERFLOW_BOUND) or (w2_pi > EXP_OVERFLOW_BOUND)):
|
490
|
-
overflow
|
491
|
-
|
492
|
-
break
|
495
|
+
print("Warning: might cause overflow. \n\t w1, w2, or payoff matrix values too large")
|
496
|
+
return
|
493
497
|
if ((w1_pi > EXP_TOO_LARGE_BOUND) or (w2_pi > EXP_TOO_LARGE_BOUND)):
|
494
|
-
|
495
|
-
|
496
|
-
if overflow:
|
497
|
-
print("Warning: might cause overflow. \n\t w1, w2, or payoff matrix values too large")
|
498
|
-
elif too_large:
|
499
|
-
print("Warning: might encounter large values > 1e38 in simulation. \n\t w1, w2, or payoff matrix values too large")
|
500
|
-
|
498
|
+
print("Warning: might encounter large values > 3e38 in simulation. \n\t w1, w2, or payoff matrix values too large")
|
499
|
+
return
|
501
500
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: piegy
|
3
|
-
Version: 2.0.
|
3
|
+
Version: 2.0.4
|
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
|
@@ -55,7 +55,7 @@ Dynamic: license-file
|
|
55
55
|
|
56
56
|
# piegy
|
57
57
|
|
58
|
-
The package full name is: Payoff-Driven Stochastic Spatial Model for Evolutionary Game Theory. "pi" refers to "payoff, and "egy"
|
58
|
+
The package full name is: Payoff-Driven Stochastic Spatial Model for Evolutionary Game Theory. "pi" refers to "payoff, and "egy" is taken from "Evolutionary Game Theory".
|
59
59
|
|
60
60
|
Provides a stochastic spatial model for simulating the interaction and evolution of two species in either 1D or 2D space, as well as analytic tools.
|
61
61
|
|
@@ -1,18 +1,18 @@
|
|
1
1
|
piegy/__init__.py,sha256=KlbuIi3_Z9YZ5dWSFTwKxwrX3jdgNO4C8ksDjyDHsbk,2064
|
2
|
-
piegy/__version__.py,sha256=
|
2
|
+
piegy/__version__.py,sha256=ydhLHcMkt_o_Ob_FaaJr7zuqNyr_hAOzLuFTcGpm3UA,1400
|
3
3
|
piegy/analysis.py,sha256=2GBsBbi7LdstSEAM0-F2bfL2kHu3MElcrw8bxZ1x6LI,8719
|
4
4
|
piegy/data_tools.py,sha256=auliVb88qKQmCX7LEDgKQvhBcwFTCXBEWKtjJ4_-rTU,3446
|
5
5
|
piegy/figures.py,sha256=GwixvD3Flaqg4feSvqr42lDR7CwZK0_2qmZg6N6_1uE,17936
|
6
|
-
piegy/simulation.py,sha256=
|
6
|
+
piegy/simulation.py,sha256=t6gusSvqKRMRc9RDEczUC36YMpDptCJEiB3I-NT3Q4o,19900
|
7
7
|
piegy/simulation_py.py,sha256=WtWhpHCosKQ457gZ-iJ-7v0N3NtyPqDfgXv4DL3aBKs,29523
|
8
8
|
piegy/test_var.py,sha256=EfItIK-FEApJTAW8rs15kdMs5xlv-8Bx6CtfpSoi8ys,23562
|
9
9
|
piegy/videos.py,sha256=QfSpOdwfaDsrQYRoiHmZ6gowzRQHom3m8kx1P65_8sM,10218
|
10
|
-
piegy/C_core/piegyc.so,sha256=
|
10
|
+
piegy/C_core/piegyc.so,sha256=sIUTEhKbLMhvUQPF22D-VZuBV2J-f-Rhq8MqPGRCatk,51320
|
11
11
|
piegy/tools/__init__.py,sha256=eYOl_HJHDonYexfrmKh3koOlxvtSo46vH6jHvCEEB4k,300
|
12
12
|
piegy/tools/figure_tools.py,sha256=54vJSJMReXidFnSPE_xFvedtgnJU3d55zQDPNBLGs98,6975
|
13
13
|
piegy/tools/file_tools.py,sha256=ncxFWeHfIE-GYLQlOrahFlhBgqPyuY3R5_93fpQeCEs,630
|
14
|
-
piegy-2.0.
|
15
|
-
piegy-2.0.
|
16
|
-
piegy-2.0.
|
17
|
-
piegy-2.0.
|
18
|
-
piegy-2.0.
|
14
|
+
piegy-2.0.4.dist-info/licenses/LICENSE.txt,sha256=wfzEht_CxOcfGGmg3f3at4mWJb9rTBjA51mXLl_3O3g,1498
|
15
|
+
piegy-2.0.4.dist-info/METADATA,sha256=H_dX6oqqDCLZWT6Dw2PmLG2VkHtfqMOaKVisZxc-eM0,5452
|
16
|
+
piegy-2.0.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
17
|
+
piegy-2.0.4.dist-info/top_level.txt,sha256=k4QLYL8PqdqDuy95-4NZD_FVLqJDsmq67tpKkBn4vMw,6
|
18
|
+
piegy-2.0.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|