# Path: autoencoder/testing/classifier.py
# def multiclass_classifier(X_train, Y_train, X_val, Y_val, X_test, Y_test, nb_epoch=200, batch_size=10, seed=7):
#     clf = softmax_network(X_train.shape[1], Y_train.shape[1])
#     clf.fit(X_train, Y_train,
#                         epochs=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'),
#                         ]
#                         )
#     acc = clf.test_on_batch(X_test, Y_test)[1]
#     # confusion matrix and precision-recall
#     true = np.argmax(Y_test,axis=1)
#     pred = np.argmax(clf.predict(X_test), axis=1)
#     print confusion_matrix(true, pred)
#     print classification_report(true, pred)
#     return acc
# 
# def multilabel_classifier(X_train, Y_train, X_val, Y_val, X_test, Y_test, nb_epoch=200, batch_size=10, seed=7):
#     clf = sigmoid_network(X_train.shape[1], Y_train.shape[1])
#     clf.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 = clf.predict(X_test)
#     pred = (pred > .5) * 1
#     macro_f1 = f1_score(Y_test, pred, average='macro')
#     micro_f1 = f1_score(Y_test, pred, average='micro')
# 
#     return [macro_f1, micro_f1]
# 
# 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.preprocessing import LabelEncoder
from sklearn.preprocessing import MultiLabelBinarizer
from sklearn.model_selection import ShuffleSplit
from autoencoder.testing.classifier import multiclass_classifier, multilabel_classifier
from autoencoder.utils.io_utils import load_json, load_pickle
'''
Created on Dec, 2016

@author: hugo

'''
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')
    parser.add_argument('-mlc', '--multilabel_clf', action='store_true', help='multilabel classification flag')

    args = parser.parse_args()

    # autoencoder
    train_doc_codes = load_json(args.train_doc_codes)
    train_doc_labels = load_json(args.train_doc_labels)

# Path: autoencoder/testing/classifier.py
# def multiclass_classifier(X_train, Y_train, X_val, Y_val, X_test, Y_test, nb_epoch=200, batch_size=10, seed=7):
#     clf = softmax_network(X_train.shape[1], Y_train.shape[1])
#     clf.fit(X_train, Y_train,
#                         epochs=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'),
#                         ]
#                         )
#     acc = clf.test_on_batch(X_test, Y_test)[1]
#     # confusion matrix and precision-recall
#     true = np.argmax(Y_test,axis=1)
#     pred = np.argmax(clf.predict(X_test), axis=1)
#     print confusion_matrix(true, pred)
#     print classification_report(true, pred)
#     return acc
# 
# def multilabel_classifier(X_train, Y_train, X_val, Y_val, X_test, Y_test, nb_epoch=200, batch_size=10, seed=7):
#     clf = sigmoid_network(X_train.shape[1], Y_train.shape[1])
#     clf.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 = clf.predict(X_test)
#     pred = (pred > .5) * 1
#     macro_f1 = f1_score(Y_test, pred, average='macro')
#     micro_f1 = f1_score(Y_test, pred, average='micro')
# 
#     return [macro_f1, micro_f1]
# 
# 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_classifier.py
import argparse
import numpy as np
    import pdb;pdb.set_trace()
from keras.utils import np_utils
from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import MultiLabelBinarizer
from sklearn.model_selection import ShuffleSplit
from autoencoder.testing.classifier import multiclass_classifier, multilabel_classifier
from autoencoder.utils.io_utils import load_json, load_pickle

'''
Created on Dec, 2016

@author: hugo

'''
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')
    parser.add_argument('-mlc', '--multilabel_clf', action='store_true', help='multilabel classification flag')

    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)