print 'Retrieved saolib options... training model'
    
t0 = time.time()
Model = saolib.trainModel(X[:,0:nTrain],Y[:,0:nTrain],options)
t1 = time.time()
print 'Time to train model: %f' %(t1-t0)
     
# Store saolib model
# print Model['pcaModel']
# print Model['pcaModel']['basesInp']
# saolib.saveModel(Model,'MolecularDynamics.model')

# Evaluate testing set
print '... evaluating model'
t0 = time.time()
Yhat = saolib.evalModel(Model,X[:,nTrain:mpts])
t1 = time.time()
print 'Time to eval model: %f' %(t1-t0)

# Store error norm of testing set
print 'Storing testing set error norms to file'
errNorms = ((Yhat-Y[0,nTrain:mpts])/Y[0,nTrain:mpts])*100.0
# np.savetxt('MolecularDynamics_ERR.txt', errNorms, delimiter=",", fmt="%1.8e")

from matplotlib.ticker import MaxNLocator
fig = plt.figure(dpi=600)
ax = fig.add_subplot(121)
ax.plot(Y[0,nTrain:mpts],np.transpose(Yhat),'o',ms=8.0)
ax.plot([np.min(Yhat),np.max(Yhat)],[np.min(Yhat),np.max(Yhat)], ls="--", c="red",lw=2.0)
ax.set_xlabel(r'Actual Values',fontsize=16)
ax.set_ylabel(r'Predicted Values',fontsize=16)
# Break down training and testing test - randomly
nTest = npts - nTrain

# Shuffling the array to make it random
np.random.shuffle(training)

""" --- RBF model --- """
# Save X (inputs) and Y (outputs) vectors for SAOlib functionality
X = training[:, :-1].T.reshape(10, training.shape[0])
Y = training[:, 10].T.reshape(1, training.shape[0])

# Retrieve options - RBF
t0 = time.time()
options = saolib.getOptions("RBF")
Model = saolib.trainModel(X[:, 0:nTrain], Y[:, 0:nTrain], options)
Yhat_rbf = saolib.evalModel(Model, X[:, nTrain:npts])
t1 = time.time()
print "RBF MODEL TIME: %f" % (t1 - t0)

""" --- GPM model --- """
# Getting min and max value for each variable
lb = np.min(training, 0)
ub = np.max(training, 0)

# Creating an information file to be pass to the filter driver (Gaussian process model)
fp = open("gppar.dat", "w")
fp.write("%d\n" % (ninputs))  # Number of inputs
fp.write("%d\n" % (nTrain))  # Number of training points
fp.write("%d\n" % (nTest))  # Number of testing points
fp.write("0\n")
fp.write("2\n")