47
47
# Activation function (options: 'relu', 'tanh', 'sigmoid', 'hard_sigmoid', 'linear')
48
48
ACTIVATION = 'relu'
49
49
LOSS = 'mse'
50
- OPTIMIZER = 'adam'
50
+ OPTIMIZER = 'sgd'
51
+ # OPTIMIZER = 'adam'
51
52
52
53
# Type of feature scaling (options: 'maxabs': to [-1,1]
53
54
# 'minmax': to [0,1]
65
66
DENSE_LAYERS = [D1 , D2 , D3 , D4 ]
66
67
67
68
# Number of units per locally connected layer
68
- LC1 = 10 , 10 # nb_filter, filter_length
69
- LC2 = 0 , 0 # disabled layer
70
- # LOCALLY_CONNECTED_LAYERS = list(LC1 + LC2 )
71
- LOCALLY_CONNECTED_LAYERS = [0 , 0 ]
72
- POOL = 100
69
+ C1 = 10 , 10 , 5 # nb_filter, filter_length, stride
70
+ C2 = 0 , 0 , 0 # disabled layer
71
+ # CONVOLUTION_LAYERS = list(C1 + C2 )
72
+ CONVOLUTION_LAYERS = [0 , 0 , 0 ]
73
+ POOL = 10
73
74
74
75
MIN_LOGCONC = - 5.
75
76
MAX_LOGCONC = - 4.
@@ -91,18 +92,18 @@ def get_parser():
91
92
parser .add_argument ("-b" , "--batch_size" , action = "store" ,
92
93
default = BATCH_SIZE , type = int ,
93
94
help = "batch size" )
94
- parser .add_argument ("-c" , "--convolution" , action = "store_true" ,
95
- default = False ,
96
- help = "use convolution layers instead of locally connected layers " )
95
+ parser .add_argument ("-c" , "--convolution" , action = "store" , nargs = '+' , type = int ,
96
+ default = CONVOLUTION_LAYERS ,
97
+ help = "integer array describing convolution layers: conv1_nb_filter, conv1_filter_len, conv1_stride, conv2_nb_filter, conv2_filter_len, conv2_stride ... " )
97
98
parser .add_argument ("-d" , "--dense" , action = "store" , nargs = '+' , type = int ,
98
99
default = DENSE_LAYERS ,
99
100
help = "number of units in fully connected layers in an integer array" )
100
101
parser .add_argument ("-e" , "--epochs" , action = "store" ,
101
102
default = NB_EPOCH , type = int ,
102
103
help = "number of training epochs" )
103
- parser .add_argument ("-l" , "--locally_connected" , action = "store" , nargs = '+' , type = int ,
104
- default = LOCALLY_CONNECTED_LAYERS ,
105
- help = "integer array describing locally connected layers: layer1_nb_filter, layer1_filter_len, layer2_nb_filter, layer2_filter_len, ... " )
104
+ parser .add_argument ("-l" , "--locally_connected" , action = "store_true" ,
105
+ default = False ,
106
+ help = "use locally connected layers instead of convolution layers " )
106
107
parser .add_argument ("-o" , "--optimizer" , action = "store" ,
107
108
default = OPTIMIZER ,
108
109
help = "keras optimizer to use: sgd, rmsprop, ..." )
@@ -163,15 +164,16 @@ def extension_from_parameters(args):
163
164
ext += '.E={}' .format (args .epochs )
164
165
if args .feature_subsample :
165
166
ext += '.F={}' .format (args .feature_subsample )
166
- if args .locally_connected :
167
- name = 'C ' if args .convolution else 'LC '
168
- layer_list = list (range (0 , len (args .locally_connected ), 2 ))
167
+ if args .convolution :
168
+ name = 'LC ' if args .locally_connected else 'C '
169
+ layer_list = list (range (0 , len (args .convolution ), 3 ))
169
170
for l , i in enumerate (layer_list ):
170
- nb_filter = args .locally_connected [i ]
171
- filter_len = args .locally_connected [i + 1 ]
172
- if nb_filter <= 0 or filter_len <= 0 :
171
+ nb_filter = args .convolution [i ]
172
+ filter_len = args .convolution [i + 1 ]
173
+ stride = args .convolution [i + 2 ]
174
+ if nb_filter <= 0 or filter_len <= 0 or stride <= 0 :
173
175
break
174
- ext += '.{}{}={},{}' .format (name , l + 1 , nb_filter , filter_len )
176
+ ext += '.{}{}={},{},{} ' .format (name , l + 1 , nb_filter , filter_len , stride )
175
177
if args .pool and layer_list [0 ] and layer_list [1 ]:
176
178
ext += '.P={}' .format (args .pool )
177
179
for i , n in enumerate (args .dense ):
@@ -308,53 +310,54 @@ def main():
308
310
309
311
ext = extension_from_parameters (args )
310
312
311
- datagen = p1b3 .RegressionDataGenerator (feature_subsample = args .feature_subsample ,
312
- scaling = args .scaling ,
313
- drug_features = args .drug_features ,
314
- scramble = args .scramble ,
315
- min_logconc = args .min_logconc ,
316
- max_logconc = args .max_logconc ,
317
- subsample = args .subsample ,
318
- category_cutoffs = args .category_cutoffs )
313
+ loader = p1b3 .DataLoader (feature_subsample = args .feature_subsample ,
314
+ scaling = args .scaling ,
315
+ drug_features = args .drug_features ,
316
+ scramble = args .scramble ,
317
+ min_logconc = args .min_logconc ,
318
+ max_logconc = args .max_logconc ,
319
+ subsample = args .subsample ,
320
+ category_cutoffs = args .category_cutoffs )
319
321
320
- topology = 'dense'
322
+ gen_shape = None
321
323
out_dim = 1
322
324
323
325
model = Sequential ()
324
- if args .locally_connected and args .locally_connected [0 ]:
325
- topology = 'simple_local '
326
- layer_list = list (range (0 , len (args .locally_connected ), 2 ))
326
+ if args .convolution and args .convolution [0 ]:
327
+ gen_shape = 'add_1d '
328
+ layer_list = list (range (0 , len (args .convolution ), 3 ))
327
329
for l , i in enumerate (layer_list ):
328
- nb_filter = args .locally_connected [i ]
329
- filter_len = args .locally_connected [i + 1 ]
330
- if nb_filter <= 0 or filter_len <= 0 :
330
+ nb_filter = args .convolution [i ]
331
+ filter_len = args .convolution [i + 1 ]
332
+ stride = args .convolution [i + 2 ]
333
+ if nb_filter <= 0 or filter_len <= 0 or stride <= 0 :
331
334
break
332
- if args .convolution :
333
- model .add (Convolution1D (nb_filter , filter_len , input_shape = (datagen .input_dim , 1 ), activation = args .activation ))
335
+ if args .locally_connected :
336
+ model .add (LocallyConnected1D (nb_filter , filter_len , subsample_length = stride , input_shape = (loader .input_dim , 1 ), activation = args .activation ))
334
337
else :
335
- model .add (LocallyConnected1D (nb_filter , filter_len , input_shape = (datagen .input_dim , 1 ), activation = args .activation ))
338
+ model .add (Convolution1D (nb_filter , filter_len , subsample_length = stride , input_shape = (loader .input_dim , 1 ), activation = args .activation ))
336
339
if args .pool :
337
340
model .add (MaxPooling1D (pool_length = args .pool ))
338
341
model .add (Flatten ())
339
342
340
343
for layer in args .dense :
341
344
if layer :
342
- model .add (Dense (layer , input_dim = datagen .input_dim , activation = args .activation ))
345
+ model .add (Dense (layer , input_dim = loader .input_dim , activation = args .activation ))
343
346
if args .drop :
344
347
model .add (Dropout (args .drop ))
345
348
model .add (Dense (out_dim ))
346
349
347
350
model .summary ()
348
351
model .compile (loss = args .loss , optimizer = args .optimizer )
349
352
350
- train_gen = datagen . flow ( batch_size = args .batch_size , topology = topology )
351
- val_gen = datagen . flow ( data = 'val' , batch_size = args .batch_size , topology = topology )
352
- val_gen2 = datagen . flow ( data = 'val' , batch_size = args .batch_size , topology = topology )
353
- test_gen = datagen . flow ( data = 'test' , batch_size = args .batch_size , topology = topology )
353
+ train_gen = p1b3 . DataGenerator ( loader , batch_size = args .batch_size , shape = gen_shape ). flow ( )
354
+ val_gen = p1b3 . DataGenerator ( loader , partition = 'val' , batch_size = args .batch_size , shape = gen_shape ). flow ( )
355
+ val_gen2 = p1b3 . DataGenerator ( loader , partition = 'val' , batch_size = args .batch_size , shape = gen_shape ). flow ( )
356
+ test_gen = p1b3 . DataGenerator ( loader , partition = 'test' , batch_size = args .batch_size , shape = gen_shape ). flow ( )
354
357
355
- train_samples = int (datagen .n_train / args .batch_size ) * args .batch_size
356
- val_samples = int (datagen .n_val / args .batch_size ) * args .batch_size
357
- test_samples = int (datagen .n_test / args .batch_size ) * args .batch_size
358
+ train_samples = int (loader .n_train / args .batch_size ) * args .batch_size
359
+ val_samples = int (loader .n_val / args .batch_size ) * args .batch_size
360
+ test_samples = int (loader .n_test / args .batch_size ) * args .batch_size
358
361
359
362
train_samples = args .train_samples if args .train_samples else train_samples
360
363
val_samples = args .val_samples if args .val_samples else val_samples
0 commit comments