# Path: mimic3models/metrics.py
# def print_metrics_binary(y_true, predictions, verbose=1):
# def print_metrics_multilabel(y_true, predictions, verbose=1):
# def mean_absolute_percentage_error(y_true, y_pred):
# def print_metrics_regression(y_true, predictions, verbose=1):
# def get_bin_log(x, nbins, one_hot=False):
# def get_estimate_log(prediction, nbins):
# def print_metrics_log_bins(y_true, predictions, verbose=1):
# def get_bin_custom(x, nbins, one_hot=False):
# def get_estimate_custom(prediction, nbins):
# def print_metrics_custom_bins(y_true, predictions, verbose=1):
# class LogBins:
# class CustomBins:


import numpy as np
import keras
import keras.backend as K
    import tensorflow as tf
from mimic3models import metrics
from keras.layers import Layer
                 batch_size=32, early_stopping=True, verbose=2):
        super(DecompensationMetrics, self).__init__()
        self.train_data_gen = train_data_gen
        self.val_data_gen = val_data_gen
        self.deep_supervision = deep_supervision
        self.batch_size = batch_size
        self.early_stopping = early_stopping
        self.verbose = verbose
        self.train_history = []
        self.val_history = []

    def calc_metrics(self, data_gen, history, dataset, logs):
        y_true = []
        predictions = []
        for i in range(data_gen.steps):
            if self.verbose == 1:
                print("\tdone {}/{}".format(i, data_gen.steps), end='\r')
            (x, y) = next(data_gen)
            pred = self.model.predict(x, batch_size=self.batch_size)
            if self.deep_supervision:
                for m, t, p in zip(x[1].flatten(), y.flatten(), pred.flatten()):
                    if np.equal(m, 1):
                        y_true.append(t)
                        predictions.append(p)
            else:
                y_true += list(y.flatten())
                predictions += list(pred.flatten())
        print('\n')
        predictions = np.array(predictions)
        predictions = np.stack([1 - predictions, predictions], axis=1)

# Path: mimic3models/metrics.py
# def print_metrics_binary(y_true, predictions, verbose=1):
# def print_metrics_multilabel(y_true, predictions, verbose=1):
# def mean_absolute_percentage_error(y_true, y_pred):
# def print_metrics_regression(y_true, predictions, verbose=1):
# def get_bin_log(x, nbins, one_hot=False):
# def get_estimate_log(prediction, nbins):
# def print_metrics_log_bins(y_true, predictions, verbose=1):
# def get_bin_custom(x, nbins, one_hot=False):
# def get_estimate_custom(prediction, nbins):
# def print_metrics_custom_bins(y_true, predictions, verbose=1):
# class LogBins:
# class CustomBins:


# Path: mimic3models/keras_utils.py
import numpy as np
import keras
import keras.backend as K
    import tensorflow as tf
from mimic3models import metrics
from keras.layers import Layer

                 batch_size=32, early_stopping=True, verbose=2):
        super(DecompensationMetrics, self).__init__()
        self.train_data_gen = train_data_gen
        self.val_data_gen = val_data_gen
        self.deep_supervision = deep_supervision
        self.batch_size = batch_size
        self.early_stopping = early_stopping
        self.verbose = verbose
        self.train_history = []
        self.val_history = []

    def calc_metrics(self, data_gen, history, dataset, logs):
        y_true = []
        predictions = []
        for i in range(data_gen.steps):
            if self.verbose == 1:
                print("\tdone {}/{}".format(i, data_gen.steps), end='\r')
            (x, y) = next(data_gen)
            pred = self.model.predict(x, batch_size=self.batch_size)
            if self.deep_supervision:
                for m, t, p in zip(x[1].flatten(), y.flatten(), pred.flatten()):
                    if np.equal(m, 1):
                        y_true.append(t)
                        predictions.append(p)
            else:
                y_true += list(y.flatten())
                predictions += list(pred.flatten())
        print('\n')
        predictions = np.array(predictions)
        predictions = np.stack([1 - predictions, predictions], axis=1)

        ret = metrics.print_metrics_binary(y_true, predictions)