-
Notifications
You must be signed in to change notification settings - Fork 11
/
train.m
82 lines (61 loc) · 2.11 KB
/
train.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
%%
% TRAIN.m
%
% Author:
% Arno Solin, 2014
%
% License:
% This software is distributed under the GNU General Public License
% (version 3 or later); please refer to the file LICENSE.txt, included
% with the software, for details.
%
%%
% Load data (the TRAIN_DATA_PATH is specified in 'settings.m')
%
% Load labels
labels_train = dataset('file', ...
fullfile(TRAIN_DATA_PATH,'train_labels.csv'),'Delimiter',',');
% Load training FNC features from file into a dataset array variable
FNC_train = dataset('file', ...
fullfile(TRAIN_DATA_PATH,'train_FNC.csv'),'Delimiter',',');
% Load training SBM features from file into a dataset array variable
SBM_train = dataset('file', ...
fullfile(TRAIN_DATA_PATH,'train_SBM.csv'),'Delimiter',',');
%%
% Combine and normalize data
%
% Convert to y \in {-1,1},
% where Healthy Control => -1 and Schizophrenic Patient => 1
y = 2*double(labels_train.Class)-1;
% Normalize feature vectors by their standard deviations
x = [bsxfun(@rdivide,double(SBM_train(:,2:end)), ...
std(double(SBM_train(:,2:end)),[],1)) ...
bsxfun(@rdivide,double(FNC_train(:,2:end)), ...
std(double(FNC_train(:,2:end)),[],1))];
%%
% Train GP classifier
%
% Create likelihood function
lik = lik_probit();
% Set GP prior covariance structure
gpcf1 = gpcf_linear();
gpcf2 = gpcf_constant();
gpcf3 = gpcf_matern52('lengthScale',.01);
gpcf = gpcf_sum('cf',{gpcf1,gpcf2,gpcf3});
% Create the GP structure
gp = gp_set('lik', lik, 'cf', gpcf, 'jitterSigma2', 1e-9);
% Optimizer parameters for the Laplace approximation
opt = optimset('TolFun',1e-3,'TolX',1e-3,'Display','iter');
% Use the Laplace approximation for initialization
gp = gp_set(gp, 'latent_method', 'Laplace');
gp = gp_optim(gp,x,y,'opt',opt);
% Continue by MCMC
gp = gp_set(gp, 'latent_method', 'MCMC', 'jitterSigma2', 1e-6);
[gp_rec] = gp_mc(gp, x, y, 'nsamples', 1000, 'display', 20);
% Remove burn-in and thin
gp = thin(gp_rec,100,10);
%%
% Save model
%
% Write model to disk (MODEL_PATH specified in 'settings.m')
save(MODEL_PATH,'gp');