-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo3.py
181 lines (126 loc) · 6.1 KB
/
demo3.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
from datetime import datetime
import os
import copy
from runEiM import RunEiM
from mod_analysis.Analysis import analysis
from mod_settings.GenParam import GenSimParam, LoadPrm
"""
## Demo 3 ##
You can run the Demo3.py file which allows you to loop though some
sequence of parameters, executing each on the RunEiM function.
In this example we have a paramater list of [0,1] which we use to vary whether
the shuffle gene is not active (0), or active (1).
In this experiment we generate a new group of num_systems number of
materials. These are then reused each loop.
The experiment results will be saved in the Results_experiemts folder, with
higher level graphs comparing the results.
However, the actual underlying data from the individual loops are still saved
in the Results folder.
"""
# Main script
if __name__ == "__main__":
# load Template Raw (unformatted) Paramaters from param%s.yaml
trprm = LoadPrm(param_file='')
# #set the model types which the experiments will be repeated for
Model_types = ['D_RN'] # or use ['R_RN', 'D_RN', 'NL_RN']
datasets = ['c2DDS'] # or use ['d2DDS', 'c2DDS', 'flipped_2DDS']
#
#
# # Run for each dataset
for dataset in datasets:
# Run Experiment for each material model
for Model in Model_types:
print("*************************************************************")
print("Experiment - Material Model:", Model)
print("*************************************************************")
# # Collect time and dat stamp of experiment
now = datetime.now()
real_d_string = now.strftime("%d_%m_%Y")
d_string = now.strftime("%Y_%m_%d")
t_string = now.strftime("%H_%M_%S")
print("Date:", real_d_string, ", Time Stamp:", t_string)
#
# # Assign Details
num_inputs = 2
#
# # Name the experiment, and add to folder name
exp_name = 'Example_UsingShuffle_%s' % (Model)
Param_Varying = 'Vary the use of the shuffle gene'
experiment_file = '%s/%s__%s___EXP_%s' % (dataset, d_string, t_string, exp_name)
# # Set parameter which will vary
Param_array = [0,1]
# # Do not load in previously generated circuits
ReUse_dir = 'na' # set defualt to 'na, this is assigned at the end of first loop'
#
num_experiments = len(Param_array) # extracts the total num of loops
for ex_loop, Param in enumerate(Param_array):
print("##################################################")
print("Experiment", ex_loop, "Out of:", num_experiments-1)
print("##################################################")
# # Create a raw (unformatted) paramater file from the loadted template
rprm = copy.deepcopy(trprm)
# Alter Prms
rprm['ReUse_dir'] = ReUse_dir
rprm['num_systems'] = 1
rprm['num_repetitions'] = 3
rprm['DE']['epochs'] = 20
rprm['DE']['training_data'] = dataset
rprm['DE']['save_fitvit'] = 0
rprm['network']['model'] = Model
rprm['network']['num_input'] = num_inputs
rprm['genome']['Shuffle']['active'] = Param
rprm['genome']['InWeight']['active'] = 0
rprm['genome']['OutWeight']['active'] = 0
rprm['mg']['plotMG'] = 1 # disable material plots
# Gen final prm dict
prm = GenSimParam(param_file=rprm,
experiment=1,
experiment_file=experiment_file,
exp_name=exp_name)
# # Run EiM
RunEiM(prm, experiment_loop=ex_loop)
# # Save the results path and toggle the reuse paramater
if ex_loop == 0:
# Set the exp to use the same materials from the first for each subsequent loop
ReUse_dir = prm['SaveDir']
# save current dir to file
with open('%s/DataDir.csv' % (prm['experiment']['file']), 'w') as dir_result_file:
dir_result_file.write(prm['SaveDir'])
dir_result_file.write("\n")
else:
# Append new dir of the results to file
with open('%s/DataDir.csv' % (prm['experiment']['file']), 'a') as dir_result_file:
dir_result_file.write(prm['SaveDir'])
dir_result_file.write("\n")
# increment experiment loop
ex_loop = ex_loop + 1
#######################################################################
# Save some data about the experiment
#######################################################################
Param_String = ''
for Parameter in Param_array:
Param_String = '%s%s \n' % (Param_String, str(Parameter))
Param_String = '%s\n%s' % (Param_String, str(Param_Varying))
path_params = "%s/Param_array.txt" % (prm['experiment']['file'])
file1 = open(path_params, "w")
file1.write(Param_String)
file1.close()
# ########################################################################
# Run Analysis and save plots to exp dir
# ########################################################################
print("\nProducing Exp analysis graphs...")
obj_anly = analysis(prm['experiment']['file'], format='png')
obj_anly.Plt_basic(Save_NotShow=1, fill=1, ExpErrors=1, StandardError=1)
obj_anly.Plt__ani(Save_NotShow=1)
# # Print end time
now = datetime.now()
d_string_fin = now.strftime("%d_%m_%Y")
t_string_fin = now.strftime("%H_%M_%S")
print("\nExperiment Finished at:", t_string_fin)
#
#
#
#
#
#
# fin