├── README.md ├── RVR ├── RVR_LOOCV.m ├── RVR_NFolds.m ├── RVR_W_Permutation.m ├── W_Calculate_RVR.m ├── W_Calculate_RVR_SGE.m ├── prt_machine_rvr.m └── prt_rvr.m └── SVR ├── CorrFilter_SVR_LOOCV.m ├── NBS ├── Random_Merge_100.m ├── Random_w2p_100_script.m ├── Random_w2p_100_script_2.m └── Significance_NBS.m ├── Regression_Prediction_Sig.m ├── Regression_W_Sig.m ├── Regression_W_Sig_100.m ├── Regression_W_Sig_100_ForSGE.m ├── Regression_W_Sig_100_ForSGE_parent.m ├── Regression_W_Sig_100_SGE.m ├── Regression_W_Sig_200.m ├── Regression_W_Sig_ForSGE.m ├── Regression_W_Sig_ForSGE_parent.m ├── Regression_W_Sig_MaximumStatistics.m ├── Regression_W_Sig_SGE.m ├── SVR.m~ ├── SVR_LOOCV.m ├── SVR_LOOCV_ForSGE.m ├── SVR_NFolds.m ├── SVR_NFolds_Avg.m ├── SVR_NFolds_ForSGE.m ├── SVR_NFolds_Repeat.m ├── SVR_Permutation.m ├── SVR_W_Permutation.m ├── SVR_W_Permutation_2.m ├── SVR_W_Permutation_3.m ├── SVR_W_Permutation_4.m ├── W_Calculate_SVR.m ├── W_Calculate_SVR_SGE.m ├── W_Calculate_SVR_SGE_2.m └── W_Calculate_SVR_SGE_3.m /README.md: -------------------------------------------------------------------------------- 1 | # Pattern_Regression_Matlab 2 | Matlab code for support vector regression (SVR) and revelance vector regression (RVR) analysis with cross validation to evaluate the prediction power. 3 | 4 | Also see the codes here https://github.com/ZaixuCui/Pattern_Regression_Clean. 5 | 6 | Citing our related paper will be greatly appreciated if you use these codes. 7 |
  ```Zaixu Cui, Gaolang Gong, The effect of machine learning regression algorithms and sample size on individualized behavioral prediction with functional connectivity features, (2018), NeuroImage, 178: 622-37``` 8 |
  ```Zaixu Cui, et al., Individualized Prediction of Reading Comprehension Ability Using Gray Matter Volume, (2018), Cerebral Cortex, 28(5):1656–72``` 9 |
  ```Zaixu Cui, et al., Individual variation in functional topography of association networks in youth. (2020) Neuron, 106(2): 340-53.``` 10 |
  ```Zaixu Cui, et al., Optimization of energy state transition trajectory supports the development of executive function during youth. (2020) eLife. 9:e53060. ``` 11 |
  ```Zaixu Cui, et al., 2016. Disrupted white matter connectivity underlying developmental dyslexia: A machine learning approach. Hum Brain Mapp 37, 1443-1458.``` 12 | 13 | Revelance vector Regression (RVR) is implemented using PRoNTo (http://www.mlnl.cs.ucl.ac.uk/pronto/). 14 | The function prt_rvr.m and prt_machine_rvr.m are functions of this software. 15 | Support vector regression (SVR) is implemented using LIBSVM (https://www.csie.ntu.edu.tw/~cjlin/libsvm/). 16 | 17 | Copyright (c) Zaixu Cui, State Key Laboratory of Cognitive Neuroscience and Learning, Beijing Normal University. 18 | Contact information: zaixucui@gmail.com 19 | -------------------------------------------------------------------------------- /RVR/RVR_LOOCV.m: -------------------------------------------------------------------------------- 1 | function Prediction = RVR_LOOCV(Subjects_Data, Subjects_Scores, Covariates, Pre_Method, Weight_Flag, ResultantFolder) 2 | % 3 | % Subject_Data: 4 | % m*n matrix 5 | % m is the number of subjects 6 | % n is the number of features 7 | % 8 | % Subject_Scores: 9 | % the continuous variable to be predicted, [1*m] 10 | % 11 | % Covariates: 12 | % m*n matrix 13 | % m is the number of subjects 14 | % n is the number of covariates 15 | % 16 | % Pre_Method: 17 | % 'Normalize', 'Scale', 'None' 18 | % 19 | % Weight_Flag: 20 | % whether to compute the weight, 1 or 0 21 | % 22 | % ResultantFolder: 23 | % the path of folder storing resultant files 24 | % 25 | 26 | if nargin >= 5 27 | if ~exist(ResultantFolder, 'dir') 28 | mkdir(ResultantFolder); 29 | end 30 | end 31 | 32 | [Subjects_Quantity, Feature_Quantity] = size(Subjects_Data); 33 | 34 | for i = 1:Subjects_Quantity 35 | 36 | disp(['The ' num2str(i) ' subject!']); 37 | 38 | Training_data = Subjects_Data; 39 | Training_scores = Subjects_Scores; 40 | 41 | % Select training data and testing data 42 | test_data = Training_data(i, :); 43 | test_score = Training_scores(i); 44 | Training_data(i, :) = []; 45 | Training_scores(i) = []; 46 | 47 | if ~isempty(Covariates) 48 | Covariates_test = Covariates(i, :); 49 | Covariates_training = Covariates; 50 | Covariates_training(i, :) = []; 51 | [Training_quantity, Covariates_quantity] = size(Covariates_training); 52 | M = 1; 53 | for j = 1:Covariates_quantity 54 | M = M + term(Covariates_training(:, j)); 55 | end 56 | slm = SurfStatLinMod(Training_data, M); 57 | 58 | Training_data = Training_data - repmat(slm.coef(1, :), Training_quantity, 1); 59 | for j = 1:Covariates_quantity 60 | Training_data = Training_data - ... 61 | repmat(Covariates_training(:, j), 1, Feature_Quantity) .* repmat(slm.coef(j + 1, :), Training_quantity, 1); 62 | end 63 | end 64 | 65 | if strcmp(Pre_Method, 'Normalize') 66 | %Normalizing 67 | MeanValue = mean(Training_data); 68 | StandardDeviation = std(Training_data); 69 | [~, columns_quantity] = size(Training_data); 70 | for j = 1:columns_quantity 71 | Training_data(:, j) = (Training_data(:, j) - MeanValue(j)) / StandardDeviation(j); 72 | end 73 | elseif strcmp(Pre_Method, 'Scale') 74 | % Scaling to [0 1] 75 | MinValue = min(Training_data); 76 | MaxValue = max(Training_data); 77 | [~, columns_quantity] = size(Training_data); 78 | for j = 1:columns_quantity 79 | Training_data(:, j) = (Training_data(:, j) - MinValue(j)) / (MaxValue(j) - MinValue(j)); 80 | end 81 | end 82 | Training_data_final = double(Training_data); 83 | 84 | % Covariate test data 85 | if ~isempty(Covariates) 86 | test_data = test_data - slm.coef(1, :); 87 | for j = 1:Covariates_quantity 88 | test_data = test_data - repmat(Covariates_test(j), 1, Feature_Quantity) .* slm.coef(j + 1, :); 89 | end 90 | end 91 | % Normalize test data 92 | if strcmp(Pre_Method, 'Normalize') 93 | % Normalizing 94 | test_data = (test_data - MeanValue) ./ StandardDeviation; 95 | elseif strcmp(Pre_Method, 'Scale') 96 | % Scale 97 | test_data = (test_data - MinValue) ./ (MaxValue - MinValue); 98 | end 99 | test_data_final = double(test_data); 100 | 101 | % RVR training & predicting 102 | d.train{1} = Training_data_final * Training_data_final'; 103 | d.test{1} = test_data_final * Training_data_final'; 104 | d.tr_targets = Training_scores'; 105 | d.use_kernel = 1; 106 | d.pred_type = 'regression'; 107 | output = prt_machine_rvr(d, []); 108 | 109 | Predicted_Scores(i) = output.predictions; 110 | 111 | end 112 | 113 | Prediction.Score = Predicted_Scores; 114 | [Prediction.Corr, ~] = corr(Predicted_Scores', Subjects_Scores'); 115 | Prediction.MAE = mean(abs((Predicted_Scores - Subjects_Scores))); 116 | 117 | if nargin >= 5 118 | save([ResultantFolder filesep 'Prediction_res.mat'], 'Prediction'); 119 | disp(['The correlation is ' num2str(Prediction.Corr)]); 120 | disp(['The MAE is ' num2str(Prediction.MAE)]); 121 | % Calculating w 122 | if Weight_Flag 123 | W_Calculate_RVR(Subjects_Data, Subjects_Scores, Covariates, Pre_Method, ResultantFolder); 124 | end 125 | end -------------------------------------------------------------------------------- /RVR/RVR_NFolds.m: -------------------------------------------------------------------------------- 1 | function Prediction = RVR_NFolds(Subjects_Data, Subjects_Scores, Covariates, FoldQuantity, Pre_Method, Weight_Flag, ResultantFolder, RandID) 2 | % 3 | % Subject_Data: 4 | % m*n matrix 5 | % m is the number of subjects 6 | % n is the number of features 7 | % 8 | % Subject_Scores: 9 | % the continuous variable to be predicted 10 | % 11 | % Covariates: 12 | % m*n matrix 13 | % m is the number of subjects 14 | % n is the number of covariates 15 | % 16 | % FoldQuantity: 17 | % The quantity of folds, 10 is recommended 18 | % 19 | % Pre_Method: 20 | % 'Normalize', 'Scale', 'None' 21 | % 22 | % Weight_Flag: 23 | % whether to compute the weight, 1 or 0 24 | % 25 | % ResultantFolder: 26 | % the path of folder storing resultant files 27 | % 28 | % RandID: 29 | % permutation of subjects' ID, for randomly split half 30 | % 31 | 32 | if nargin >= 6 33 | if ~exist(ResultantFolder, 'dir') 34 | mkdir(ResultantFolder); 35 | end 36 | end 37 | 38 | [Subjects_Quantity, Features_Quantity] = size(Subjects_Data); 39 | 40 | % Split into N folds randomly 41 | EachPart_Quantity = fix(Subjects_Quantity / FoldQuantity); 42 | if nargin <= 7 43 | RandID = randperm(Subjects_Quantity); 44 | end 45 | for j = 1:FoldQuantity 46 | Origin_ID{j} = RandID([(j - 1) * EachPart_Quantity + 1: j * EachPart_Quantity])'; 47 | end 48 | Reamin = mod(Subjects_Quantity, FoldQuantity); 49 | for j = 1:Reamin 50 | Origin_ID{j} = [Origin_ID{j} ; RandID(FoldQuantity * EachPart_Quantity + j)]; 51 | end 52 | 53 | for j = 1:FoldQuantity 54 | 55 | disp(['The ' num2str(j) ' fold!']); 56 | 57 | Training_data = Subjects_Data; 58 | Training_scores = Subjects_Scores; 59 | 60 | % Select training data and testing data 61 | test_data = Training_data(Origin_ID{j}, :); 62 | test_score = Training_scores(Origin_ID{j})'; 63 | Training_data(Origin_ID{j}, :) = []; 64 | Training_scores(Origin_ID{j}) = []; 65 | 66 | if ~isempty(Covariates) 67 | Covariates_test = Covariates(Origin_ID{j}, :); 68 | Covariates_training = Covariates; 69 | Covariates_training(Origin_ID{j}, :) = []; 70 | [Training_quantity, Covariates_quantity] = size(Covariates_training); 71 | M = 1; 72 | for k = 1:Covariates_quantity 73 | M = M + term(Covariates_training(:, k)); 74 | end 75 | slm = SurfStatLinMod(Training_data, M); 76 | 77 | Training_data = Training_data - repmat(slm.coef(1, :), Training_quantity, 1); 78 | for k = 1:Covariates_quantity 79 | Training_data = Training_data - ... 80 | repmat(Covariates_training(:, k), 1, Feature_Quantity) .* repmat(slm.coef(k + 1, :), Training_quantity, 1); 81 | end 82 | end 83 | 84 | if strcmp(Pre_Method, 'Normalize') 85 | % Normalizing 86 | MeanValue = mean(Training_data); 87 | StandardDeviation = std(Training_data); 88 | [~, columns_quantity] = size(Training_data); 89 | for k = 1:columns_quantity 90 | Training_data(:, k) = (Training_data(:, k) - MeanValue(k)) / StandardDeviation(k); 91 | end 92 | elseif strcmp(Pre_Method, 'Scale') 93 | % Scaling to [0 1] 94 | MinValue = min(Training_data); 95 | MaxValue = max(Training_data); 96 | [~, columns_quantity] = size(Training_data); 97 | for k = 1:columns_quantity 98 | Training_data(:, k) = (Training_data(:, k) - MinValue(k)) / (MaxValue(k) - MinValue(k)); 99 | end 100 | end 101 | Training_data_final = double(Training_data); 102 | 103 | % Covariate test data 104 | if ~isempty(Covariates) 105 | [test_quantity, ~] = sieze(test_data); 106 | test_data = test_data - repmat(slm.coef(1, :), test_quantity, 1); 107 | for k = 1:Covariates_quantity 108 | test_data = test_data - ... 109 | repmat(Covariates_test(:, k), 1, Feature_Quantity) .* repmat(slm.coef(k + 1, :), test_quantity, 1); 110 | end 111 | end 112 | % Normalize test data 113 | if strcmp(Pre_Method, 'Normalize') 114 | % Normalizing 115 | MeanValue_New = repmat(MeanValue, length(test_score), 1); 116 | StandardDeviation_New = repmat(StandardDeviation, length(test_score), 1); 117 | test_data = (test_data - MeanValue_New) ./ StandardDeviation_New; 118 | elseif strcmp(Pre_Method, 'Scale') 119 | % Scale 120 | MaxValue_New = repmat(MaxValue, length(test_score), 1); 121 | MinValue_New = repmat(MinValue, length(test_score), 1); 122 | test_data = (test_data - MinValue_New) ./ (MaxValue_New - MinValue_New); 123 | end 124 | test_data_final = double(test_data); 125 | 126 | % RVR training & predicting 127 | d.train{1} = Training_data_final * Training_data_final'; 128 | d.test{1} = test_data_final * Training_data_final'; 129 | d.tr_targets = Training_scores'; 130 | d.use_kernel = 1; 131 | d.pred_type = 'regression'; 132 | output = prt_machine_rvr(d, []); 133 | 134 | Prediction.Origin_ID{j} = Origin_ID{j}; 135 | Prediction.Score{j} = output.predictions; 136 | Prediction.Corr(j) = corr(output.predictions, test_score); 137 | Prediction.MAE(j) = mean(abs(output.predictions - test_score)); 138 | 139 | end 140 | 141 | Prediction.Mean_Corr = mean(Prediction.Corr); 142 | Prediction.Mean_MAE = mean(Prediction.MAE); 143 | if nargin >= 6 144 | save([ResultantFolder filesep 'Prediction_res.mat'], 'Prediction'); 145 | disp(['The correlation is ' num2str(Prediction.Mean_Corr)]); 146 | disp(['The MAE is ' num2str(Prediction.Mean_MAE)]); 147 | % Calculating w 148 | if Weight_Flag 149 | W_Calculate_RVR(Subjects_Data, Subjects_Scores, Covariates, Pre_Method, ResultantFolder); 150 | end 151 | end 152 | -------------------------------------------------------------------------------- /RVR/RVR_W_Permutation.m: -------------------------------------------------------------------------------- 1 | 2 | function RVR_W_Permutation(Data_Path, Scores, Perm_times_Range, RandIndex_Folder, Covariates, Pre_Method, ResultantFolder, Queue) 3 | 4 | TaskQuantity = 100; 5 | JobsPerTask = fix(length(Perm_times_Range) / TaskQuantity); 6 | JobsRemain = mod(length(Perm_times_Range), TaskQuantity * JobsPerTask); 7 | 8 | mkdir([ResultantFolder filesep 'rand_perm']); 9 | 10 | for i = 1:100 11 | i 12 | 13 | ID = Perm_times_Range([(i - 1) * JobsPerTask + 1 : i * JobsPerTask]); 14 | if i == 100 & JobsRemain 15 | ID = [ID Perm_times_Range(length(Perm_times_Range) - JobsRemain + 1 : end)]; 16 | end 17 | for j = 1:length(ID) 18 | % Rand_Index = randperm(length(Scores)); 19 | load([RandIndex_Folder filesep 'RandID_' num2str(ID(j)) '.mat']); 20 | Rand_Index = RandID; 21 | Rand_Score{j} = Scores(Rand_Index); 22 | end 23 | 24 | save([ResultantFolder filesep 'rand_perm' filesep 'rand_perm_' num2str(i) '.mat'], 'Rand_Score'); 25 | Job_Name = ['perm_W_' num2str(i)]; 26 | pipeline.(Job_Name).command = 'W_Calculate_RVR_SGE(opt.para1, opt.para2, opt.para3, opt.para4, opt.para5, opt.para6)'; 27 | pipeline.(Job_Name).opt.para1 = Data_Path; 28 | pipeline.(Job_Name).opt.para2 = Rand_Score; 29 | pipeline.(Job_Name).opt.para3 = ID; 30 | pipeline.(Job_Name).opt.para4 = Covariates; 31 | pipeline.(Job_Name).opt.para5 = Pre_Method; 32 | pipeline.(Job_Name).opt.para6 = ResultantFolder; 33 | clear Rand_Score; 34 | end 35 | 36 | Pipeline_opt.mode = 'qsub'; 37 | Pipeline_opt.qsub_options = Queue; 38 | Pipeline_opt.mode_pipeline_manager = 'batch'; 39 | Pipeline_opt.max_queued = 200; 40 | Pipeline_opt.flag_verbose = 1; 41 | Pipeline_opt.flag_pause = 0; 42 | Pipeline_opt.flag_update = 1; 43 | Pipeline_opt.path_logs = [ResultantFolder filesep 'logs']; 44 | 45 | psom_run_pipeline(pipeline,Pipeline_opt); 46 | 47 | 48 | -------------------------------------------------------------------------------- /RVR/W_Calculate_RVR.m: -------------------------------------------------------------------------------- 1 | 2 | function [w_Brain, model_All] = W_Calculate_RVR(Subjects_Data, Subjects_Scores, Covariates, Pre_Method, ResultantFolder) 3 | % 4 | % Subject_Data: 5 | % m*n matrix 6 | % m is the number of subjects 7 | % n is the number of features 8 | % 9 | % Subject_Scores: 10 | % the continuous variable to be predicted,[1*m] 11 | % 12 | % Covariates: 13 | % m*n matrix 14 | % m is the number of subjects 15 | % n is the number of covariates 16 | % 17 | % Pre_Method: 18 | % 'Normalize', 'Scale', 'None' 19 | % 20 | % ResultantFolder: 21 | % the path of folder storing resultant files 22 | % 23 | 24 | if nargin >= 5 25 | if ~exist(ResultantFolder, 'dir') 26 | mkdir(ResultantFolder); 27 | end 28 | end 29 | 30 | [Subjects_Quantity, Features_Quantity] = size(Subjects_Data); 31 | 32 | if ~isempty(Covariates) 33 | [~, Covariates_quantity] = size(Covariates); 34 | M = 1; 35 | for j = 1:Covariates_quantity 36 | M = M + term(Covariates(:, j)); 37 | end 38 | slm = SurfStatLinMod(Subjects_Data, M); 39 | 40 | Subjects_Data = Subjects_Data - repmat(slm.coef(1, :), Subjects_Quantity, 1); 41 | for j = 1:Covariates_quantity 42 | Subjects_Data = Subjects_Data - ... 43 | repmat(Covariates(:, j), 1, Features_Quantity) .* repmat(slm.coef(j + 1, :), Subjects_Quantity, 1); 44 | end 45 | end 46 | 47 | if strcmp(Pre_Method, 'Normalize') 48 | %Normalizing 49 | MeanValue = mean(Subjects_Data); 50 | StandardDeviation = std(Subjects_Data); 51 | [~, columns_quantity] = size(Subjects_Data); 52 | for j = 1:columns_quantity 53 | Subjects_Data(:, j) = (Subjects_Data(:, j) - MeanValue(j)) / StandardDeviation(j); 54 | end 55 | elseif strcmp(Pre_Method, 'Scale') 56 | % Scaling to [0 1] 57 | MinValue = min(Subjects_Data); 58 | MaxValue = max(Subjects_Data); 59 | [~, columns_quantity] = size(Subjects_Data); 60 | for j = 1:columns_quantity 61 | Subjects_Data(:, j) = (Subjects_Data(:, j) - MinValue(j)) / (MaxValue(j) - MinValue(j)); 62 | end 63 | end 64 | 65 | % SVR 66 | Subjects_Data = double(Subjects_Data); 67 | d.train{1} = Subjects_Data * Subjects_Data'; 68 | d.test{1} = Subjects_Data * Subjects_Data'; 69 | d.tr_targets = Subjects_Scores'; 70 | d.use_kernel = 1; 71 | d.pred_type = 'regression'; 72 | model_All = prt_machine_rvr(d, []); 73 | 74 | w_Brain = zeros(1, Features_Quantity); 75 | for i = 1:length(model_All.alpha) 76 | w_Brain = w_Brain + model_All.alpha(i) * Subjects_Data(i, :); 77 | end 78 | 79 | w_Brain = w_Brain / norm(w_Brain); 80 | 81 | if nargin >= 5 82 | save([ResultantFolder filesep 'w_Brain.mat'], 'w_Brain'); 83 | end 84 | -------------------------------------------------------------------------------- /RVR/W_Calculate_RVR_SGE.m: -------------------------------------------------------------------------------- 1 | 2 | function W_Calculate_RVR_SGE(Subjects_Data_Path, Rand_Scores, ID, Covariates, Pre_Method, ResultantFolder) 3 | 4 | tmp = load(Subjects_Data_Path); 5 | FieldName = fieldnames(tmp); 6 | 7 | for i = 1:length(ID) 8 | disp(ID(i)); 9 | [w_Brain, ~] = W_Calculate_RVR(tmp.(FieldName{1}), Rand_Scores{i}, Covariates, Pre_Method); 10 | save([ResultantFolder filesep 'w_Brain_' num2str(ID(i)) '.mat'], 'w_Brain'); 11 | end -------------------------------------------------------------------------------- /RVR/prt_machine_rvr.m: -------------------------------------------------------------------------------- 1 | function output = prt_machine_rvr(d,args) 2 | % Relevance vector regression (training and testing) 3 | % FORMAT output = prt_machine_svm_bin(d,args) 4 | % Inputs: 5 | % d - structure with data information, with mandatory fields: 6 | % .train - training data (cell array of matrices of row vectors, 7 | % each [Ntr x D]). each matrix contains one representation 8 | % of the data. This is useful for approaches such as 9 | % multiple kernel learning. 10 | % .test - testing data (cell array of matrices row vectors, each 11 | % [Nte x D]) 12 | % .tr_targets - training labels (for classification) or values (for 13 | % regression) (column vector, [Ntr x 1]) 14 | % .use_kernel - flag, is data in form of kernel matrices (true) of in 15 | % form of features (false) 16 | % args - libSVM arguments 17 | % Output: 18 | % output - output of machine (struct). 19 | % * Mandatory fields: 20 | % .predictions - predictions of classification or regression [Nte x D] 21 | % * Optional fields: 22 | % .func_val - value of the decision function 23 | % .type - which type of machine this is (here, 'classifier') 24 | %__________________________________________________________________________ 25 | % Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory 26 | 27 | % Written by Carlton Chu 28 | % $Id: prt_machine_rvr.m 741 2013-07-22 14:07:36Z mjrosa $ 29 | 30 | 31 | output.type=d.pred_type; 32 | 33 | SANITYCHECK=true; % can turn off for "speed". Expert only. 34 | 35 | if SANITYCHECK==true 36 | % args should be a string (empty or otherwise) 37 | 38 | K=d.train{1}; 39 | [n m]=size(K); 40 | if n~=m 41 | error('prt_machine_krr:kernelSize',['Error: krr'... 42 | ' training kernel should be square ' ... 43 | ' SOLUTION: do the right thing']); 44 | end 45 | 46 | % Run RVR 47 | %-------------------------------------------------------------------------- 48 | t=d.tr_targets; 49 | w=prt_rvr(K,t); 50 | 51 | output.predictions=d.test{1}*w(1:end-1)+w(end); 52 | output.func_val=output.predictions; 53 | output.alpha=w(1:end-1); 54 | 55 | end 56 | 57 | end 58 | -------------------------------------------------------------------------------- /RVR/prt_rvr.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZaixuCui/Pattern_Regression_Matlab/6525b0f2752bb69f3778668effd0e3562845113f/RVR/prt_rvr.m -------------------------------------------------------------------------------- /SVR/CorrFilter_SVR_LOOCV.m: -------------------------------------------------------------------------------- 1 | function Prediction = CorrFilter_SVR_LOOCV(Subjects_Data, Subjects_Scores, CoefThreshold, Pre_Method, ResultantFolder) 2 | % 3 | % Subject_Data: 4 | % m*n matrix 5 | % m is the number of subjects 6 | % n is the number of features 7 | % 8 | % Subject_Scores: 9 | % the continuous variable to be predicted 10 | % 11 | % Pre_Method: 12 | % 'Normalize' or 'Scale' 13 | % 14 | % ResultantFolder: 15 | % the path of folder storing resultant files 16 | % 17 | 18 | if nargin >= 4 19 | if ~exist(ResultantFolder, 'dir') 20 | mkdir(ResultantFolder); 21 | end 22 | end 23 | 24 | [Subjects_Quantity, Feature_Quantity] = size(Subjects_Data); 25 | 26 | Feature_Frequency = zeros(1, Feature_Quantity); 27 | for i = 1:Subjects_Quantity 28 | 29 | disp(['The ' num2str(i) ' iteration!']); 30 | 31 | Training_data = Subjects_Data; 32 | Training_scores = Subjects_Scores; 33 | 34 | % Select training data and testing data 35 | test_data = Training_data(i, :); 36 | test_score = Training_scores(i); 37 | Training_data(i, :) = []; 38 | Training_scores(i) = []; 39 | 40 | coef = corr(Training_data, Training_scores'); 41 | coef(find(isnan(coef))) = 0; 42 | RetainID{i} = find(abs(coef) > CoefThreshold); 43 | Training_data_New = Training_data(:, RetainID{i}); 44 | Selected_Mask = zeros(1, Feature_Quantity); 45 | Selected_Mask(RetainID{i}) = 1; 46 | Feature_Frequency = Feature_Frequency + Selected_Mask; 47 | 48 | % Normalizing 49 | if strcmp(Pre_Method, 'Normalize') 50 | % Normalizing 51 | MeanValue = mean(Training_data_New); 52 | StandardDeviation = std(Training_data_New); 53 | [~, columns_quantity] = size(Training_data_New); 54 | for j = 1:columns_quantity 55 | Training_data_New(:, j) = (Training_data_New(:, j) - MeanValue(j)) / StandardDeviation(j); 56 | end 57 | elseif strcmp(Pre_Method, 'Scale') 58 | % Scaling to [0 1] 59 | MinValue = min(Training_data_New); 60 | MaxValue = max(Training_data_New); 61 | [~, columns_quantity] = size(Training_data_New); 62 | for j = 1:columns_quantity 63 | Training_data_New(:, j) = (Training_data_New(:, j) - MinValue(j)) / (MaxValue(j) - MinValue(j)); 64 | end 65 | end 66 | 67 | % SVR training 68 | Training_scores = Training_scores'; 69 | Training_data_New = double(Training_data_New); 70 | model(i) = svmtrain(Training_scores, Training_data_New,'-s 3 -t 2'); 71 | 72 | test_data_New = test_data(:, RetainID{i}); 73 | % Normalizing 74 | if strcmp(Pre_Method, 'Normalize') 75 | % Normalizing 76 | test_data_New = (test_data_New - MeanValue) ./ StandardDeviation; 77 | elseif strcmp(Pre_Method, 'Scale') 78 | % Scale 79 | test_data_New = (test_data_New - MinValue) ./ (MaxValue - MinValue); 80 | end 81 | 82 | % predicts 83 | test_data_New = double(test_data_New); 84 | [Predicted_Scores(i), ~, ~] = svmpredict(test_score, test_data_New, model(i)); 85 | 86 | end 87 | Prediction.Score = Predicted_Scores; 88 | [Prediction.Corr, ~] = corr(Predicted_Scores', Subjects_Scores'); 89 | Prediction.MAE = mean(abs((Predicted_Scores - Subjects_Scores))); 90 | Prediction.Feature_Frequency = Feature_Frequency; 91 | if nargin >= 4 92 | save([ResultantFolder filesep 'Prediction_res.mat'], 'Prediction'); 93 | disp(['The correlation is ' num2str(Prediction.Corr)]); 94 | disp(['The MSE is ' num2str(Prediction.MAE)]); 95 | end 96 | 97 | -------------------------------------------------------------------------------- /SVR/NBS/Random_Merge_100.m: -------------------------------------------------------------------------------- 1 | 2 | Rand_w_Brain_Path_Cell = g_ls('/data/s5/cuizaixu/DATA_ShuHua_ReadingAbility/SVR_Analysis/FunctionalConn_DARTEL_Random_L512R512_NoSmooth_GlobalRegress_01/res_WLR_left_44/Permutation/Permutation_W/w_Brain*.mat'); 3 | ResultantFolder = '/data/s5/cuizaixu/DATA_ShuHua_ReadingAbility/SVR_Analysis/FunctionalConn_DARTEL_Random_L512R512_NoSmooth_GlobalRegress_01/res_WLR_left_44/Permutation/Permutation_W_200'; 4 | 5 | for i = 1:50 6 | disp(i); 7 | for j = 1:200 8 | Rand_W = load(Rand_w_Brain_Path_Cell{(i - 1) * 200 + j}); 9 | Rand_W_200(j, :) = Rand_W.w_Brain; 10 | end 11 | save([ResultantFolder filesep 'Rand_W_200_' num2str(i) '.mat'], 'Rand_W_200'); 12 | clear Rand_W_200; 13 | end -------------------------------------------------------------------------------- /SVR/NBS/Random_w2p_100_script.m: -------------------------------------------------------------------------------- 1 | 2 | RandW_Cell = g_ls('/data/s5/cuizaixu/DATA_ShuHua_ReadingAbility/SVR_Analysis/FunctionalConn_DARTEL_Random_L512R512_NoSmooth_GlobalRegress_01/res_WLR_left_44/Permutation/Permutation_W/*.mat'); 3 | RandMerge100_Cell = g_ls('/data/s5/cuizaixu/DATA_ShuHua_ReadingAbility/SVR_Analysis/FunctionalConn_DARTEL_Random_L512R512_NoSmooth_GlobalRegress_01/res_WLR_left_44/Permutation/Permutation_W_Merge100/*.mat'); 4 | ResultantFolder = '/data/s5/cuizaixu/DATA_ShuHua_ReadingAbility/SVR_Analysis/FunctionalConn_DARTEL_Random_L512R512_NoSmooth_GlobalRegress_01/res_WLR_left_44/Permutation/Permutation_W_P_2'; 5 | Regression_W_Sig_100_SGE(RandW_Cell([1:5000]), RandMerge100_Cell, ResultantFolder, '-q veryshort.q') -------------------------------------------------------------------------------- /SVR/NBS/Random_w2p_100_script_2.m: -------------------------------------------------------------------------------- 1 | 2 | RandW_Cell = g_ls('/data/s5/cuizaixu/DATA_ShuHua_ReadingAbility/SVR_Analysis/FunctionalConn_DARTEL_Random_L512R512_NoSmooth_GlobalRegress_01/res_WLR_left_44/Permutation/Permutation_W/*.mat'); 3 | RandMerge100_Cell = g_ls('/data/s5/cuizaixu/DATA_ShuHua_ReadingAbility/SVR_Analysis/FunctionalConn_DARTEL_Random_L512R512_NoSmooth_GlobalRegress_01/res_WLR_left_44/Permutation/Permutation_W_Merge100/*.mat'); 4 | ResultantFolder = '/data/s5/cuizaixu/DATA_ShuHua_ReadingAbility/SVR_Analysis/FunctionalConn_DARTEL_Random_L512R512_NoSmooth_GlobalRegress_01/res_WLR_left_44/Permutation/Permutation_W_P'; 5 | Regression_W_Sig_100_SGE(RandW_Cell([5001:10000]), RandMerge100_Cell, ResultantFolder, '-q verylong.q') -------------------------------------------------------------------------------- /SVR/NBS/Significance_NBS.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | % Random_P_Map = g_ls('/data/s5/cuizaixu/DATA_ShuHua_ReadingAbility/SVR_Analysis/FunctionalConn_DARTEL_Random_L512R512_NoSmooth_GlobalRegress_01/res_WLR_left_44/Permutation/Permutation_W_P/*.mat'); 4 | tmp = tril(magic(512), -1); 5 | Index = find(tmp); 6 | 7 | % for i = 1:length(Random_P_Map) 8 | % i 9 | % load(Random_P_Map{i}); 10 | % Sig_Index = find(w_Brain_PValue < 0.0005); 11 | % Sig_Mask = zeros(size(w_Brain_PValue)); 12 | % Sig_Mask(Sig_Index) = 1; 13 | % Sig_Mask_Matrix = zeros(size(tmp)); 14 | % Sig_Mask_Matrix(Index) = Sig_Mask; 15 | % Sig_Mask_Matrix = Sig_Mask_Matrix + Sig_Mask_Matrix'; 16 | % [ci_rand sizes_rand] = components(sparse(Sig_Mask_Matrix)); 17 | % NumofEdge_rand = zeros(length(sizes_rand),1); 18 | % for j = 1:length(sizes_rand) 19 | % index_subn = find(ci_rand == j); 20 | % if length(index_subn) == 1 21 | % NumofEdge_rand(j) = 0; 22 | % else 23 | % subn = Sig_Mask_Matrix(index_subn, index_subn); 24 | % NumofEdge_rand(j) = sum(sum(subn))/2; 25 | % end 26 | % end 27 | % max_NumofEdge_rand(i) = max(NumofEdge_rand); 28 | % end 29 | % save max_NumofEdge_rand.mat max_NumofEdge_rand; 30 | 31 | load /data/s5/cuizaixu/DATA_ShuHua_ReadingAbility/SVR_Analysis/FunctionalConn_DARTEL_Random_L512R512_NoSmooth_GlobalRegress_01/res_WLR_left_44/w_Brain_PValue.mat; 32 | Sig_Index = find(w_Brain_PValue < 0.0005); 33 | Sig_Mask = zeros(size(w_Brain_PValue)); 34 | Sig_Mask(Sig_Index) = 1; 35 | Sig_Mask_Matrix = zeros(size(tmp)); 36 | Sig_Mask_Matrix(Index) = Sig_Mask; 37 | Sig_Mask_Matrix = Sig_Mask_Matrix + Sig_Mask_Matrix'; 38 | [ci_real sizes_real] = components(sparse(Sig_Mask_Matrix)); 39 | NumofEdge_real = zeros(length(sizes_real),1); 40 | num = 0; 41 | for j = 1:length(sizes_real) 42 | index_subn = find(ci_real == j); 43 | if length(index_subn) == 1 44 | NumofEdge_real(j) = 0; 45 | else 46 | subn = Sig_Mask_Matrix(index_subn, index_subn); 47 | NumofEdge_real(j) = sum(sum(subn))/2; 48 | if length(find(max_NumofEdge_rand > NumofEdge_real(j))) / 10000 <= 0.05 49 | num = num + 1; 50 | SigComponent_index{num} = index_subn; 51 | end 52 | end 53 | end 54 | save NumofEdge_real.mat NumofEdge_real; 55 | 56 | load /data/s5/cuizaixu/DATA_ShuHua_ReadingAbility/SVR_Analysis/FunctionalConn_DARTEL_Random_L512R512_NoSmooth_GlobalRegress_01/res_WLR_left_44/w_Brain.mat; 57 | NBSSig_Mask = zeros(size(tmp)); 58 | Weight_Matrix = zeros(size(tmp)); 59 | Weight_Matrix(Index) = w_Brain; 60 | Weight_Matrix = Weight_Matrix + Weight_Matrix'; 61 | for i = 1:length(SigComponent_index) 62 | NBSSig_Mask(SigComponent_index{i}, SigComponent_index{i}) = NBSSig_Mask(SigComponent_index{i}, SigComponent_index{i}) + ... 63 | Sig_Mask_Matrix(SigComponent_index{i}, SigComponent_index{i}); 64 | end 65 | NBSSig_W = NBSSig_Mask .* Weight_Matrix; 66 | save NBSSig_W.mat NBSSig_W; 67 | 68 | Node_Weight = sum(NBSSig_W); 69 | Node_Index = find(Node_Weight); 70 | BrainNet_GenCoord('/data/s5/cuizaixu/DATA_ShuHua_ReadingAbility/GM_Atlas/Random_left_512_right_512_2/Left_512_Right_512_Template/left_512_right_512_44.nii', 'WLR_left_00005_NBS005.node', Node_Index, Node_Weight(Node_Index)); 71 | 72 | Edge_00005_NBS005 = NBSSig_W(Node_Index, Node_Index); 73 | save WLR_left_00005_NBS005.edge Edge_00005_NBS005 -ascii; -------------------------------------------------------------------------------- /SVR/Regression_Prediction_Sig.m: -------------------------------------------------------------------------------- 1 | 2 | function Prediction_Sig = Regression_Prediction_Sig(Real_Prediction_Path, Rand_Prediction_Path_Cell) 3 | 4 | load(Real_Prediction_Path); 5 | 6 | RandomQuantity = length(Rand_Prediction_Path_Cell); 7 | for i = 1:RandomQuantity 8 | i 9 | tmp = load(Rand_Prediction_Path_Cell{i}); 10 | Rand_Corr(i) = tmp.Prediction.Corr; 11 | Rand_MAE(i) = tmp.Prediction.MAE; 12 | end 13 | % Corr, the bigger, the better 14 | Corr_Sig = length(find(Rand_Corr >= Prediction.Corr)) / RandomQuantity; 15 | % MAE, the smaller, the better 16 | MAE_Sig = length(find(Rand_MAE <= Prediction.MAE)) / RandomQuantity; 17 | 18 | Prediction_Sig.Corr_PValue = Corr_Sig; 19 | Prediction_Sig.MAE_PValue = MAE_Sig; 20 | 21 | [ResultantFolder, ~, ~] = fileparts(Real_Prediction_Path); 22 | save([ResultantFolder filesep 'Prediction_Sig.mat'], 'Prediction_Sig'); 23 | -------------------------------------------------------------------------------- /SVR/Regression_W_Sig.m: -------------------------------------------------------------------------------- 1 | 2 | function w_Brain_PValue = Regression_W_Sig(Real_w_Brain_Path, Rand_w_Brain_Path_Cell) 3 | 4 | Original_W = load(Real_w_Brain_Path); 5 | 6 | RandomQuantity = length(Rand_w_Brain_Path_Cell); 7 | w_Brain_PValue = zeros(1, length(Original_W.w_Brain)); 8 | for i = 1:RandomQuantity 9 | i 10 | Rand_W = load(Rand_w_Brain_Path_Cell{i}); 11 | 12 | Compare_w = abs(Rand_W.w_Brain) - abs(Original_W.w_Brain); 13 | Compare_w(find(Compare_w >= 0)) = 1; 14 | Compare_w(find(Compare_w < 0)) = 0; 15 | w_Brain_PValue = w_Brain_PValue + Compare_w; 16 | end 17 | w_Brain_PValue = w_Brain_PValue / RandomQuantity; 18 | 19 | [ResultantFolder, ~, ~] = fileparts(Real_w_Brain_Path); 20 | save([ResultantFolder filesep 'w_Brain_PValue.mat'], 'w_Brain_PValue'); -------------------------------------------------------------------------------- /SVR/Regression_W_Sig_100.m: -------------------------------------------------------------------------------- 1 | 2 | function w_Brain_PValue = Regression_W_Sig_100(Real_w_Brain_Path, Rand_w_Brain_100_Path_Cell) 3 | 4 | load(Real_w_Brain_Path); 5 | w_Brain_100 = repmat(w_Brain, 100, 1); 6 | 7 | RandomQuantity = length(Rand_w_Brain_100_Path_Cell); 8 | w_Brain_PValue = zeros(1, length(w_Brain)); 9 | 10 | for i = 1:RandomQuantity 11 | i 12 | Rand_W = load(Rand_w_Brain_100_Path_Cell{i}); 13 | 14 | Compare_w = abs(Rand_W.Rand_W_100) - abs(w_Brain_100); 15 | Compare_w(find(Compare_w >= 0)) = 1; 16 | Compare_w(find(Compare_w < 0)) = 0; 17 | w_Brain_PValue = w_Brain_PValue + sum(Compare_w); 18 | end 19 | w_Brain_PValue = w_Brain_PValue / (RandomQuantity * 100); 20 | 21 | [ResultantFolder, ~, ~] = fileparts(Real_w_Brain_Path); 22 | save([ResultantFolder filesep 'w_Brain_PValue.mat'], 'w_Brain_PValue'); 23 | -------------------------------------------------------------------------------- /SVR/Regression_W_Sig_100_ForSGE.m: -------------------------------------------------------------------------------- 1 | 2 | function w_Brain_PValue = Regression_W_Sig_100_ForSGE(Real_w_Brain_Path, Rand_w_Brain_100_Path_Cell, ResultantFolder) 3 | 4 | load(Real_w_Brain_Path); 5 | w_Brain_100 = repmat(w_Brain, 100, 1); 6 | 7 | RandomQuantity = length(Rand_w_Brain_100_Path_Cell); 8 | w_Brain_PValue = zeros(1, length(w_Brain)); 9 | 10 | for i = 1:RandomQuantity 11 | Rand_W = load(Rand_w_Brain_100_Path_Cell{i}); 12 | 13 | Compare_w = abs(Rand_W.Rand_W_100) - abs(w_Brain_100); 14 | Compare_w(find(Compare_w >= 0)) = 1; 15 | Compare_w(find(Compare_w < 0)) = 0; 16 | w_Brain_PValue = w_Brain_PValue + sum(Compare_w); 17 | end 18 | w_Brain_PValue = w_Brain_PValue / (RandomQuantity * 100); 19 | 20 | [~, FileName, ~] = fileparts(Real_w_Brain_Path); 21 | save([ResultantFolder filesep FileName '_PValue.mat'], 'w_Brain_PValue'); 22 | -------------------------------------------------------------------------------- /SVR/Regression_W_Sig_100_ForSGE_parent.m: -------------------------------------------------------------------------------- 1 | 2 | function Regression_W_Sig_100_ForSGE_parent(w_Brain_Path_Cell, Rand_w_Brain_100_Path_Cell, ResultantFolder) 3 | 4 | 5 | for i = 1:length(w_Brain_Path_Cell) 6 | i 7 | DateNow = datevec(datenum(now)); 8 | DateNowString = [num2str(DateNow(1)) '_' num2str(DateNow(2), '%02d') '_' num2str(DateNow(3), '%02d') '_' num2str(DateNow(4), '%02d') '_' num2str(DateNow(5), '%02d')]; 9 | disp(DateNowString); 10 | Regression_W_Sig_100_ForSGE(w_Brain_Path_Cell{i}, Rand_w_Brain_100_Path_Cell, ResultantFolder); 11 | end -------------------------------------------------------------------------------- /SVR/Regression_W_Sig_100_SGE.m: -------------------------------------------------------------------------------- 1 | 2 | function Regression_W_Sig_100_SGE(w_Brain_Path_Cell, Rand_w_Brain_Path_Cell_Path, ResultantFolder, Queue) 3 | % 4 | % using Regression_W_Sig_100 function 5 | % 6 | 7 | TaskQuantity = 100; 8 | JobsPerTask = fix(length(w_Brain_Path_Cell) / TaskQuantity); 9 | JobsRemain = mod(length(w_Brain_Path_Cell), TaskQuantity * JobsPerTask); 10 | 11 | if ~exist(ResultantFolder, 'dir') 12 | mkdir(ResultantFolder); 13 | end 14 | 15 | for i = 97:99 16 | w_Brain_Path_Cell_Sub = w_Brain_Path_Cell([(i - 1) * JobsPerTask + 1 : i * JobsPerTask]); 17 | if i == 100 & JobsRemain 18 | w_Brain_Path_Cell_Sub = [w_Brain_Path_Cell_Sub; w_Brain_Path_Cell_Sub(length(Perm_times_Range) - JobsRemain + 1 : end)]; 19 | end 20 | Job_Name = ['perm_w2p_' num2str(i)]; 21 | pipeline.(Job_Name).command = 'Regression_W_Sig_100_ForSGE_parent(opt.para1, opt.para2, opt.para3)'; 22 | pipeline.(Job_Name).opt.para1 = w_Brain_Path_Cell_Sub; 23 | pipeline.(Job_Name).opt.para2 = Rand_w_Brain_Path_Cell_Path; 24 | pipeline.(Job_Name).opt.para3 = ResultantFolder; 25 | end 26 | 27 | Pipeline_opt.mode = 'qsub'; 28 | Pipeline_opt.qsub_options = Queue; 29 | Pipeline_opt.mode_pipeline_manager = 'background'; 30 | Pipeline_opt.max_queued = 100; 31 | Pipeline_opt.flag_verbose = 1; 32 | Pipeline_opt.flag_pause = 0; 33 | Pipeline_opt.flag_update = 1; 34 | Pipeline_opt.path_logs = [ResultantFolder filesep 'logs']; 35 | 36 | psom_run_pipeline(pipeline,Pipeline_opt); 37 | -------------------------------------------------------------------------------- /SVR/Regression_W_Sig_200.m: -------------------------------------------------------------------------------- 1 | 2 | function w_Brain_PValue = Regression_W_Sig_200(Real_w_Brain_Path, Rand_w_Brain_200_Path_Cell) 3 | 4 | load(Real_w_Brain_Path); 5 | w_Brain_200 = repmat(w_Brain, 200, 1); 6 | 7 | RandomQuantity = length(Rand_w_Brain_200_Path_Cell); 8 | w_Brain_PValue = zeros(1, length(w_Brain)); 9 | 10 | for i = 1:RandomQuantity 11 | i 12 | Rand_W = load(Rand_w_Brain_200_Path_Cell{i}); 13 | 14 | Compare_w = abs(Rand_W.Rand_W_200) - abs(w_Brain_200); 15 | Compare_w(find(Compare_w >= 0)) = 1; 16 | Compare_w(find(Compare_w < 0)) = 0; 17 | w_Brain_PValue = w_Brain_PValue + sum(Compare_w); 18 | end 19 | w_Brain_PValue = w_Brain_PValue / (RandomQuantity * 200); 20 | 21 | [ResultantFolder, ~, ~] = fileparts(Real_w_Brain_Path); 22 | save([ResultantFolder filesep 'w_Brain_PValue.mat'], 'w_Brain_PValue'); 23 | -------------------------------------------------------------------------------- /SVR/Regression_W_Sig_ForSGE.m: -------------------------------------------------------------------------------- 1 | 2 | function w_Brain_PValue = Regression_W_Sig_ForSGE(w_Brain_Path, Rand_w_Brain_Path_Cell_Path) 3 | 4 | % 5 | % w_Brain_Path: 6 | % The full path of .mat file contain w_Brain to be converted to p map 7 | % 8 | % Rand_w_Brain_Path_Cell_Path: 9 | % The full path of .mat file contain the paths of rand w_brain 10 | % 11 | 12 | load(w_Brain_Path); 13 | load(Rand_w_Brain_Path_Cell_Path); 14 | 15 | RandomQuantity = length(Rand_w_Brain_Path_Cell); 16 | w_Brain_PValue = zeros(1, length(w_Brain)); 17 | 18 | for i = 1:RandomQuantity 19 | if ~mod(i, 1000) 20 | disp(i); 21 | end 22 | Rand_W = load(Rand_w_Brain_Path_Cell{i}); 23 | 24 | Compare_w = abs(Rand_W.w_Brain) - abs(w_Brain); 25 | Compare_w(find(Compare_w >= 0)) = 1; 26 | Compare_w(find(Compare_w < 0)) = 0; 27 | w_Brain_PValue = w_Brain_PValue + Compare_w; 28 | end 29 | w_Brain_PValue = w_Brain_PValue / RandomQuantity; 30 | 31 | [ResultantFolder, FileName, ~] = fileparts(w_Brain_Path); 32 | save([ResultantFolder filesep FileName '_PValue.mat'], 'w_Brain_PValue'); -------------------------------------------------------------------------------- /SVR/Regression_W_Sig_ForSGE_parent.m: -------------------------------------------------------------------------------- 1 | 2 | function Regression_W_Sig_ForSGE_parent(w_Brain_Path_Cell, Rand_w_Brain_Path_Cell_Path) 3 | 4 | 5 | for i = 1:length(w_Brain_Path_Cell) 6 | i 7 | Regression_W_Sig_ForSGE(w_Brain_Path_Cell{i}, Rand_w_Brain_Path_Cell_Path); 8 | end -------------------------------------------------------------------------------- /SVR/Regression_W_Sig_MaximumStatistics.m: -------------------------------------------------------------------------------- 1 | 2 | function w_Brain_PValue = Regression_W_Sig_MaximumStatistics(Real_w_Brain_Path, Rand_w_Brain_Path_Cell) 3 | 4 | Original_W = load(Real_w_Brain_Path); 5 | Original_w_Brain_Matrix = repmat(abs(Original_W.w_Brain), length(Rand_w_Brain_Path_Cell), 1); 6 | 7 | RandomQuantity = length(Rand_w_Brain_Path_Cell); 8 | w_Brain_PValue = zeros(1, length(Original_W.w_Brain)); 9 | for i = 1:RandomQuantity 10 | i 11 | Rand_W = load(Rand_w_Brain_Path_Cell{i}); 12 | Rand_W_Maximum(i) = max(abs(Rand_W.w_Brain)); 13 | end 14 | Rand_W_Maximum_Matrix = repmat(Rand_W_Maximum', 1, length(Original_W.w_Brain)); 15 | 16 | Compare_W = Rand_W_Maximum_Matrix - Original_w_Brain_Matrix; 17 | Compare_W(find(Compare_W >= 0)) = 1; 18 | Compare_W(find(Compare_W < 0)) = 0; 19 | Compare_W_Sum = sum(Compare_W); 20 | w_Brain_PValue = Compare_W_Sum / RandomQuantity; 21 | 22 | [ResultantFolder, ~, ~] = fileparts(Real_w_Brain_Path); 23 | save([ResultantFolder filesep 'w_Brain_PValue_MaximumStatistics.mat'], 'w_Brain_PValue'); -------------------------------------------------------------------------------- /SVR/Regression_W_Sig_SGE.m: -------------------------------------------------------------------------------- 1 | 2 | function Regression_W_Sig_SGE(w_Brain_Path_Cell, Rand_w_Brain_Path_Cell_Path, Queue) 3 | 4 | TaskQuantity = 100; 5 | JobsPerTask = fix(length(w_Brain_Path_Cell) / TaskQuantity); 6 | JobsRemain = mod(length(w_Brain_Path_Cell), TaskQuantity * JobsPerTask); 7 | 8 | for i = 1:100 9 | w_Brain_Path_Cell_Sub = w_Brain_Path_Cell([(i - 1) * JobsPerTask + 1 : i * JobsPerTask]); 10 | if i == 100 & JobsRemain 11 | w_Brain_Path_Cell_Sub = [w_Brain_Path_Cell_Sub; w_Brain_Path_Cell_Sub(length(Perm_times_Range) - JobsRemain + 1 : end)]; 12 | end 13 | Job_Name = ['perm_w2p_' num2str(i)]; 14 | pipeline.(Job_Name).command = 'Regression_W_Sig_ForSGE_parent(opt.para1, opt.para2)'; 15 | pipeline.(Job_Name).opt.para1 = w_Brain_Path_Cell_Sub; 16 | pipeline.(Job_Name).opt.para2 = Rand_w_Brain_Path_Cell_Path; 17 | end 18 | 19 | Pipeline_opt.mode = 'qsub'; 20 | Pipeline_opt.qsub_options = Queue; 21 | Pipeline_opt.mode_pipeline_manager = 'batch'; 22 | Pipeline_opt.max_queued = 100; 23 | Pipeline_opt.flag_verbose = 1; 24 | Pipeline_opt.flag_pause = 0; 25 | Pipeline_opt.flag_update = 1; 26 | Pipeline_opt.path_logs = [pwd filesep 'logs']; 27 | 28 | psom_run_pipeline(pipeline,Pipeline_opt); 29 | -------------------------------------------------------------------------------- /SVR/SVR.m~: -------------------------------------------------------------------------------- 1 | function [Accuracy Sensitivity Specificity Category] = SVR(Subjects_Data, Subjects_Scores, Pre_Method, ResultantFolder) 2 | % 3 | % Subject_Data: 4 | % m*n matrix 5 | % m is the number of subjects 6 | % n is the number of features 7 | % 8 | % Subject_Scores: 9 | % the continuous variable to be predicted 10 | % 11 | % Pre_Method: 12 | % 'Normalize' or 'Scale' 13 | % 14 | % ResultantFolder: 15 | % the path of folder storing resultant files 16 | % 17 | 18 | if nargin >= 4 19 | if ~exist(ResultantFolder, 'dir') 20 | mkdir(ResultantFolder); 21 | end 22 | end 23 | 24 | [Subjects_Quantity Feature_Quantity] = size(Subjects_Data); 25 | 26 | for i = 1:Subjects_Quantity 27 | 28 | disp(['The ' num2str(i) ' iteration!']); 29 | 30 | Training_all_data = Subjects_Data; 31 | Training_all_scores = Subjects_Scores; 32 | 33 | % Select training data and testing data 34 | test_data = Training_all_data(i, :); 35 | test_score = Training_all_scores(i); 36 | Training_all_data(i, :) = []; 37 | Training_all_scores(i) = []; 38 | 39 | if strcmp(Pre_Method, 'Normalize') 40 | %Normalizing 41 | MeanValue = mean(Training_all_data); 42 | StandardDeviation = std(Training_all_data); 43 | [rows, columns_quantity] = size(Training_all_data); 44 | for j = 1:columns_quantity 45 | Training_all_data(:, j) = (Training_all_data(:, j) - MeanValue(j)) / StandardDeviation(j); 46 | end 47 | elseif strcmp(Pre_Method, 'Scale') 48 | % Scaling to [0 1] 49 | MinValue = min(Training_all_data); 50 | MaxValue = max(Training_all_data); 51 | [rows, columns_quantity] = size(Training_all_data); 52 | for j = 1:columns_quantity 53 | Training_all_data(:, j) = (Training_all_data(:, j) - MinValue(j)) / (MaxValue(j) - MinValue(j)); 54 | end 55 | end 56 | 57 | % SVR training 58 | Training_all_scores = Training_all_scores'; 59 | Training_all_data = double(Training_all_data); 60 | model(i) = svmtrain(Training_all_Label, Training_all_data,'-s 3 -t 0'); 61 | 62 | if strcmp(Pre_Method, 'Normalize') 63 | % Normalizing 64 | test_data = (test_data - MeanValue) ./ StandardDeviation; 65 | elseif strcmp(Pre_Method, 'Scale') 66 | % Scale 67 | test_data = (test_data - MinValue) ./ (MaxValue - MinValue); 68 | end 69 | 70 | % predicts 71 | test_data = double(test_data); 72 | [predicted_score(i), accuracy, tmp] = svmpredict(test_score, test_data, model(i)); 73 | 74 | w{i} = zeros(1, Feature_Quantity); 75 | for j = 1 : model(i).totalSV 76 | w{i} = w{i} + model(i).sv_coef(j) * model(i).SVs(j, :); 77 | end 78 | decision_values(i) = w{i} * test_data' - model(i).rho; 79 | Distance_svm(i) = decision_values(i) / norm(w{i}); 80 | 81 | end 82 | 83 | Group1_Index = find(Subjects_Label == 1); 84 | Group0_Index = find(Subjects_Label == -1); 85 | Category_group1 = predicted_labels(Group1_Index); 86 | Y_group1 = decision_values(Group1_Index); 87 | Category_group0 = predicted_labels(Group0_Index); 88 | Y_group0 = decision_values(Group0_Index); 89 | % Calculating distance for svm 90 | Dis_group1_svm = Distance_svm(Group1_Index); 91 | Dis_group0_svm = Distance_svm(Group0_Index); 92 | save([ResultantFolder filesep 'Dis_svm.mat'], 'Dis_group1_svm', 'Dis_group0_svm'); 93 | 94 | if nargin >= 4 95 | save([ResultantFolder filesep 'Y.mat'], 'Y_group1', 'Y_group0'); 96 | save([ResultantFolder filesep 'Category.mat'], 'Category_group1', 'Category_group0'); 97 | end 98 | 99 | Category.Category_group0 = Category_group0; 100 | Category.Category_group1 = Category_group1; 101 | 102 | group0_Wrong_ID = find(Category_group0 == 1); 103 | group0_Wrong_Quantity = length(group0_Wrong_ID); 104 | group1_Wrong_ID = find(Category_group1 == -1); 105 | group1_Wrong_Quantity = length(group1_Wrong_ID); 106 | 107 | Accuracy = (Subjects_Quantity - group0_Wrong_Quantity - group1_Wrong_Quantity) / Subjects_Quantity; 108 | Sensitivity = (length(Group0_Index) - group0_Wrong_Quantity) / length(Group0_Index); 109 | Specificity = (length(Group1_Index) - group1_Wrong_Quantity) / length(Group1_Index); 110 | 111 | if nargin >= 4 112 | disp(['group0: ' num2str(group0_Wrong_Quantity) ' subjects are wrong ' mat2str(group0_Wrong_ID) ]); 113 | disp(['group1: ' num2str(group1_Wrong_Quantity) ' subjects are wrong ' mat2str(group1_Wrong_ID) ]); 114 | save([ResultantFolder filesep 'WrongInfo.mat'], 'group0_Wrong_Quantity', 'group0_Wrong_ID', 'group1_Wrong_Quantity', 'group1_Wrong_ID'); 115 | disp(['Accuracy is ' num2str(Accuracy) ' !']); 116 | save([ResultantFolder filesep 'Accuracy.mat'], 'Accuracy'); 117 | disp(['Sensitivity is ' num2str(Sensitivity) ' !']); 118 | save([ResultantFolder filesep 'Sensitivity.mat'], 'Sensitivity'); 119 | disp(['Specificity is ' num2str(Specificity) ' !']); 120 | save([ResultantFolder filesep 'Specificity.mat'], 'Specificity'); 121 | PPV = length(find(Category_group0 == -1)) / length(find([Category_group0 Category_group1] == -1)); 122 | save([ResultantFolder filesep 'PPV.mat'], 'PPV'); 123 | NPV = length(find(Category_group1 == 1)) / length(find([Category_group0 Category_group1] == 1)); 124 | save([ResultantFolder filesep 'NPV.mat'], 'NPV'); 125 | 126 | % Calculating w 127 | W_Calculate_SVM(Subjects_Data, Subjects_Label, Pre_Method, ResultantFolder); 128 | end -------------------------------------------------------------------------------- /SVR/SVR_LOOCV.m: -------------------------------------------------------------------------------- 1 | function Prediction = SVR_LOOCV(Subjects_Data, Subjects_Scores, Covariates, Pre_Method, ResultantFolder) 2 | % 3 | % Subject_Data: 4 | % m*n matrix 5 | % m is the number of subjects 6 | % n is the number of features 7 | % 8 | % Subject_Scores: 9 | % the continuous variable to be predicted, [1*m] 10 | % 11 | % Covariates: 12 | % m*n matrix 13 | % m is the number of subjects 14 | % n is the number of covariates 15 | % 16 | % Pre_Method: 17 | % 'Normalize', 'Scale', 'None' 18 | % 19 | % ResultantFolder: 20 | % the path of folder storing resultant files 21 | % 22 | 23 | if nargin >= 5 24 | if ~exist(ResultantFolder, 'dir') 25 | mkdir(ResultantFolder); 26 | end 27 | end 28 | 29 | [Subjects_Quantity, Feature_Quantity] = size(Subjects_Data); 30 | 31 | for i = 1:Subjects_Quantity 32 | 33 | disp(['The ' num2str(i) ' subject!']); 34 | 35 | Training_data = Subjects_Data; 36 | Training_scores = Subjects_Scores; 37 | 38 | % Select training data and testing data 39 | test_data = Training_data(i, :); 40 | test_score = Training_scores(i); 41 | Training_data(i, :) = []; 42 | Training_scores(i) = []; 43 | 44 | if ~isempty(Covariates) 45 | Covariates_test = Covariates(i, :); 46 | Covariates_training = Covariates; 47 | Covariates_training(i, :) = []; 48 | [Training_quantity, Covariates_quantity] = size(Covariates_training); 49 | M = 1; 50 | for j = 1:Covariates_quantity 51 | M = M + term(Covariates_training(:, j)); 52 | end 53 | slm = SurfStatLinMod(Training_data, M); 54 | 55 | Training_data = Training_data - repmat(slm.coef(1, :), Training_quantity, 1); 56 | for j = 1:Covariates_quantity 57 | Training_data = Training_data - ... 58 | repmat(Covariates_training(:, j), 1, Feature_Quantity) .* repmat(slm.coef(j + 1, :), Training_quantity, 1); 59 | end 60 | end 61 | 62 | if strcmp(Pre_Method, 'Normalize') 63 | %Normalizing 64 | MeanValue = mean(Training_data); 65 | StandardDeviation = std(Training_data); 66 | [~, columns_quantity] = size(Training_data); 67 | for j = 1:columns_quantity 68 | Training_data(:, j) = (Training_data(:, j) - MeanValue(j)) / StandardDeviation(j); 69 | end 70 | elseif strcmp(Pre_Method, 'Scale') 71 | % Scaling to [0 1] 72 | MinValue = min(Training_data); 73 | MaxValue = max(Training_data); 74 | [~, columns_quantity] = size(Training_data); 75 | for j = 1:columns_quantity 76 | Training_data(:, j) = (Training_data(:, j) - MinValue(j)) / (MaxValue(j) - MinValue(j)); 77 | end 78 | end 79 | 80 | % SVR training 81 | Training_scores = Training_scores'; 82 | Training_data_final = double(Training_data); 83 | model = svmtrain(Training_scores, Training_data_final,'-s 3 -t 0'); 84 | 85 | % Covariate test data 86 | if ~isempty(Covariates) 87 | test_data = test_data - slm.coef(1, :); 88 | for j = 1:Covariates_quantity 89 | test_data = test_data - repmat(Covariates_test(j), 1, Feature_Quantity) .* slm.coef(j + 1, :); 90 | end 91 | end 92 | % Normalize test data 93 | if strcmp(Pre_Method, 'Normalize') 94 | % Normalizing 95 | test_data = (test_data - MeanValue) ./ StandardDeviation; 96 | elseif strcmp(Pre_Method, 'Scale') 97 | % Scale 98 | test_data = (test_data - MinValue) ./ (MaxValue - MinValue); 99 | end 100 | test_data_final = double(test_data); 101 | % predict test data 102 | [Predicted_Scores(i), ~, ~] = svmpredict(test_score, test_data_final, model); 103 | 104 | end 105 | 106 | Prediction.Score = Predicted_Scores; 107 | [Prediction.Corr, ~] = corr(Predicted_Scores', Subjects_Scores'); 108 | Prediction.MAE = mean(abs((Predicted_Scores - Subjects_Scores))); 109 | 110 | if nargin >= 5 111 | save([ResultantFolder filesep 'Prediction_res.mat'], 'Prediction'); 112 | disp(['The correlation is ' num2str(Prediction.Corr)]); 113 | disp(['The MAE is ' num2str(Prediction.MAE)]); 114 | % Calculating w 115 | W_Calculate_SVR(Subjects_Data, Subjects_Scores, Covariates, Pre_Method, ResultantFolder); 116 | end -------------------------------------------------------------------------------- /SVR/SVR_LOOCV_ForSGE.m: -------------------------------------------------------------------------------- 1 | 2 | function SVR_LOOCV_ForSGE(Subjects_Data_Path, Subjects_Scores, ResultantFolder) 3 | 4 | Subjects_Data = load(Subjects_Data_Path); 5 | FieldName = fieldnames(Subjects_Data); 6 | SVR_LOOCV(Subjects_Data.(FieldName{1}), Subjects_Scores, [], ResultantFolder); -------------------------------------------------------------------------------- /SVR/SVR_NFolds.m: -------------------------------------------------------------------------------- 1 | function Prediction = SVR_NFolds(Subjects_Data, Subjects_Scores, Covariates, FoldQuantity, Pre_Method, ResultantFolder) 2 | % 3 | % Subject_Data: 4 | % m*n matrix 5 | % m is the number of subjects 6 | % n is the number of features 7 | % 8 | % Subject_Scores: 9 | % the continuous variable to be predicted 10 | % 11 | % Covariates: 12 | % m*n matrix 13 | % m is the number of subjects 14 | % n is the number of covariates 15 | % 16 | % FoldQuantity: 17 | % The quantity of folds, 10 is recommended 18 | % 19 | % Pre_Method: 20 | % 'Normalize', 'Scale', 'None' 21 | % 22 | % ResultantFolder: 23 | % the path of folder storing resultant files 24 | % 25 | 26 | if nargin >= 6 27 | if ~exist(ResultantFolder, 'dir') 28 | mkdir(ResultantFolder); 29 | end 30 | end 31 | 32 | [Subjects_Quantity, Features_Quantity] = size(Subjects_Data); 33 | 34 | % Split into N folds randomly 35 | EachPart_Quantity = fix(Subjects_Quantity / FoldQuantity); 36 | RandID = randperm(Subjects_Quantity); 37 | for j = 1:FoldQuantity 38 | Origin_ID{j} = RandID([(j - 1) * EachPart_Quantity + 1: j * EachPart_Quantity])'; 39 | end 40 | Reamin = mod(Subjects_Quantity, FoldQuantity); 41 | for j = 1:Reamin 42 | Origin_ID{j} = [Origin_ID{j} ; RandID(FoldQuantity * EachPart_Quantity + j)]; 43 | end 44 | 45 | for j = 1:FoldQuantity 46 | 47 | disp(['The ' num2str(j) ' fold!']); 48 | 49 | Training_data = Subjects_Data; 50 | Training_scores = Subjects_Scores; 51 | 52 | % Select training data and testing data 53 | test_data = Training_data(Origin_ID{j}, :); 54 | test_score = Training_scores(Origin_ID{j})'; 55 | Training_data(Origin_ID{j}, :) = []; 56 | Training_scores(Origin_ID{j}) = []; 57 | 58 | if ~isempty(Covariates) 59 | Covariates_test = Covariates(Origin_ID{j}, :); 60 | Covariates_training = Covariates; 61 | Covariates_training(Origin_ID{j}, :) = []; 62 | [Training_quantity, Covariates_quantity] = size(Covariates_training); 63 | M = 1; 64 | for k = 1:Covariates_quantity 65 | M = M + term(Covariates_training(:, k)); 66 | end 67 | slm = SurfStatLinMod(Training_data, M); 68 | 69 | Training_data = Training_data - repmat(slm.coef(1, :), Training_quantity, 1); 70 | for k = 1:Covariates_quantity 71 | Training_data = Training_data - ... 72 | repmat(Covariates_training(:, k), 1, Feature_Quantity) .* repmat(slm.coef(k + 1, :), Training_quantity, 1); 73 | end 74 | end 75 | 76 | if strcmp(Pre_Method, 'Normalize') 77 | % Normalizing 78 | MeanValue = mean(Training_data); 79 | StandardDeviation = std(Training_data); 80 | [~, columns_quantity] = size(Training_data); 81 | for k = 1:columns_quantity 82 | Training_data(:, k) = (Training_data(:, k) - MeanValue(k)) / StandardDeviation(k); 83 | end 84 | elseif strcmp(Pre_Method, 'Scale') 85 | % Scaling to [0 1] 86 | MinValue = min(Training_data); 87 | MaxValue = max(Training_data); 88 | [~, columns_quantity] = size(Training_data); 89 | for k = 1:columns_quantity 90 | Training_data(:, k) = (Training_data(:, k) - MinValue(k)) / (MaxValue(k) - MinValue(k)); 91 | end 92 | end 93 | 94 | % SVR training 95 | Training_scores = Training_scores'; 96 | Training_data_final = double(Training_data); 97 | model = svmtrain(Training_scores, Training_data_final,'-s 3 -t 0'); 98 | 99 | % Covariate test data 100 | if ~isempty(Covariates) 101 | [test_quantity, ~] = sieze(test_data); 102 | test_data = test_data - repmat(slm.coef(1, :), test_quantity, 1); 103 | for k = 1:Covariates_quantity 104 | test_data = test_data - ... 105 | repmat(Covariates_test(:, k), 1, Feature_Quantity) .* repmat(slm.coef(k + 1, :), test_quantity, 1); 106 | end 107 | end 108 | % Normalize test data 109 | if strcmp(Pre_Method, 'Normalize') 110 | % Normalizing 111 | MeanValue_New = repmat(MeanValue, length(test_score), 1); 112 | StandardDeviation_New = repmat(StandardDeviation, length(test_score), 1); 113 | test_data = (test_data - MeanValue_New) ./ StandardDeviation_New; 114 | elseif strcmp(Pre_Method, 'Scale') 115 | % Scale 116 | MaxValue_New = repmat(MaxValue, length(test_score), 1); 117 | MinValue_New = repmat(MinValue, length(test_score), 1); 118 | test_data = (test_data - MinValue_New) ./ (MaxValue_New - MinValue_New); 119 | end 120 | test_data_final = double(test_data); 121 | % Predict test data 122 | [Predicted_Scores, ~, ~] = svmpredict(test_score, test_data_final, model); 123 | Prediction.Origin_ID{j} = Origin_ID{j}; 124 | Prediction.Score{j} = Predicted_Scores; 125 | Prediction.Corr(j) = corr(Predicted_Scores, test_score); 126 | Prediction.MAE(j) = mean(abs(Predicted_Scores - test_score)); 127 | 128 | end 129 | 130 | Prediction.Mean_Corr = mean(Prediction.Corr); 131 | Prediction.Mean_MAE = mean(Prediction.MAE); 132 | if nargin >= 6 133 | save([ResultantFolder filesep 'Prediction.mat'], 'Prediction'); 134 | disp(['The correlation is ' num2str(Prediction.Mean_Corr)]); 135 | disp(['The MAE is ' num2str(Prediction.Mean_MAE)]); 136 | % Calculating w 137 | W_Calculate_SVR(Subjects_Data, Subjects_Scores, Covariates, Pre_Method, ResultantFolder); 138 | end 139 | -------------------------------------------------------------------------------- /SVR/SVR_NFolds_Avg.m: -------------------------------------------------------------------------------- 1 | function [Prediction w_Brain] = SVR_NFolds_Avg(Prediction_Cell, ResultantFolder) 2 | % 3 | % Prediction_Cell: 4 | % Cell of path of .mat file 5 | % .mat file with variable name 'Prediction' 6 | % Prediction.Corr 7 | % Prediction.MAE 8 | % Prediction.w_Brain 9 | % 10 | 11 | Tmp = load(Prediction_Cell{1}); 12 | Corr = Tmp.Prediction.Corr; 13 | MAE = Tmp.Prediction.MAE; 14 | w_Brain = Tmp.Prediction.w_Brain; 15 | 16 | for i = 2:length(Prediction_Cell) 17 | Tmp = load(Prediction_Cell{i}); 18 | Corr = Corr + Tmp.Prediction.Corr; 19 | MAE = MAE + Tmp.Prediction.MAE; 20 | w_Brain = w_Brain + Tmp.Prediction.w_Brain; 21 | end 22 | 23 | Prediction.Corr = Corr / length(Prediction_Cell); 24 | Prediction.MAE = MAE / length(Prediction_Cell); 25 | w_Brain = w_Brain / length(Prediction_Cell); 26 | save([ResultantFolder filesep 'Prediction.mat'], 'Prediction'); 27 | save([ResultantFolder filesep 'w_Brain.mat'], 'w_Brain'); 28 | 29 | 30 | -------------------------------------------------------------------------------- /SVR/SVR_NFolds_ForSGE.m: -------------------------------------------------------------------------------- 1 | function SVR_NFolds_ForSGE(Subjects_Data_Path, Subjects_Scores, Covariates, FoldQuantity, ResultantFolder) 2 | % 3 | % Subject_Data: 4 | % m*n matrix 5 | % m is the number of subjects 6 | % n is the number of features 7 | % 8 | % Subject_Scores: 9 | % the continuous variable to be predicted 10 | % 11 | % ResultantFolder: 12 | % the path of folder storing resultant files 13 | % 14 | % Covariates: 15 | % m*n matrix 16 | % m is the number of subjects 17 | % n is the number of covariates 18 | % 19 | % SplitTimes: 20 | % The times for split half 21 | % 22 | 23 | ImgData = load(Subjects_Data_Path); 24 | FieldName = fieldnames(ImgData); 25 | 26 | SVR_NFolds(ImgData.(FieldName{1}), Subjects_Scores, Covariates, FoldQuantity, ResultantFolder); -------------------------------------------------------------------------------- /SVR/SVR_NFolds_Repeat.m: -------------------------------------------------------------------------------- 1 | function Prediction = SVR_NFolds_Repeat(Subjects_Data_Path, Subjects_Scores, Covariates, FoldQuantity, RepetitionTimes, ResultantFolder, QsubOption) 2 | % 3 | % Subject_Data_Path: 4 | % The path of .mat file which contans m*n matrix 5 | % m is the number of subjects 6 | % n is the number of features 7 | % 8 | % Subject_Scores: 9 | % the continuous variable to be predicted 10 | % 11 | % ResultantFolder: 12 | % the path of folder storing resultant files 13 | % 14 | % Covariates: 15 | % m*n matrix 16 | % m is the number of subjects 17 | % n is the number of covariates 18 | % 19 | % SplitTimes: 20 | % The times for split half 21 | % 22 | % RepetitionTimes: 23 | % The repetition times for spliting N folds 24 | % 25 | 26 | if ~exist(ResultantFolder, 'dir') 27 | mkdir(ResultantFolder); 28 | end 29 | 30 | for i = 1:RepetitionTimes 31 | Sub_ResFolder = [ResultantFolder filesep 'EachTime/res_' num2str(i)]; 32 | mkdir(Sub_ResFolder); 33 | Job_Name = ['Repetition_' num2str(i)]; 34 | pipeline.(Job_Name).command = 'SVR_NFolds_ForSGE(opt.parameters1, opt.parameters2, opt.parameters3, opt.parameters4, opt.parameters5)'; 35 | pipeline.(Job_Name).opt.parameters1 = Subjects_Data_Path; 36 | pipeline.(Job_Name).opt.parameters2 = Subjects_Scores; 37 | pipeline.(Job_Name).opt.parameters3 = Covariates; 38 | pipeline.(Job_Name).opt.parameters4 = FoldQuantity; 39 | pipeline.(Job_Name).opt.parameters5 = Sub_ResFolder; 40 | pipeline.(Job_Name).files_out{1} = [Sub_ResFolder filesep 'Prediction.mat']; 41 | end 42 | 43 | Job_Name = ['Average']; 44 | pipeline.(Job_Name).command = 'SVR_NFolds_Avg(files_in, opt.parameter1)'; 45 | for i = 1:RepetitionTimes 46 | Job_Name_I = ['Repetition_' num2str(i)]; 47 | pipeline.(Job_Name).files_in{i} = pipeline.(Job_Name_I).files_out{1}; 48 | end 49 | pipeline.(Job_Name).opt.parameter1 = ResultantFolder; 50 | 51 | Pipeline_opt.mode = 'qsub'; 52 | Pipeline_opt.qsub_options = QsubOption; 53 | Pipeline_opt.mode_pipeline_manager = 'batch'; 54 | Pipeline_opt.max_queued = 200; 55 | Pipeline_opt.flag_verbose = 1; 56 | Pipeline_opt.flag_pause = 0; 57 | Pipeline_opt.flag_update = 1; 58 | Pipeline_opt.path_logs = [ResultantFolder filesep 'logs']; 59 | 60 | psom_run_pipeline(pipeline,Pipeline_opt); -------------------------------------------------------------------------------- /SVR/SVR_Permutation.m: -------------------------------------------------------------------------------- 1 | 2 | function SVR_Permutation(Data_Path, Score, Real_Prediction_Path, Perm_times_Range, ResultantFolder) 3 | 4 | for i = Perm_times_Range 5 | i 6 | Rand_Index = randperm(length(Score)); 7 | Rand_Score = Score(Rand_Index); 8 | ResultantFolder_Sub{i} = [ResultantFolder filesep 'time_' num2str(i)]; 9 | mkdir(ResultantFolder_Sub{i}); 10 | save([ResultantFolder_Sub{i} filesep 'Rand_Index.mat'], 'Rand_Index'); 11 | save([ResultantFolder_Sub{i} filesep 'Rand_Score.mat'], 'Rand_Score'); 12 | 13 | Job_Name = ['perm_' num2str(i)]; 14 | pipeline.(Job_Name).command = 'SVR_LOOCV_ForSGE(opt.para1, opt.para2, opt.para3)'; 15 | pipeline.(Job_Name).opt.para1 = Data_Path; 16 | pipeline.(Job_Name).opt.para2 = Rand_Score'; 17 | pipeline.(Job_Name).opt.para3 = ResultantFolder_Sub{i}; 18 | pipeline.(Job_Name).files_out.Rand_prediction = [ResultantFolder_Sub{i} filesep 'Prediction_res.mat']; 19 | pipeline.(Job_Name).files_out.w_Brain = [ResultantFolder_Sub{i} filesep 'w_Brain.mat']; 20 | 21 | end 22 | 23 | % Job_Name = ['Sig_test']; 24 | % for i = Perm_times_Range 25 | % Perm_JobName_I = ['perm_' num2str(i)]; 26 | % pipeline.(Job_Name).files_in.Rand_prediction{i} = pipeline.(Perm_JobName_I).files_out.Rand_prediction; 27 | % pipeline.(Job_Name).files_in.w_Brain{i} = pipeline.(Perm_JobName_I).files_out.w_Brain; 28 | % end 29 | % pipeline.(Job_Name).command = 'Regression_Prediction_Sig(opt.para1, files_in.Rand_prediction)'; 30 | % pipeline.(Job_Name).opt.para1 = Real_Prediction_Path; 31 | 32 | Pipeline_opt.mode = 'qsub'; 33 | Pipeline_opt.qsub_options = '-q veryshort.q'; 34 | Pipeline_opt.mode_pipeline_manager = 'batch'; 35 | Pipeline_opt.max_queued = 200; 36 | Pipeline_opt.flag_verbose = 1; 37 | Pipeline_opt.flag_pause = 0; 38 | Pipeline_opt.flag_update = 1; 39 | Pipeline_opt.path_logs = [ResultantFolder filesep 'logs']; 40 | 41 | psom_run_pipeline(pipeline,Pipeline_opt); 42 | 43 | 44 | -------------------------------------------------------------------------------- /SVR/SVR_W_Permutation.m: -------------------------------------------------------------------------------- 1 | 2 | function SVR_W_Permutation(Data_Path, Scores, Perm_times_Range, ResultantFolder, Queue) 3 | 4 | TaskQuantity = 100; 5 | JobsPerTask = fix(length(Perm_times_Range) / TaskQuantity); 6 | JobsRemain = mod(length(Perm_times_Range), TaskQuantity * JobsPerTask); 7 | 8 | mkdir([ResultantFolder filesep 'rand_perm']); 9 | 10 | for i = 1:100 11 | i 12 | 13 | ID = Perm_times_Range([(i - 1) * JobsPerTask + 1 : i * JobsPerTask]); 14 | if i == 100 & JobsRemain 15 | ID = [ID Perm_times_Range(length(Perm_times_Range) - JobsRemain + 1 : end)]; 16 | end 17 | for j = 1:length(ID) 18 | Rand_Index = randperm(length(Scores)); 19 | Rand_Score{j} = Scores(Rand_Index)'; 20 | end 21 | 22 | save([ResultantFolder filesep 'rand_perm' filesep 'rand_perm_' num2str(i) '.mat'], 'Rand_Score'); 23 | Job_Name = ['perm_W_' num2str(i)]; 24 | pipeline.(Job_Name).command = 'W_Calculate_SVR_SGE(opt.para1, opt.para2, opt.para3, opt.para4)'; 25 | pipeline.(Job_Name).opt.para1 = Data_Path; 26 | pipeline.(Job_Name).opt.para2 = Rand_Score; 27 | pipeline.(Job_Name).opt.para3 = ID; 28 | pipeline.(Job_Name).opt.para4 = ResultantFolder; 29 | clear Rand_Score; 30 | end 31 | 32 | Pipeline_opt.mode = 'qsub'; 33 | Pipeline_opt.qsub_options = Queue; 34 | Pipeline_opt.mode_pipeline_manager = 'batch'; 35 | Pipeline_opt.max_queued = 200; 36 | Pipeline_opt.flag_verbose = 1; 37 | Pipeline_opt.flag_pause = 0; 38 | Pipeline_opt.flag_update = 1; 39 | Pipeline_opt.path_logs = [ResultantFolder filesep 'logs']; 40 | 41 | psom_run_pipeline(pipeline,Pipeline_opt); 42 | 43 | 44 | -------------------------------------------------------------------------------- /SVR/SVR_W_Permutation_2.m: -------------------------------------------------------------------------------- 1 | 2 | function SVR_W_Permutation_2(Data_Path, Score, Perm_times_Range, ResultantFolder, Queue) 3 | 4 | for i = Perm_times_Range 5 | i 6 | Job_Name = ['perm_' num2str(i)]; 7 | pipeline.(Job_Name).command = 'W_Calculate_SVR_SGE_2(opt.para1, opt.para2, opt.para3, opt.para4)'; 8 | pipeline.(Job_Name).opt.para1 = Data_Path; 9 | pipeline.(Job_Name).opt.para2 = Score'; 10 | pipeline.(Job_Name).opt.para3 = i; 11 | pipeline.(Job_Name).opt.para4 = ResultantFolder; 12 | 13 | end 14 | 15 | Pipeline_opt.mode = 'qsub'; 16 | Pipeline_opt.qsub_options = Queue; 17 | Pipeline_opt.mode_pipeline_manager = 'batch'; 18 | Pipeline_opt.max_queued = 100; 19 | Pipeline_opt.flag_verbose = 1; 20 | Pipeline_opt.flag_pause = 0; 21 | Pipeline_opt.flag_update = 1; 22 | Pipeline_opt.path_logs = [ResultantFolder filesep 'logs']; 23 | 24 | psom_run_pipeline(pipeline,Pipeline_opt); 25 | 26 | 27 | -------------------------------------------------------------------------------- /SVR/SVR_W_Permutation_3.m: -------------------------------------------------------------------------------- 1 | 2 | function SVR_W_Permutation_3(Data_Path, Scores, Perm_times_Range, ResultantFolder, Queue) 3 | 4 | for i =Perm_times_Range 5 | i 6 | Rand_Index = randperm(length(Scores)); 7 | Rand_Scores = Scores(Rand_Index); 8 | Job_Name = ['perm_' num2str(i)]; 9 | pipeline.(Job_Name).command = 'W_Calculate_SVR_SGE_3(opt.para1, opt.para2, opt.para3, opt.para4)'; 10 | pipeline.(Job_Name).opt.para1 = Data_Path; 11 | pipeline.(Job_Name).opt.para2 = Rand_Scores'; 12 | pipeline.(Job_Name).opt.para3 = i; 13 | pipeline.(Job_Name).opt.para4 = ResultantFolder; 14 | 15 | end 16 | 17 | Pipeline_opt.mode = 'qsub'; 18 | Pipeline_opt.qsub_options = Queue; 19 | Pipeline_opt.mode_pipeline_manager = 'batch'; 20 | Pipeline_opt.max_queued = 100; 21 | Pipeline_opt.flag_verbose = 1; 22 | Pipeline_opt.flag_pause = 0; 23 | Pipeline_opt.flag_update = 1; 24 | Pipeline_opt.path_logs = [ResultantFolder filesep 'logs']; 25 | 26 | psom_run_pipeline(pipeline,Pipeline_opt); 27 | 28 | 29 | -------------------------------------------------------------------------------- /SVR/SVR_W_Permutation_4.m: -------------------------------------------------------------------------------- 1 | 2 | function SVR_W_Permutation_4(Data_Path, Scores, Perm_times_Range, ResultantFolder, Queue) 3 | 4 | for i = Perm_times_Range 5 | i 6 | Rand_Index = randperm(length(Scores)); 7 | Rand_Scores(i, :) = Scores(Rand_Index); 8 | end 9 | for i =Perm_times_Range 10 | i 11 | Job_Name = ['perm_' num2str(i)]; 12 | pipeline.(Job_Name).command = 'W_Calculate_SVR_SGE_3(opt.para1, opt.para2, opt.para3, opt.para4)'; 13 | pipeline.(Job_Name).opt.para1 = Data_Path; 14 | pipeline.(Job_Name).opt.para2 = Rand_Scores(i, :); 15 | pipeline.(Job_Name).opt.para3 = i; 16 | pipeline.(Job_Name).opt.para4 = ResultantFolder; 17 | 18 | end 19 | 20 | Pipeline_opt.mode = 'qsub'; 21 | Pipeline_opt.qsub_options = Queue; 22 | Pipeline_opt.mode_pipeline_manager = 'batch'; 23 | Pipeline_opt.max_queued = 100; 24 | Pipeline_opt.flag_verbose = 1; 25 | Pipeline_opt.flag_pause = 0; 26 | Pipeline_opt.flag_update = 1; 27 | Pipeline_opt.path_logs = [ResultantFolder filesep 'logs']; 28 | 29 | psom_run_pipeline(pipeline,Pipeline_opt); 30 | 31 | 32 | -------------------------------------------------------------------------------- /SVR/W_Calculate_SVR.m: -------------------------------------------------------------------------------- 1 | 2 | function [w_Brain, model_All] = W_Calculate_SVR(Subjects_Data, Subjects_Scores, Covariates, Pre_Method, ResultantFolder) 3 | % 4 | % Subject_Data: 5 | % m*n matrix 6 | % m is the number of subjects 7 | % n is the number of features 8 | % 9 | % Subject_Scores: 10 | % the continuous variable to be predicted,[1*m] 11 | % 12 | % Covariates: 13 | % m*n matrix 14 | % m is the number of subjects 15 | % n is the number of covariates 16 | % 17 | % Pre_Method: 18 | % 'Normalize', 'Scale', 'None' 19 | % 20 | % ResultantFolder: 21 | % the path of folder storing resultant files 22 | % 23 | 24 | if nargin >= 3 25 | if ~exist(ResultantFolder, 'dir') 26 | mkdir(ResultantFolder); 27 | end 28 | end 29 | 30 | [Subjects_Quantity, Features_Quantity] = size(Subjects_Data); 31 | 32 | if ~isempty(Covariates) 33 | [~, Covariates_quantity] = size(Covariates); 34 | M = 1; 35 | for j = 1:Covariates_quantity 36 | M = M + term(Covariates(:, j)); 37 | end 38 | slm = SurfStatLinMod(Subjects_Data, M); 39 | 40 | Subjects_Data = Subjects_Data - repmat(slm.coef(1, :), Subjects_Quantity, 1); 41 | for j = 1:Covariates_quantity 42 | Subjects_Data = Subjects_Data - ... 43 | repmat(Covariates(:, j), 1, Features_Quantity) .* repmat(slm.coef(j + 1, :), Subjects_Quantity, 1); 44 | end 45 | end 46 | 47 | if strcmp(Pre_Method, 'Normalize') 48 | %Normalizing 49 | MeanValue = mean(Subjects_Data); 50 | StandardDeviation = std(Subjects_Data); 51 | [~, columns_quantity] = size(Subjects_Data); 52 | for j = 1:columns_quantity 53 | Subjects_Data(:, j) = (Subjects_Data(:, j) - MeanValue(j)) / StandardDeviation(j); 54 | end 55 | elseif strcmp(Pre_Method, 'Scale') 56 | % Scaling to [0 1] 57 | MinValue = min(Subjects_Data); 58 | MaxValue = max(Subjects_Data); 59 | [~, columns_quantity] = size(Subjects_Data); 60 | for j = 1:columns_quantity 61 | Subjects_Data(:, j) = (Subjects_Data(:, j) - MinValue(j)) / (MaxValue(j) - MinValue(j)); 62 | end 63 | end 64 | 65 | % SVR 66 | Subjects_Scores = Subjects_Scores'; 67 | Subjects_Data = double(Subjects_Data); 68 | model_All = svmtrain(Subjects_Scores, Subjects_Data,'-s 3 -t 0'); 69 | w_Brain = zeros(1, Features_Quantity); 70 | for j = 1 : model_All.totalSV 71 | w_Brain = w_Brain + model_All.sv_coef(j) * model_All.SVs(j, :); 72 | end 73 | 74 | w_Brain = w_Brain / norm(w_Brain); 75 | 76 | if nargin >= 5 77 | save([ResultantFolder filesep 'w_Brain.mat'], 'w_Brain'); 78 | end 79 | -------------------------------------------------------------------------------- /SVR/W_Calculate_SVR_SGE.m: -------------------------------------------------------------------------------- 1 | 2 | function W_Calculate_SVR_SGE(Subjects_Data_Path, Rand_Scores, ID, ResultantFolder) 3 | 4 | tmp = load(Subjects_Data_Path); 5 | FieldName = fieldnames(tmp); 6 | 7 | for i = 1:length(ID) 8 | disp(ID(i)); 9 | [w_Brain, ~] = W_Calculate_SVR(tmp.(FieldName{1}), Rand_Scores{i}); 10 | save([ResultantFolder filesep 'w_Brain_' num2str(ID(i)) '.mat'], 'w_Brain'); 11 | end -------------------------------------------------------------------------------- /SVR/W_Calculate_SVR_SGE_2.m: -------------------------------------------------------------------------------- 1 | 2 | function W_Calculate_SVR_SGE_2(Subjects_Data_Path, Subjects_Scores, i, ResultantFolder) 3 | 4 | tmp = load(Subjects_Data_Path); 5 | FieldName = fieldnames(tmp); 6 | Rand_Index = randperm(length(Subjects_Scores)); 7 | Rand_Scores = Subjects_Scores(Rand_Index); 8 | [w_Brain, ~] = W_Calculate_SVR(tmp.(FieldName{1}), Rand_Scores); 9 | save([ResultantFolder filesep 'w_Brain_' num2str(i) '.mat'], 'w_Brain'); -------------------------------------------------------------------------------- /SVR/W_Calculate_SVR_SGE_3.m: -------------------------------------------------------------------------------- 1 | 2 | function W_Calculate_SVR_SGE_3(Subjects_Data_Path, Subjects_Scores_rand, i, ResultantFolder) 3 | 4 | tmp = load(Subjects_Data_Path); 5 | FieldName = fieldnames(tmp); 6 | 7 | [w_Brain, ~] = W_Calculate_SVR(tmp.(FieldName{1}), Subjects_Scores_rand); 8 | save([ResultantFolder filesep 'w_Brain_' num2str(i) '.mat'], 'w_Brain'); --------------------------------------------------------------------------------