'''
Train Convulotional

Created on Nov 9, 2016

Train_1
Accuracy: 0.905457 epochs 20000 learning rate 0.0011 hidden 10 *
AUC 0.935988185123

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize
0.885473   10000     0.0005         5         5         4         4         4         16
AUC 0.959253821775

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize
0.998744 10000 0.0005 5 5 4 4 4 16
AUC 0.999992609017 patient 1

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize
0.835427 1000 0.0005 5 5 4 4 4 16 .5
AUC 0.945373244642 patient 1

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.913317 1000 0.0005 5 5 4 4 4 16 .3
AUC 0.959563932003 patient 1

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.932161 1000 0.0005 5 5 4 8 4 16 0.5
AUC 0.965136733186 patient 1 con todo

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.690955 1000 0.0005 5 5 4 8 4 16 0.5
AUC 0.917738359202 patient 1 con todo

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.894472 1000 0.0005 5 5 4 8 4 16 0.5
AUC 0.932804878049 patient 1 con todo

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
    1.0   10000     0.0005         5         5         4         4         4         16       0.3
AUC 1.0 patient 1

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.98995 10000 0.0005 5 5 4 4 4 16 0.7
AUC 0.992549889135 patient 1

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
1.0 10000 0.0005 5 5 8 4 4 16 0.5
AUC 1.0 patient 1

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.998744 10000 0.0005 5 5 4 8 4 16 0.5
AUC 1.0 patient 1

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
1.0 10000 0.0005 5 5 16 16 4 16 0.5
AUC 1.0 patient 1

epochs learning_rate cv1_size cv2_size cv1_channels cv2_channels hidden img_resize dropout
    10000      0.0005        5       5          16            8        4        16      0.5
Accuracy: 0.979036 Accuracy test: 0.874608
AUC 0.984848484848 AUC test 0.917033976125 patient 1

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.969849 30000 5e-05 5 5 4 8 4 16 0.5
AUC 0.99317812269 patient 1 con todo

Train_2
Accuracy: 0.936488 epochs 20000 learning rate 0.0011 hidden 10 *
AUC 0.891772920461

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize
0.936061  10000     0.0005         5         5         4         4         4         16
AUC 0.924193989071

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize
0.892452 1000 0.0005 5 5 4 4 4 16
AUC 0.748961613949

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize
0.892452 10000 0.0005 5 5 4 4 4 16
AUC 0.5 patient 2

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize
0.892452 1000 0.005 5 5 4 4 4 16
AUC 0.944406408325 patient 2

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize *
0.981746     1000     0.01         5         5         4         4         4         16
AUC 0.994771301495 patient 2

epochs learning_rate cv1_size cv2_size cv1_channels cv2_channels hidden img_resize dropout
    1000      0.01        5       5          4            4        4        16      0.5
Accuracy: 0.893004 Accuracy test: 0.891626
AUC 0.938394186459 AUC test 0.860191172777 patient 2

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.892452 10000 0.0005 5 5 4 4 4 16 0.3
AUC 0.939853484869 patient 2

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.892452 10000 0.01 5 5 4 4 4 16 0.3
AUC 0.960475400774 patient 2

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.892452 10000 0.01 5 5 4 4 4 16 0.5
AUC 0.993642896628 patient 2

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.892452 20000 0.01 5 5 4 4 4 16 0.5
AUC 0.996406854616 patient 2 con todo

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.892452 10000 0.01 5 5 4 8 4 16 0.5
AUC 0.967349795366 patient 2

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.991206 10000 0.0005 5 5 4 8 4 16 0.5
AUC 0.993636363636 patient 1 con todo

best cost 0.0323752 epoch 1472
best acc 0.997016 epoch 1591
best auc 2.69174 epoch 1623
Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.95263 10000 0.01 5 5 16 8 25 16 0.5
AUC 0.980089359522 Cost 0.132656 patient 2 con todo


Train3
Accuracy: 0.942774 epochs 20000 learning rate 0.0011 hidden 10 *
AUC 0.948229352347

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize
0.972849  10000     0.0005         5         5         4         4         4         16
AUC 0.978215983363

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize *
0.882762 10000 0.0005 5 5 4 4 4 16
AUC 0.990899754132 patient 3

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize
0.991196 10000 0.005 5 5 4 4 4 16
AUC 0.99501312336 patient 3

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.882762 10000 0.0005 5 5 4 4 4 16 0.3
AUC 0.974103928709 patient 3

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.882762 10000 0.005 5 5 4 4 4 16 0.3
AUC 0.994100193997 patient 3

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.882762 10000 0.005 5 5 4 4 4 16 0.5
AUC 0.5 patient 3

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.882762 10000 0.005 5 5 4 8 4 16 0.5
AUC 0.5 patient 3

@author: botpi

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
1.0 10000 0.0005 5 5 16 8 4 16 0.5
AUC 1.0 patient 1 con todo

epochs learning_rate cv1_size cv2_size cv1_channels cv2_channels hidden img_resize dropout
    10000      0.0005        5       5          16            8        4        16      0.5
Accuracy: 0.979036 Accuracy test: 0.874608
AUC 0.984848484848 AUC test 0.917033976125 patient 1

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.892452 10000 0.01 5 5 16 8 4 16 0.5
AUC 0.987009397457 patient 2 con todo

epochs learning_rate cv1_size cv2_size cv1_channels cv2_channels hidden img_resize dropout
    10000      0.01        5       5          16            8        4        16      0.5
Accuracy: 0.893004 Accuracy test: 0.891626
AUC 0.998617511521 AUC test 0.856761677549 patient 2

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.987952 10000 0.005 5 5 16 8 4 16 0.5
AUC 0.948616600791 patient 3 con todo

epochs learning_rate cv1_size cv2_size cv1_channels cv2_channels hidden img_resize dropout
    10000      0.005        5       5          16            8        4        16      0.5
Accuracy: 1.0 Accuracy test: 0.929398
AUC 1.0 AUC test 0.939593947815 patient 3

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.964004 1000 0.005 5 5 4 4 4 16 0.5
AUC 0.98162107207 Cost 0.27 patient 3 con todo, 4

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.989373 3000 0.005 5 5 4 4 4 16 0.5
AUC 0.992125984252 Cost 0.237044 patient 3 con todo

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.988344 3000 0.005 5 5 4 4 4 16 0.5
AUC 0.991076115486 Cost 0.328393 patient 3 con todo

Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.99182 3000 0.005 5 5 4 4 4 16 0.5
AUC 0.992505679873 Cost 0.218764 patient 3 con todo

best cost 0.0294573 epoch 2560
Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.556529 10000 0.005 5 5 4 8 16 16 0.5
AUC 0.5 Cost 0.686742 patient 3 con todo

best cost 0.00816442 epoch 3909
Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.995326 10000 0.005 5 5 4 8 16 16 0.5
AUC 0.995750728787 Cost 0.0310193 patient 3 con todo

best cost 0.204824 epoch 7258
best acc 0.728529 epoch 0
best auc 0.613361 epoch 44
Accuracy: epochs learning rate cv1 size cv2 size cv1 channels cv2channels hidden img resize dropout
0.976308 10000 0.0005 5 5 4 8 4 16 0.5
AUC 0.983739837398 Cost 0.230548 patient 1 con todo

'''
import tensorflow as tf
import numpy as np
from epinn31 import *
import scipy.io
from epinn24 import *
from params import param
from apiepi import read_images_balanced

print "begin"
patient = 1
group = "train_%s_new" % patient
parameters = param(patient)
training_epochs = 4000

#images, labels, names = read_images(group)
#print images.shape, labels.shape, len(names)
images, labels, names = read_images_balanced(group, 2)
print images.shape, labels.shape, len(names)
features, prob, acc, cost = train_tf(images, labels, parameters, training_epochs=training_epochs)

print "Accuracy:", "epochs", "learning rate", "cv1 size", "cv2 size", "cv1 channels", "cv2channels", "hidden", "img resize", "dropout"
print acc, training_epochs, parameters["learning_rate"], parameters["cv1_size"], parameters["cv2_size"], parameters["cv1_channels"], parameters["cv2_channels"], parameters["hidden"], parameters["img_resize"], parameters["dropout"]
print "AUC", auc(labels, prob), "Cost", cost, "patient", patient, "con todo"

scipy.io.savemat("resp_%s_new" % patient, features, do_compression=True)    
print "end"