# 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/common_utils.py
# def convert_to_dict(data, header, channel_info):
# def extract_features_from_rawdata(chunk, header, period, features):
# def read_chunk(reader, chunk_size):
# def sort_and_shuffle(data, batch_size):
# def add_common_arguments(parser):
#     def __init__(self, dataset_dir, listfile=None, small_part=False):
#     def _read_timeseries(self, ts_filename):
# def create_directory(directory):
# def pad_zeros(arr, min_length=None):
# class DeepSupervisionDataLoader:


from mimic3models import metrics
from mimic3models import common_utils
import threading
import os
import numpy as np
import random
        self.lock = threading.Lock()
        self.generator = self._generator()

    def _generator(self):
        B = self.batch_size
        while True:
            if self.shuffle:
                self.reader.random_shuffle()
            remaining = self.n_examples
            while remaining > 0:
                current_size = min(self.chunk_size, remaining)
                remaining -= current_size

                ret = common_utils.read_chunk(self.reader, current_size)
                Xs = ret["X"]
                ts = ret["t"]
                ys = ret["y"]
                names = ret["name"]

                Xs = preprocess_chunk(Xs, ts, self.discretizer, self.normalizer)
                (Xs, ys, ts, names) = common_utils.sort_and_shuffle([Xs, ys, ts, names], B)

                for i in range(0, current_size, B):
                    X = common_utils.pad_zeros(Xs[i:i + B])
                    y = ys[i:i+B]
                    y_true = np.array(y)
                    batch_names = names[i:i+B]
                    batch_ts = ts[i:i+B]

                    if self.partition == 'log':

# 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/common_utils.py
# def convert_to_dict(data, header, channel_info):
# def extract_features_from_rawdata(chunk, header, period, features):
# def read_chunk(reader, chunk_size):
# def sort_and_shuffle(data, batch_size):
# def add_common_arguments(parser):
#     def __init__(self, dataset_dir, listfile=None, small_part=False):
#     def _read_timeseries(self, ts_filename):
# def create_directory(directory):
# def pad_zeros(arr, min_length=None):
# class DeepSupervisionDataLoader:


# Path: mimic3models/length_of_stay/utils.py
from mimic3models import metrics
from mimic3models import common_utils
import threading
import os
import numpy as np
import random

        self.lock = threading.Lock()
        self.generator = self._generator()

    def _generator(self):
        B = self.batch_size
        while True:
            if self.shuffle:
                self.reader.random_shuffle()
            remaining = self.n_examples
            while remaining > 0:
                current_size = min(self.chunk_size, remaining)
                remaining -= current_size

                ret = common_utils.read_chunk(self.reader, current_size)
                Xs = ret["X"]
                ts = ret["t"]
                ys = ret["y"]
                names = ret["name"]

                Xs = preprocess_chunk(Xs, ts, self.discretizer, self.normalizer)
                (Xs, ys, ts, names) = common_utils.sort_and_shuffle([Xs, ys, ts, names], B)

                for i in range(0, current_size, B):
                    X = common_utils.pad_zeros(Xs[i:i + B])
                    y = ys[i:i+B]
                    y_true = np.array(y)
                    batch_names = names[i:i+B]
                    batch_ts = ts[i:i+B]

                    if self.partition == 'log':

                        y = [metrics.get_bin_log(x, 10) for x in y]