`R/create_model.R`

`create_model_lstm_cnn_target_middle.Rd`

Creates a network consisting of an arbitrary number of CNN, LSTM and dense layers. Function creates two sub networks consisting each of (optional) CNN layers followed by an arbitrary number of LSTM layers. Afterwards the last LSTM layers get concatenated and followed by one or more dense layers. Last layer is a dense layer. Network tries to predict target in the middle of a sequence. If input is AACCTAAGG, input tensors should correspond to x1 = AACC, x2 = GGAA and y = T.

```
create_model_lstm_cnn_target_middle(
maxlen = 50,
dropout_lstm = 0,
recurrent_dropout_lstm = 0,
layer_lstm = 128,
solver = "adam",
learning_rate = 0.001,
vocabulary_size = 4,
bidirectional = FALSE,
stateful = FALSE,
batch_size = NULL,
padding = "same",
compile = TRUE,
layer_dense = NULL,
kernel_size = NULL,
filters = NULL,
pool_size = NULL,
strides = NULL,
label_input = NULL,
zero_mask = FALSE,
label_smoothing = 0,
label_noise_matrix = NULL,
last_layer_activation = "softmax",
loss_fn = "categorical_crossentropy",
num_output_layers = 1,
f1_metric = FALSE,
verbose = TRUE,
batch_norm_momentum = 0.99,
model_seed = NULL
)
```

- maxlen
Length of predictor sequence.

- dropout_lstm
Fraction of the units to drop for inputs.

- recurrent_dropout_lstm
Fraction of the units to drop for recurrent state.

- layer_lstm
Number of cells per network layer. Can be a scalar or vector.

- solver
Optimization method, options are

`"adam", "adagrad", "rmsprop"`

or`"sgd"`

.- learning_rate
Learning rate for optimizer.

- vocabulary_size
Number of unique character in vocabulary.

- bidirectional
Use bidirectional wrapper for lstm layers.

- stateful
Boolean. Whether to use stateful LSTM layer.

- batch_size
Number of samples that are used for one network update. Only used if

`stateful = TRUE`

.- padding
Padding of CNN layers, e.g.

`"same", "valid"`

or`"causal"`

.- compile
Whether to compile the model.

- layer_dense
Vector specifying number of neurons per dense layer after last LSTM or CNN layer (if no LSTM used).

- kernel_size
Size of 1d convolutional layers. For multiple layers, assign a vector. (e.g,

`rep(3,2)`

for two layers and kernel size 3)- filters
Number of filters. For multiple layers, assign a vector.

- pool_size
Integer, size of the max pooling windows. For multiple layers, assign a vector.

- strides
Stride values. For multiple layers, assign a vector.

- label_input
Integer or

`NULL`

. If not`NULL`

, adds additional input layer of`label_input`

size.- zero_mask
Boolean, whether to apply zero masking before LSTM layer. Only used if model does not use any CNN layers.

- label_smoothing
Float in [0, 1]. If 0, no smoothing is applied. If > 0, loss between the predicted labels and a smoothed version of the true labels, where the smoothing squeezes the labels towards 0.5. The closer the argument is to 1 the more the labels get smoothed.

- label_noise_matrix
Matrix of label noises. Every row stands for one class and columns for percentage of labels in that class. If first label contains 5 percent wrong labels and second label no noise, then

`label_noise_matrix <- matrix(c(0.95, 0.05, 0, 1), nrow = 2, byrow = TRUE )`

- last_layer_activation
Either

`"sigmoid"`

or`"softmax"`

.- loss_fn
Either

`"categorical_crossentropy"`

or`"binary_crossentropy"`

. If`label_noise_matrix`

given, will use custom`"noisy_loss"`

.- num_output_layers
Number of output layers.

- f1_metric
Whether to add F1 metric.

- verbose
Boolean.

- batch_norm_momentum
Momentum for the moving mean and the moving variance.

- model_seed
Set seed for model parameters in tensorflow if not

`NULL`

.

```
create_model_lstm_cnn_target_middle(
maxlen = 500,
vocabulary_size = 4,
kernel_size = c(8, 8, 8),
filters = c(16, 32, 64),
pool_size = c(3, 3, 3),
layer_lstm = c(32, 64),
layer_dense = c(128, 4),
learning_rate = 0.001)
#> Model: "model_4"
#> ________________________________________________________________________________
#> Layer (type) Output Shape Param # Connected to Trainable
#> ================================================================================
#> input_4 (InputLayer) [(None, 250, 0 [] Y
#> 4)]
#> input_5 (InputLayer) [(None, 250, 0 [] Y
#> 4)]
#> conv1d_5 (Conv1D) (None, 250, 1 528 ['input_4[0][0]'] Y
#> 6)
#> conv1d_8 (Conv1D) (None, 250, 1 528 ['input_5[0][0]'] Y
#> 6)
#> max_pooling1d_5 (Max (None, 83, 16 0 ['conv1d_5[0][0]'] Y
#> Pooling1D) )
#> max_pooling1d_8 (Max (None, 83, 16 0 ['conv1d_8[0][0]'] Y
#> Pooling1D) )
#> batch_normalization_ (None, 83, 16 64 ['max_pooling1d_5[0][ Y
#> 5 (BatchNormalizatio ) 0]']
#> n)
#> batch_normalization_ (None, 83, 16 64 ['max_pooling1d_8[0][ Y
#> 8 (BatchNormalizatio ) 0]']
#> n)
#> conv1d_6 (Conv1D) (None, 83, 32 4128 ['batch_normalization Y
#> ) _5[0][0]']
#> conv1d_9 (Conv1D) (None, 83, 32 4128 ['batch_normalization Y
#> ) _8[0][0]']
#> max_pooling1d_6 (Max (None, 27, 32 0 ['conv1d_6[0][0]'] Y
#> Pooling1D) )
#> max_pooling1d_9 (Max (None, 27, 32 0 ['conv1d_9[0][0]'] Y
#> Pooling1D) )
#> batch_normalization_ (None, 27, 32 128 ['max_pooling1d_6[0][ Y
#> 6 (BatchNormalizatio ) 0]']
#> n)
#> batch_normalization_ (None, 27, 32 128 ['max_pooling1d_9[0][ Y
#> 9 (BatchNormalizatio ) 0]']
#> n)
#> conv1d_7 (Conv1D) (None, 27, 64 16448 ['batch_normalization Y
#> ) _6[0][0]']
#> conv1d_10 (Conv1D) (None, 27, 64 16448 ['batch_normalization Y
#> ) _9[0][0]']
#> max_pooling1d_7 (Max (None, 9, 64) 0 ['conv1d_7[0][0]'] Y
#> Pooling1D)
#> max_pooling1d_10 (Ma (None, 9, 64) 0 ['conv1d_10[0][0]'] Y
#> xPooling1D)
#> batch_normalization_ (None, 9, 64) 256 ['max_pooling1d_7[0][ Y
#> 7 (BatchNormalizatio 0]']
#> n)
#> batch_normalization_ (None, 9, 64) 256 ['max_pooling1d_10[0] Y
#> 10 (BatchNormalizati [0]']
#> on)
#> lstm_4 (LSTM) (None, 9, 32) 12416 ['batch_normalization Y
#> _7[0][0]']
#> lstm_6 (LSTM) (None, 9, 32) 12416 ['batch_normalization Y
#> _10[0][0]']
#> lstm_5 (LSTM) (None, 64) 24832 ['lstm_4[0][0]'] Y
#> lstm_7 (LSTM) (None, 64) 24832 ['lstm_6[0][0]'] Y
#> concatenate (Concate (None, 128) 0 ['lstm_5[0][0]', Y
#> nate) 'lstm_7[0][0]']
#> dense_6 (Dense) (None, 128) 16512 ['concatenate[0][0]'] Y
#> dense_7 (Dense) (None, 4) 516 ['dense_6[0][0]'] Y
#> ================================================================================
#> Total params: 134,628
#> Trainable params: 134,180
#> Non-trainable params: 448
#> ________________________________________________________________________________
```