# Path: autoencoder/testing/regression.py
# def neural_regression(X_train, Y_train, X_val, Y_val, X_test, Y_test, nb_epoch=200, batch_size=10, seed=7):
#     reg = neural_network(X_train.shape[1])
#     reg.fit(X_train, Y_train,
#                         nb_epoch=nb_epoch,
#                         batch_size=batch_size,
#                         shuffle=True,
#                         validation_data=(X_val, Y_val),
#                         callbacks=[
#                                     ReduceLROnPlateau(monitor='val_loss', factor=0.2, patience=3, min_lr=0.01),
#                                     EarlyStopping(monitor='val_loss', min_delta=1e-5, patience=5, verbose=0, mode='auto'),
#                         ]
#                         )
#     pred = reg.predict(X_test)
#     pred = np.reshape(pred, pred.shape[0])
#     r2 = r2_score(Y_test, pred)
# 
#     return r2
# 
# Path: autoencoder/utils/io_utils.py
# def load_json(file):
#     try:
#         with open(file, 'r') as datafile:
#             data = json.load(datafile)
#     except Exception as e:
#         raise e
# 
#     return data
# 
# def load_pickle(path_to_file):
#     try:
#         with open(path_to_file, 'r') as f:
#             data = pickle.load(f)
#     except Exception as e:
#         raise e
# 
#     return data


import argparse
import numpy as np
    import pdb;pdb.set_trace()
from keras.utils import np_utils
from sklearn.model_selection import ShuffleSplit
from autoencoder.testing.regression import neural_regression
from autoencoder.utils.io_utils import load_json, load_pickle
'''
from __future__ import absolute_import


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('train_doc_codes', type=str, help='path to the train doc codes file')
    parser.add_argument('train_doc_labels', type=str, help='path to the train doc labels file')
    parser.add_argument('test_doc_codes', type=str, help='path to the test doc codes file')
    parser.add_argument('test_doc_labels', type=str, help='path to the test doc labels file')
    parser.add_argument('-nv', '--n_val', type=int, default=1000, help='size of validation set (default 1000)')
    parser.add_argument('-ne', '--n_epoch', type=int, default=100, help='num of epoches (default 100)')
    parser.add_argument('-bs', '--batch_size', type=int, default=100, help='batch size (default 100)')
    parser.add_argument('-cv', '--cross_validation', type=int, help='k-fold cross validation')
    args = parser.parse_args()

    # autoencoder
    # train_doc_codes = load_json(args.train_doc_codes)
    # train_doc_labels = load_json(args.train_doc_labels)
    # test_doc_codes = load_json(args.test_doc_codes)
    # test_doc_labels = load_json(args.test_doc_labels)
    # X_train = np.r_[train_doc_codes.values()]
    # Y_train = np.array([train_doc_labels[i] for i in train_doc_codes])
    # X_test = np.r_[test_doc_codes.values()]
    # Y_test = np.array([test_doc_labels[i] for i in test_doc_codes])

    # # DBN
    X_train = np.array(load_pickle(args.train_doc_codes))
    Y_train = load_pickle(args.train_doc_labels)
    X_test = np.array(load_pickle(args.test_doc_codes))

# Path: autoencoder/testing/regression.py
# def neural_regression(X_train, Y_train, X_val, Y_val, X_test, Y_test, nb_epoch=200, batch_size=10, seed=7):
#     reg = neural_network(X_train.shape[1])
#     reg.fit(X_train, Y_train,
#                         nb_epoch=nb_epoch,
#                         batch_size=batch_size,
#                         shuffle=True,
#                         validation_data=(X_val, Y_val),
#                         callbacks=[
#                                     ReduceLROnPlateau(monitor='val_loss', factor=0.2, patience=3, min_lr=0.01),
#                                     EarlyStopping(monitor='val_loss', min_delta=1e-5, patience=5, verbose=0, mode='auto'),
#                         ]
#                         )
#     pred = reg.predict(X_test)
#     pred = np.reshape(pred, pred.shape[0])
#     r2 = r2_score(Y_test, pred)
# 
#     return r2
# 
# Path: autoencoder/utils/io_utils.py
# def load_json(file):
#     try:
#         with open(file, 'r') as datafile:
#             data = json.load(datafile)
#     except Exception as e:
#         raise e
# 
#     return data
# 
# def load_pickle(path_to_file):
#     try:
#         with open(path_to_file, 'r') as f:
#             data = pickle.load(f)
#     except Exception as e:
#         raise e
# 
#     return data


# Path: run_regression.py
import argparse
import numpy as np
    import pdb;pdb.set_trace()
from keras.utils import np_utils
from sklearn.model_selection import ShuffleSplit
from autoencoder.testing.regression import neural_regression
from autoencoder.utils.io_utils import load_json, load_pickle

'''
from __future__ import absolute_import


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('train_doc_codes', type=str, help='path to the train doc codes file')
    parser.add_argument('train_doc_labels', type=str, help='path to the train doc labels file')
    parser.add_argument('test_doc_codes', type=str, help='path to the test doc codes file')
    parser.add_argument('test_doc_labels', type=str, help='path to the test doc labels file')
    parser.add_argument('-nv', '--n_val', type=int, default=1000, help='size of validation set (default 1000)')
    parser.add_argument('-ne', '--n_epoch', type=int, default=100, help='num of epoches (default 100)')
    parser.add_argument('-bs', '--batch_size', type=int, default=100, help='batch size (default 100)')
    parser.add_argument('-cv', '--cross_validation', type=int, help='k-fold cross validation')
    args = parser.parse_args()

    # autoencoder
    # train_doc_codes = load_json(args.train_doc_codes)
    # train_doc_labels = load_json(args.train_doc_labels)
    # test_doc_codes = load_json(args.test_doc_codes)
    # test_doc_labels = load_json(args.test_doc_labels)
    # X_train = np.r_[train_doc_codes.values()]
    # Y_train = np.array([train_doc_labels[i] for i in train_doc_codes])
    # X_test = np.r_[test_doc_codes.values()]
    # Y_test = np.array([test_doc_labels[i] for i in test_doc_codes])

    # # DBN
    X_train = np.array(load_pickle(args.train_doc_codes))
    Y_train = load_pickle(args.train_doc_labels)
    X_test = np.array(load_pickle(args.test_doc_codes))

    Y_test = load_pickle(args.test_doc_labels)