Skip to content

Commit 59a4b7f

Browse files
committed
Added logging to file, avoiding the need to redirect output. Minor code refactoring. Added new activations. Added default parameters where possible. Removed unnecessary parameter. Updated documentation.
1 parent f50af3f commit 59a4b7f

File tree

19 files changed

+2300
-1275
lines changed

19 files changed

+2300
-1275
lines changed

MARGE.py

Lines changed: 271 additions & 58 deletions
Large diffs are not rendered by default.

doc/MARGE_user_manual/MARGE_user_manual.tex

Lines changed: 334 additions & 106 deletions
Large diffs are not rendered by default.

example/BART_example/MARGE.cfg

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ fsize = datsize.npy
4646
rmse_file = rmse
4747
r2_file = r2
4848

49-
weight_file = cnn_weights.h5
49+
weight_file = nn_weights.keras
5050

5151
gridsearch = False
52-
architectures = 2048r-2048r-2048r-2048r
5352
nodes = 2048 2048 2048 2048
5453
layers = dense dense dense dense
5554
lay_params = None None None None
@@ -60,7 +59,6 @@ epochs = 500
6059
patience = 20
6160
batch_size = 256
6261

63-
# cnn_weights.h5
6462
lengthscale = 1e-4
6563
max_lr = 1e-3
6664

example/BART_example/MARGE_gridsearch.cfg

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,45 +46,10 @@ fsize = datsize.npy
4646
rmse_file = rmse
4747
r2_file = r2
4848

49-
weight_file = cnn_weights.h5
49+
weight_file = nn_weights.keras
5050

5151
gridsearch = True
5252

53-
# Names for each architecture
54-
architectures = 512r-512r-512r-512r
55-
1024r-1024r-1024r-1024r
56-
2048r-2048r-2048r-2048r
57-
4096r-4096r-4096r-4096r
58-
512r-512r-512r
59-
1024r-1024r-1024r
60-
2048r-2048r-2048r
61-
4096r-4096r-4096r
62-
4096l05-4096l05-4096l05-4096r
63-
4096l05-4096l05-4096l05-4096l05
64-
4096l10-4096l10-4096l10-4096l10
65-
4096e05-4096e05-4096e05-4096e05
66-
4096e10-4096e10-4096e10-4096e10
67-
4096e15-4096e15-4096e15-4096e15
68-
4096e20-4096e20-4096e20-4096e20
69-
64cl05-4096l05-4096l05
70-
64cl05-4096l05-4096l05-4096l05
71-
64cl05-4096l05-4096l05-4096l05-4096l05
72-
128cl05-4096l05-4096l05
73-
128cl05-4096l05-4096l05-4096l05
74-
128cl05-4096l05-4096l05-4096l05-4096l05
75-
256cl05-4096l05-4096l05
76-
256cl05-4096l05-4096l05-4096l05
77-
256cl05-4096l05-4096l05-4096l05-4096l05
78-
64ce05-4096e05-4096e05
79-
64ce05-4096e05-4096e05-4096e05
80-
64ce05-4096e05-4096e05-4096e05-4096e05
81-
128ce05-4096e05-4096e05
82-
128ce05-4096e05-4096e05-4096e05
83-
128ce05-4096e05-4096e05-4096e05-4096e05
84-
256ce05-4096e05-4096e05
85-
256ce05-4096e05-4096e05-4096e05
86-
256ce05-4096e05-4096e05-4096e05-4096e05
87-
8853
# Number of nodes per hidden layer (that has nodes)
8954
nodes = 512 512 512 512
9055
1024 1024 1024 1024
@@ -265,7 +230,6 @@ epochs = 50
265230
patience = 20
266231
batch_size = 256
267232

268-
# cnn_weights.h5
269233
lengthscale = 2e-4
270234
max_lr = 2e-3
271235

example/BART_example/README

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Introduction
22
============
33

4-
This directory holds an example of how to run MARGE using BART for data
5-
generation. It matches the use case demonstrated in Himes et al. (2022), except
4+
This directory holds an example of how to run MARGE, using BART for data
5+
generation. It matches the use case demonstrated in Himes et al. (2020), except
66
with reduced accuracy to reduce the runtime.
77

88
********************************** IMPORTANT **********************************
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# For details on these parameters, see the MARGE_rangetest.cfg or MARGE_run.cfg
2+
# files. This file will only detail the gridsearch parameters.
3+
4+
[DEFAULT]
5+
resume = False
6+
seed = 0
7+
verb = 2
8+
9+
[MARGE]
10+
datagen = False
11+
datagenfile = datagen
12+
cfile = None
13+
processdat = False
14+
preservedat = True
15+
16+
NNModel = True
17+
trainflag = True
18+
validflag = True
19+
testflag = False
20+
21+
optimize = 0
22+
optngpus = 4
23+
optnlays = 1 3
24+
optlayer = dense dense dense
25+
optnnode = 2 4 8 16 32 64 128 256
26+
optmaxconvnode = 256
27+
optactiv = relu elu leakyrelu sig tanh
28+
optactrng = 0.01 0.6
29+
optminlr = None
30+
optmaxlr = None
31+
32+
TFR_file = circle
33+
buffer = 15
34+
ncores = 6
35+
36+
normalize = False
37+
scale = True
38+
scalelims = -1, 1
39+
40+
inputdir = inputs_quickexample
41+
outputdir = outputs_gridsearch
42+
plotdir = plots
43+
datadir = ../data
44+
preddir = pred
45+
46+
ishape = 1
47+
oshape = 2
48+
49+
ilog = False
50+
olog = False
51+
52+
xvals = None
53+
xlabel = None
54+
ylabel = None
55+
56+
statsaxes = all
57+
58+
fxmean = xmean.npy
59+
fymean = ymean.npy
60+
fxstd = xstd.npy
61+
fystd = ystd.npy
62+
fxmin = xmin.npy
63+
fxmax = xmax.npy
64+
fymin = ymin.npy
65+
fymax = ymax.npy
66+
fsize = datsize.npy
67+
68+
rmse_file = rmse
69+
r2_file = r2
70+
71+
weight_file = nn_weights.keras
72+
73+
# Determines whether to perform a grid search
74+
gridsearch = True
75+
76+
# Below are where the architectures for the grid search are specified.
77+
# Each architecture to be considered in the grid search is on its own line.
78+
# These are just provided for an example, and this is not an exhaustive
79+
# grid search.
80+
81+
# Sets the number of nodes per layer that has nodes. Space-separated values.
82+
nodes = 64 256 16
83+
16 16 16
84+
16 16 16
85+
16 16 16
86+
16 16 16
87+
16 16 16
88+
64 64 64
89+
64 64 64
90+
64 64 64
91+
64 64 64
92+
64 64 64
93+
256 256 256
94+
256 256 256
95+
256 256 256
96+
256 256 256
97+
256 256 256
98+
99+
# Sets the activation function per layer that has nodes. Space separated.
100+
activations = relu elu sig
101+
relu relu relu
102+
elu elu elu
103+
elu elu elu
104+
elu elu elu
105+
sig sig sig
106+
relu relu relu
107+
elu elu elu
108+
elu elu elu
109+
elu elu elu
110+
sig sig sig
111+
relu relu relu
112+
elu elu elu
113+
elu elu elu
114+
elu elu elu
115+
sig sig sig
116+
117+
# Sets the parameter for each activation function
118+
# For activation functions that do not have a parameter, or to use the default,
119+
# use None. Space separated.
120+
act_params = None 0.05585 None
121+
None None None
122+
0.01 0.01 0.01
123+
0.05 0.05 0.05
124+
0.10 0.10 0.10
125+
None None None
126+
None None None
127+
0.01 0.01 0.01
128+
0.05 0.05 0.05
129+
0.10 0.10 0.10
130+
None None None
131+
None None None
132+
0.01 0.01 0.01
133+
0.05 0.05 0.05
134+
0.10 0.10 0.10
135+
None None None
136+
137+
# Sets the type of each hidden layer. Space separated.
138+
layers = dense dense dense
139+
dense dense dense
140+
dense dense dense
141+
dense dense dense
142+
dense dense dense
143+
dense dense dense
144+
dense dense dense
145+
dense dense dense
146+
dense dense dense
147+
dense dense dense
148+
dense dense dense
149+
dense dense dense
150+
dense dense dense
151+
dense dense dense
152+
dense dense dense
153+
dense dense dense
154+
155+
# Sets the parameter for each hidden layer. For layers that do not have free
156+
# parameters, or to use the default, use None. Space separated.
157+
lay_params = None None None
158+
None None None
159+
None None None
160+
None None None
161+
None None None
162+
None None None
163+
None None None
164+
None None None
165+
None None None
166+
None None None
167+
None None None
168+
None None None
169+
None None None
170+
None None None
171+
None None None
172+
None None None
173+
174+
# Set the number of iterations through the data set to consider.
175+
# In a grid search, you usually cannot afford to train until early stopping,
176+
# so select something where it is long enough to get a decent result.
177+
epochs = 60
178+
179+
# Set the early stopping criteria. If there is no improvement after `patience`
180+
# epochs, then terminate training. Here, since it is set higher than the
181+
# number of epochs, early stopping will never engage.
182+
patience = 60
183+
184+
# Set the batch size, or number of data cases to use in each iteration.
185+
batch_size = 256
186+
187+
# Set the minimum and maximum learning rate
188+
lengthscale = 1e-3 # This parameter can also be called `min_lr`
189+
max_lr = 1e-1
190+
191+
# Sets the cyclical learning rate mode and how long each cycle is.
192+
# For more details, see the User Manual.
193+
clr_mode = triangular2
194+
clr_steps = 6
195+
196+
# Determines which test cases to plot. Use integers to specify the index in the
197+
# test set to plot. Space or new-line separated. Use None to not plot any.
198+
# Note that plotting only works for 1D output data.
199+
plot_cases = None
200+
201+
# Determines the window size for a Svitsky-Golay filter in the output plots
202+
# Can be useful for high resolution spectra to better see trends in differences
203+
# between predicted and true spectra.
204+
smoothing = 0

example/quick_example/MARGE_optimization.cfg

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
# For details on these parameters, see the MARGE_rangetest.cfg or MARGE_run.cfg
2+
# files. This file will only detail the Bayesian optimization parameters.
3+
14
[DEFAULT]
25
resume = False
36
seed = 0
4-
verb = 1
7+
verb = 2
58

69
[MARGE]
710
datagenfile = datagen
@@ -15,14 +18,49 @@ trainflag = True
1518
validflag = True
1619
testflag = False
1720

21+
# Number of models to train per GPU during the optimization
1822
optimize = 200
23+
24+
# Number of GPUs to use for the optimization
1925
optngpus = 1
26+
27+
# Minimum and maximum number of layers to consider during the optimization
2028
optnlays = 1 3
29+
30+
# Layer types to use. Specify as many as the maximum for `optnlays`.
31+
# These are used in the order they are specified. So, if a model with 2 layers
32+
# is chosen, then it will use the first 2 layers specified here.
33+
# If you want to do something different, such as changing the first layer but
34+
# keeping the last N layers the same, then you will need to run separate
35+
# optimizations.
2136
optlayer = dense dense dense
37+
38+
# The allowed values for layers with nodes. For each layer with nodes, a
39+
# value from this list will be chosen. Values of 2^n are specified here since
40+
# GPUs are optimized for calculations of that size.
2241
optnnode = 2 4 8 16 32 64 128 256
23-
optmaxconvnode = 256
42+
43+
# The maximum number of nodes (feature maps) for convolutional layers. In this
44+
# example, any conv layer would have at most 128 feature maps. This is enabled
45+
# because model size can balloon quickly if you have a large number of
46+
# feature maps, leading to out-of-memory errors. In general, start with this
47+
# value equal to your maximum of `optnnode`, then reduce it if you hit OOM errors.
48+
optmaxconvnode = 128
49+
50+
# The activations functions to consider during the optimization. Each layer has
51+
# its own activation function selected from this list.
2452
optactiv = relu elu leakyrelu sig tanh
53+
54+
# For activation functions with parameters, this sets the minimum and maximum values
55+
# that can be chosen for it.
2556
optactrng = 0.01 0.6
57+
58+
# If you wish to also optimize the learning rate at the same time, you can
59+
# use these parameters to set the minimum and maximum LR. Note that it can
60+
# be very, very costly to do that, since it will require training a lot more
61+
# models. It is generally recommended to not use this, and instead run multiple
62+
# optimizations for different learning rate policies (specified near the end
63+
# of this file, using lengthscale/min_lr and max_lr).
2664
optminlr = None
2765
optmaxlr = None
2866

@@ -62,12 +100,10 @@ rmse_file = rmse
62100
r2_file = r2
63101
statsaxes = all
64102

65-
weight_file = nn_weights.h5.keras
103+
weight_file = nn_weights.keras
66104

67105
gridsearch = False
68106

69-
architectures = d64e
70-
71107
nodes = 64
72108

73109
activations = elu
@@ -82,7 +118,7 @@ epochs = 60
82118
patience = 60
83119
batch_size = 256
84120

85-
lengthscale = 1e-3
121+
lengthscale = 1e-3 # Can also call this parameter min_lr
86122
max_lr = 1e-1
87123

88124
clr_mode = triangular2

0 commit comments

Comments
 (0)