# Path: mimic3models/keras_utils.py
# class DecompensationMetrics(keras.callbacks.Callback):
# class InHospitalMortalityMetrics(keras.callbacks.Callback):
# class PhenotypingMetrics(keras.callbacks.Callback):
# class LengthOfStayMetrics(keras.callbacks.Callback):
# class MultitaskMetrics(keras.callbacks.Callback):
# class CollectAttetion(Layer):
# class Slice(Layer):
# class GetTimestep(Layer):
# class ExtendMask(Layer):
#     def __init__(self, train_data_gen, val_data_gen, deep_supervision,
#                  batch_size=32, early_stopping=True, verbose=2):
#     def calc_metrics(self, data_gen, history, dataset, logs):
#     def on_epoch_end(self, epoch, logs={}):
#     def __init__(self, train_data, val_data, target_repl, batch_size=32, early_stopping=True, verbose=2):
#     def calc_metrics(self, data, history, dataset, logs):
#     def on_epoch_end(self, epoch, logs={}):
#     def __init__(self, train_data_gen, val_data_gen, batch_size=32,
#                  early_stopping=True, verbose=2):
#     def calc_metrics(self, data_gen, history, dataset, logs):
#     def on_epoch_end(self, epoch, logs={}):
#     def __init__(self, train_data_gen, val_data_gen, partition, batch_size=32,
#                  early_stopping=True, verbose=2):
#     def calc_metrics(self, data_gen, history, dataset, logs):
#     def on_epoch_end(self, epoch, logs={}):
#     def __init__(self, train_data_gen, val_data_gen, partition,
#                  batch_size=32, early_stopping=True, verbose=2):
#     def calc_metrics(self, data_gen, history, dataset, logs):
#     def on_epoch_end(self, epoch, logs={}):
# def softmax(x, axis, mask=None):
# def _collect_attention(x, a, mask):
#     def __init__(self, **kwargs):
#     def call(self, inputs, mask=None):
#     def compute_output_shape(self, input_shape):
#     def compute_mask(self, input, input_mask=None):
#     def __init__(self, indices, **kwargs):
#     def call(self, x, mask=None):
#     def compute_output_shape(self, input_shape):
#     def compute_mask(self, input, input_mask=None):
#     def get_config(self):
#     def __init__(self, pos=-1, **kwargs):
#     def call(self, x, mask=None):
#     def compute_output_shape(self, input_shape):
#     def compute_mask(self, input, input_mask=None):
#     def get_config(self):
#     def __init__(self, add_epsilon=False, **kwargs):
#     def call(self, x, mask=None):
#     def compute_output_shape(self, input_shape):
#     def compute_mask(self, input, input_mask=None):
#     def get_config(self):
#         B = self.batch_size
# 
# Path: mimic3models/keras_utils.py
# class ExtendMask(Layer):
#     """ Inputs:      [X, M]
#         Output:      X
#         Output_mask: M
#     """
# 
#     def __init__(self, add_epsilon=False, **kwargs):
#         self.supports_masking = True
#         self.add_epsilon = add_epsilon
#         super(ExtendMask, self).__init__(**kwargs)
# 
#     def call(self, x, mask=None):
#         return x[0]
# 
#     def compute_output_shape(self, input_shape):
#         return input_shape[0]
# 
#     def compute_mask(self, input, input_mask=None):
#         if self.add_epsilon:
#             return input[1] + K.epsilon()
#         return input[1]
# 
#     def get_config(self):
#         return {'add_epsilon': self.add_epsilon}


from keras.models import Model
from keras.layers import Input, Dense, LSTM, Masking, Dropout
from keras.layers.wrappers import Bidirectional, TimeDistributed
from mimic3models.keras_utils import LastTimestep
from mimic3models.keras_utils import ExtendMask
        for i in range(depth - 1):
            num_units = dim
            if is_bidirectional:
                num_units = num_units // 2

            lstm = LSTM(units=num_units,
                        activation='tanh',
                        return_sequences=True,
                        recurrent_dropout=rec_dropout,
                        dropout=dropout)

            if is_bidirectional:
                mX = Bidirectional(lstm)(mX)
            else:
                mX = lstm(mX)

        # Output module of the network
        return_sequences = (target_repl or deep_supervision)
        L = LSTM(units=dim,
                 activation='tanh',
                 return_sequences=return_sequences,
                 dropout=dropout,
                 recurrent_dropout=rec_dropout)(mX)

        if dropout > 0:
            L = Dropout(dropout)(L)

        if target_repl:
            y = TimeDistributed(Dense(num_classes, activation=final_activation),
                                name='seq')(L)

# Path: mimic3models/keras_utils.py
# class DecompensationMetrics(keras.callbacks.Callback):
# class InHospitalMortalityMetrics(keras.callbacks.Callback):
# class PhenotypingMetrics(keras.callbacks.Callback):
# class LengthOfStayMetrics(keras.callbacks.Callback):
# class MultitaskMetrics(keras.callbacks.Callback):
# class CollectAttetion(Layer):
# class Slice(Layer):
# class GetTimestep(Layer):
# class ExtendMask(Layer):
#     def __init__(self, train_data_gen, val_data_gen, deep_supervision,
#                  batch_size=32, early_stopping=True, verbose=2):
#     def calc_metrics(self, data_gen, history, dataset, logs):
#     def on_epoch_end(self, epoch, logs={}):
#     def __init__(self, train_data, val_data, target_repl, batch_size=32, early_stopping=True, verbose=2):
#     def calc_metrics(self, data, history, dataset, logs):
#     def on_epoch_end(self, epoch, logs={}):
#     def __init__(self, train_data_gen, val_data_gen, batch_size=32,
#                  early_stopping=True, verbose=2):
#     def calc_metrics(self, data_gen, history, dataset, logs):
#     def on_epoch_end(self, epoch, logs={}):
#     def __init__(self, train_data_gen, val_data_gen, partition, batch_size=32,
#                  early_stopping=True, verbose=2):
#     def calc_metrics(self, data_gen, history, dataset, logs):
#     def on_epoch_end(self, epoch, logs={}):
#     def __init__(self, train_data_gen, val_data_gen, partition,
#                  batch_size=32, early_stopping=True, verbose=2):
#     def calc_metrics(self, data_gen, history, dataset, logs):
#     def on_epoch_end(self, epoch, logs={}):
# def softmax(x, axis, mask=None):
# def _collect_attention(x, a, mask):
#     def __init__(self, **kwargs):
#     def call(self, inputs, mask=None):
#     def compute_output_shape(self, input_shape):
#     def compute_mask(self, input, input_mask=None):
#     def __init__(self, indices, **kwargs):
#     def call(self, x, mask=None):
#     def compute_output_shape(self, input_shape):
#     def compute_mask(self, input, input_mask=None):
#     def get_config(self):
#     def __init__(self, pos=-1, **kwargs):
#     def call(self, x, mask=None):
#     def compute_output_shape(self, input_shape):
#     def compute_mask(self, input, input_mask=None):
#     def get_config(self):
#     def __init__(self, add_epsilon=False, **kwargs):
#     def call(self, x, mask=None):
#     def compute_output_shape(self, input_shape):
#     def compute_mask(self, input, input_mask=None):
#     def get_config(self):
#         B = self.batch_size
# 
# Path: mimic3models/keras_utils.py
# class ExtendMask(Layer):
#     """ Inputs:      [X, M]
#         Output:      X
#         Output_mask: M
#     """
# 
#     def __init__(self, add_epsilon=False, **kwargs):
#         self.supports_masking = True
#         self.add_epsilon = add_epsilon
#         super(ExtendMask, self).__init__(**kwargs)
# 
#     def call(self, x, mask=None):
#         return x[0]
# 
#     def compute_output_shape(self, input_shape):
#         return input_shape[0]
# 
#     def compute_mask(self, input, input_mask=None):
#         if self.add_epsilon:
#             return input[1] + K.epsilon()
#         return input[1]
# 
#     def get_config(self):
#         return {'add_epsilon': self.add_epsilon}


# Path: mimic3models/keras_models/lstm.py
from keras.models import Model
from keras.layers import Input, Dense, LSTM, Masking, Dropout
from keras.layers.wrappers import Bidirectional, TimeDistributed
from mimic3models.keras_utils import LastTimestep
from mimic3models.keras_utils import ExtendMask

        for i in range(depth - 1):
            num_units = dim
            if is_bidirectional:
                num_units = num_units // 2

            lstm = LSTM(units=num_units,
                        activation='tanh',
                        return_sequences=True,
                        recurrent_dropout=rec_dropout,
                        dropout=dropout)

            if is_bidirectional:
                mX = Bidirectional(lstm)(mX)
            else:
                mX = lstm(mX)

        # Output module of the network
        return_sequences = (target_repl or deep_supervision)
        L = LSTM(units=dim,
                 activation='tanh',
                 return_sequences=return_sequences,
                 dropout=dropout,
                 recurrent_dropout=rec_dropout)(mX)

        if dropout > 0:
            L = Dropout(dropout)(L)

        if target_repl:
            y = TimeDistributed(Dense(num_classes, activation=final_activation),
                                name='seq')(L)

            y_last = LastTimestep(name='single')(y)