function [pred, acc, optnet, optlrtheta, lastact, para] = DNNTrain(data, label, cv_data, cv_label)
% data : mxp training data matrix (no need to normalize), m is # of samples and p is # of dims
% label: m*1 training labels \in {0,1}, can be binary (class) or real-valued (reg)
% cv_data: kxp dev data matrix, used for early stopping
% cv_label: corresponding dev data labels

% neural net model consists of 'optnet','optlrtheta','para'. So just save those.

%% params setting
para.hidstruct = [200 200]; % num of hidden layers and units

% para.isRBM = true; % RBM pretraining? For small dataset, this will significantly improve performance
para.isRBM = false;
para.rbmEpoch = 60; 

para.costFunc = 'xentropy'; % cross entropy
% para.costFunc = 'maxHF'; % hit-fa maximization
% para.costFunc = 'HFAcc'; % cross+entropy + hit-fa
% para.costFunc = 'consFA'; % hit-fa max with constraint on fa
%% normalization
if para.isMVA
    [rowTrData para.tr_mu para.tr_std] = MVAProcess(data, para.MVAOrder, 0); 
    cv_data = MVAProcess_testing(cv_data, para.MVAOrder, 0, para.tr_mu, para.tr_std);
else
    [rowTrData, para.tr_mu, para.tr_std] = mean_var_norm(data);
    cv_data = mean_var_norm_testing(cv_data, para.tr_mu, para.tr_std);
end
