-
Notifications
You must be signed in to change notification settings - Fork 0
/
table_growth_all_pickles.py
157 lines (157 loc) · 5.87 KB
/
table_growth_all_pickles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#
# Table Growth All Pickles
#
# Peter Turney, March 1, 2021
#
# Read all fusion pickle files (fusion_storage.bin)
# and analyze all fusion events.
#
import golly as g
import model_classes as mclass
import model_functions as mfunc
import model_parameters as mparam
import numpy as np
import pickle
import os
import re
import sys
#
# Number of steps to run Game of Life in order to estimate
# growth rates of fused seeds and parts of fused seeds. This
# is a dynamic variable in model_functions.py, calculated by
# the function dimensions(), but here it is a constant, so
# that all fused seeds are evaluated by the same standard.
# Also, score_pair() in model_functions.py uses a toroid,
# but we will use an infinite plane here.
#
num_steps = 1000
#
# Location of fusion_storage.bin files -- the input pickles.
#
fusion_dir = "C:/Users/peter/Peter's Projects" + \
"/management-theory/Experiments/exper1"
#
fusion_files = [] # list of pickles
num_files = 18 # 18 fusion pickles
#
for i in range(num_files):
fusion_files.append(fusion_dir + "/run" + str(i + 1) + \
"/fusion_storage.bin")
#
# Open the fusion report file for writing.
#
report_path = "C:/Users/peter/Peter's Projects/management-theory" + \
"/Experiments/exper1/table_growth_all_pickles.tsv"
report_handle = open(report_path, "w")
#
# Write table header.
#
report_handle.write(
"run number\t" + \
"fusion number\t" + \
"whole seed birth number\t" + \
"left seed growth\t" + \
"right seed growth\t" + \
"whole seed growth\t" + \
"sum parts growth\t" + \
"max parts growth\t" + \
"whole seed growth > sum parts growth\t" + \
"whole seed growth > max parts growth\t" + \
"red cells growth\t" + \
"blue cells growth\t" + \
"orange cells growth\t" + \
"green cells growth\t" + \
"red manager\t" + \
"blue manager\t" + \
"manager-manager relation\t" + \
"manager-worker relation\t" + \
"worker-worker relation\n")
#
# Read and process each fusion file one-by-one. Each fusion
# file contains several fusion seeds.
#
run_num = 1 # run_num ranges from 1 to 18
fusion_num = 1 # fusion_num ranges from 1 to 844
#
for fusion_file in fusion_files:
fusion_handle = open(fusion_file, "ab+")
fusion_handle.seek(0) # start at the beginning of the file
fusion_list = []
# read the pickle file into fusion_list
while True:
try:
part = pickle.load(fusion_handle)
fusion_list.append(part)
except (EOFError, pickle.UnpicklingError):
break
fusion_handle.close()
# iterate through the fusion events in the current fusion file
# -- read four items at a time
for (s2, s3, s4, n) in zip(*[iter(fusion_list)] * 4):
# make a clean, empty hash table for storing statistics,
# so we start over fresh each time through this loop
stats_hash = {}
stats_hash["run number"] = run_num
stats_hash["fusion number"] = fusion_num
stats_hash["whole seed birth number"] = n
# growth of left seed, right seed, and whole fused seed
mfunc.mono_growth(g, num_steps, s2, "left seed", stats_hash)
mfunc.mono_growth(g, num_steps, s3, "right seed", stats_hash)
mfunc.mono_growth(g, num_steps, s4, "whole seed", stats_hash)
stats_hash["sum parts growth"] = \
stats_hash["left seed growth"] + \
stats_hash["right seed growth"]
stats_hash["max parts growth"] = \
max(stats_hash["left seed growth"], \
stats_hash["right seed growth"])
# difference between parts and whole
stats_hash["whole seed growth > sum parts growth"] = \
stats_hash["whole seed growth"] > stats_hash["sum parts growth"]
stats_hash["whole seed growth > max parts growth"] = \
stats_hash["whole seed growth"] > stats_hash["max parts growth"]
# growth of red, blue, orange, green
mfunc.quad_growth(g, num_steps, s2, s3, stats_hash)
# manager-worker relations
stats_hash["red manager"] = stats_hash["green cells growth"] > \
(stats_hash["red cells growth"] + stats_hash["orange cells growth"])
stats_hash["blue manager"] = stats_hash["orange cells growth"] > \
(stats_hash["blue cells growth"] + stats_hash["green cells growth"])
# note that we're adding Boolean values here, treating False as 0
# and True as 1
stats_hash["manager-manager relation"] = \
((stats_hash["red manager"] + stats_hash["blue manager"]) == 2)
stats_hash["manager-worker relation"] = \
((stats_hash["red manager"] + stats_hash["blue manager"]) == 1)
stats_hash["worker-worker relation"] = \
((stats_hash["red manager"]) + (stats_hash["blue manager"]) == 0)
# table row
report_handle.write(
"{}\t".format(stats_hash["run number"]) + \
"{}\t".format(stats_hash["fusion number"]) + \
"{}\t".format(stats_hash["whole seed birth number"]) + \
"{}\t".format(stats_hash["left seed growth"]) + \
"{}\t".format(stats_hash["right seed growth"]) + \
"{}\t".format(stats_hash["whole seed growth"]) + \
"{}\t".format(stats_hash["sum parts growth"]) + \
"{}\t".format(stats_hash["max parts growth"]) + \
"{}\t".format(stats_hash["whole seed growth > sum parts growth"]) + \
"{}\t".format(stats_hash["whole seed growth > max parts growth"]) + \
"{}\t".format(stats_hash["red cells growth"]) + \
"{}\t".format(stats_hash["blue cells growth"]) + \
"{}\t".format(stats_hash["orange cells growth"]) + \
"{}\t".format(stats_hash["green cells growth"]) + \
"{}\t".format(stats_hash["red manager"]) + \
"{}\t".format(stats_hash["blue manager"]) + \
"{}\t".format(stats_hash["manager-manager relation"]) + \
"{}\t".format(stats_hash["manager-worker relation"]) + \
"{}\n".format(stats_hash["worker-worker relation"]))
#
fusion_num += 1
#
run_num += 1
#
# Close the fusion report file.
#
report_handle.close()
#
#