# Path: sop_embed/tools.py
# def split_data_to_minibatchs_eval(data, batch_size, sharpe=False):
#     """Split a dataset to minibatchs to:
#         1. Control the case where the size of the set is not divided by the
#             btahc_size.
#         2. Allows to share batch by batch when the size of data is too big to
#             fit in the GPU shared memory.
# 
#     data: dictionnary with two keys:
#         x: x (numpy.ndarray) for the supervised data
#             may contains rows with only numpy.nan as values.
#         y: y (numpy.ndarray) for the superrvised data
#             may contains rows with only numpy.nan as values.
#     batch_size: the size of the batch
# 
#     Returns:
#         list_minibatchs: list
#             a list of dic of mini-batchs, each one has the 2 keys: "x", "y".
#     """
#     nbr_samples = data['x'].shape[0]
#     if batch_size > nbr_samples:
#         batch_size = nbr_samples
# 
#     nbr_batchs = int(nbr_samples / batch_size)
#     list_minibatchs = []
#     for index in xrange(nbr_batchs):
#         x_train = data['x'][index * batch_size:(index+1) * batch_size]
#         y_train = data['y'][index * batch_size:(index+1) * batch_size]
#         list_minibatchs.append({'x': x_train.astype(theano.config.floatX),
#                                 'y': y_train.astype(theano.config.floatX)})
#     if not sharpe:
#         # in case some samples are left
#         if (nbr_batchs * batch_size) < nbr_samples:
#             x_train = data['x'][(index+1) * batch_size:]
#             y_train = data['y'][(index+1) * batch_size:]
#             list_minibatchs.append({'x': x_train.astype(theano.config.floatX),
#                                     'y': y_train.astype(theano.config.floatX)})
# 
#     return list_minibatchs
# 
# Path: sop_embed/tools.py
# def split_data_to_minibatchs_embed(data, batch_size, share=False, borrow=True,
#                                    sharpe=False):
#     """Split a dataset to minibatchs to:
#         1. Control the case where the size of the set is not divided by the
#             btahc_size.
#         2. Allows to share batch by batch when the size of data is too big to
#             fit in the GPU shared memory.
# 
#     data: dictionnary with two keys:
#         x: x (numpy.ndarray) for the supervised data
#             may contains rows with only numpy.nan as values.
#         y: y (numpy.ndarray) for the superrvised data
#             may contains rows with only numpy.nan as values.
#     batch_size: the size of the batch
#     sharpe: Boolean. If True, ignore the rest of data with size less than
#         batch size.
# 
#     Returns:
#         list_minibatchs: list
#             a list of dic of mini-batchs, each one has the 3 keys: "in",
#             "out", "sup".
#     """
#     nbr_samples = data['x'].shape[0]
#     if batch_size > nbr_samples:
#         batch_size = nbr_samples
# 
#     nbr_batchs = int(nbr_samples / batch_size)
#     list_minibatchs = []
#     for index in xrange(nbr_batchs):
#         x_train = data['x'][index * batch_size:(index+1) * batch_size]
#         y_train = data['y'][index * batch_size:(index+1) * batch_size]
#         c_batch_in, c_batch_out, c_batch_sup = split_mini_batch(
#             x_train.astype(theano.config.floatX),
#             y_train.astype(theano.config.floatX), share=share, borrow=borrow)
# 
#         list_minibatchs.append(
#             {'in': c_batch_in, 'out': c_batch_out, 'sup': c_batch_sup})
#     if not sharpe:
#         # in case some samples are left
#         if (nbr_batchs * batch_size) < nbr_samples:
#             x_train = data['x'][(index+1) * batch_size:]
#             y_train = data['y'][(index+1) * batch_size:]
#             c_batch_in, c_batch_out, c_batch_sup = split_mini_batch(
#                 x_train.astype(theano.config.floatX),
#                 y_train.astype(theano.config.floatX), share=share,
#                 borrow=borrow)
#             list_minibatchs.append(
#                 {'in': c_batch_in, 'out': c_batch_out, 'sup': c_batch_sup})
# 
#     return list_minibatchs


from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras import backend as K
from keras.optimizers import SGD
from sop_embed.tools import split_data_to_minibatchs_eval
from sop_embed.tools import split_data_to_minibatchs_embed
import keras
import theano.tensor as T
import datetime as DT
import os
import sys
import cPickle as pkl
import numpy as np




def baseline_model():
    # create model
    input_shape = (1, 50, 50)
    model = Sequential()
    model.add(Conv2D(16, (3, 3),

# Path: sop_embed/tools.py
# def split_data_to_minibatchs_eval(data, batch_size, sharpe=False):
#     """Split a dataset to minibatchs to:
#         1. Control the case where the size of the set is not divided by the
#             btahc_size.
#         2. Allows to share batch by batch when the size of data is too big to
#             fit in the GPU shared memory.
# 
#     data: dictionnary with two keys:
#         x: x (numpy.ndarray) for the supervised data
#             may contains rows with only numpy.nan as values.
#         y: y (numpy.ndarray) for the superrvised data
#             may contains rows with only numpy.nan as values.
#     batch_size: the size of the batch
# 
#     Returns:
#         list_minibatchs: list
#             a list of dic of mini-batchs, each one has the 2 keys: "x", "y".
#     """
#     nbr_samples = data['x'].shape[0]
#     if batch_size > nbr_samples:
#         batch_size = nbr_samples
# 
#     nbr_batchs = int(nbr_samples / batch_size)
#     list_minibatchs = []
#     for index in xrange(nbr_batchs):
#         x_train = data['x'][index * batch_size:(index+1) * batch_size]
#         y_train = data['y'][index * batch_size:(index+1) * batch_size]
#         list_minibatchs.append({'x': x_train.astype(theano.config.floatX),
#                                 'y': y_train.astype(theano.config.floatX)})
#     if not sharpe:
#         # in case some samples are left
#         if (nbr_batchs * batch_size) < nbr_samples:
#             x_train = data['x'][(index+1) * batch_size:]
#             y_train = data['y'][(index+1) * batch_size:]
#             list_minibatchs.append({'x': x_train.astype(theano.config.floatX),
#                                     'y': y_train.astype(theano.config.floatX)})
# 
#     return list_minibatchs
# 
# Path: sop_embed/tools.py
# def split_data_to_minibatchs_embed(data, batch_size, share=False, borrow=True,
#                                    sharpe=False):
#     """Split a dataset to minibatchs to:
#         1. Control the case where the size of the set is not divided by the
#             btahc_size.
#         2. Allows to share batch by batch when the size of data is too big to
#             fit in the GPU shared memory.
# 
#     data: dictionnary with two keys:
#         x: x (numpy.ndarray) for the supervised data
#             may contains rows with only numpy.nan as values.
#         y: y (numpy.ndarray) for the superrvised data
#             may contains rows with only numpy.nan as values.
#     batch_size: the size of the batch
#     sharpe: Boolean. If True, ignore the rest of data with size less than
#         batch size.
# 
#     Returns:
#         list_minibatchs: list
#             a list of dic of mini-batchs, each one has the 3 keys: "in",
#             "out", "sup".
#     """
#     nbr_samples = data['x'].shape[0]
#     if batch_size > nbr_samples:
#         batch_size = nbr_samples
# 
#     nbr_batchs = int(nbr_samples / batch_size)
#     list_minibatchs = []
#     for index in xrange(nbr_batchs):
#         x_train = data['x'][index * batch_size:(index+1) * batch_size]
#         y_train = data['y'][index * batch_size:(index+1) * batch_size]
#         c_batch_in, c_batch_out, c_batch_sup = split_mini_batch(
#             x_train.astype(theano.config.floatX),
#             y_train.astype(theano.config.floatX), share=share, borrow=borrow)
# 
#         list_minibatchs.append(
#             {'in': c_batch_in, 'out': c_batch_out, 'sup': c_batch_sup})
#     if not sharpe:
#         # in case some samples are left
#         if (nbr_batchs * batch_size) < nbr_samples:
#             x_train = data['x'][(index+1) * batch_size:]
#             y_train = data['y'][(index+1) * batch_size:]
#             c_batch_in, c_batch_out, c_batch_sup = split_mini_batch(
#                 x_train.astype(theano.config.floatX),
#                 y_train.astype(theano.config.floatX), share=share,
#                 borrow=borrow)
#             list_minibatchs.append(
#                 {'in': c_batch_in, 'out': c_batch_out, 'sup': c_batch_sup})
# 
#     return list_minibatchs


# Path: sop_embed/experiments/keras_cnn.py
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras import backend as K
from keras.optimizers import SGD
from sop_embed.tools import split_data_to_minibatchs_eval
from sop_embed.tools import split_data_to_minibatchs_embed
import keras
import theano.tensor as T
import datetime as DT
import os
import sys
import cPickle as pkl
import numpy as np





def baseline_model():
    # create model
    input_shape = (1, 50, 50)
    model = Sequential()
    model.add(Conv2D(16, (3, 3),

                 activation='sigmoid',