% NITP Summer 2012
% Machine Learning Practical
% Pamela Douglas :)
%
% Feel free to email w/ questions or thoughts:
% pamelakdouglas@yahoo.com
%---------------------------------------
% 
% Goal: Classify ADHD vs. TD with simulated rs-fc-MRI Matricies
%
% STEPS:
% 1.) Load in simulated data .mat files
% 2.) Extract Data & Dimensions
% 2.) Create Training & Testing Attribute Relation Files for WEKA
%           - Use 3-fold cross validation, with nested 10-fold for tuning
%           params.
% 3.) Remove upper or lower triangle (redundant data)
%           - Does this change the outcome? With K*? With SVM?
% 4.) Try other feature selection methods ( if there's time  )
%
%---------------------------------------
% STEP 1:
% Load Data/Define Vars

Data=load('Data_NITP.mat'); % first 15 are ADHD

%Data=load('Data1_NITP.mat'); % This data set is less obviously 'shattered'
%... try out this if you have time at the end

Num_Folds=3; % Number of Cross Validation Folds


%---------------------------------------
% STEP 2: 
% Extract Data and Dimensions
N_ADHD=15;  N_TD=15;
Total=N_ADHD+N_TD;
temp=struct2cell(Data); Data=temp{1,1,1};
sz=size(Data); row=sz(1); col=sz(2);


% Create Attribute/ Relation File for each fold
% Define Relation Name
% first check to see if .arff file exists and then delete if it does

Num_iter=1; %Note - we are only working with the 1st "outer" fold here.  
% After multiple 'folds,' WEKA should be run at the command line.

pth='/Users/Pamela/Desktop/NITP_2012/WEKA';

N_Test=N_TD/Num_Folds;
N_Train=N_TD-N_Test;

Train=[1 N_Train 1+N_TD Total-N_Test];
Test=[N_Train+1 N_ADHD N_TD+N_Train+1 Total];

for i=1:1:Num_iter,
    %Name_Train=strcat('NITP_train_',num2str(i));
    %Name_Test=strcat('NITP_test_',num2str(i));
    
    Name_Train_NR=strcat('NITP_train_NR',num2str(i));
    Name_Test_NR=strcat('NITP_test_NR',num2str(i));
    
    data_train=cat(3,Data(:,:,Train(i,1):Train(i,2)),Data(:,:,Train(i,3):Train(i,4)));
    data_test=cat(3,Data(:,:,Test(i,1):Test(i,2)),Data(:,:,Test(i,3):Test(i,4)));
    
    
    %create_arff_nitp( pth, Name_Train, 'ADHD', 'Typical' , data_train, N_Train)
    %create_arff_nitp( pth, Name_Test, 'ADHD', 'Typical', data_test, N_Test)
    
    create_arff_nitp_NR( pth, Name_Train_NR, 'ADHD', 'Typical' , data_train, N_Train)
    create_arff_nitp_NR( pth, Name_Test_NR, 'ADHD', 'Typical', data_test, N_Test)
end


   