-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsp_gp_cluster_job.m
82 lines (71 loc) · 2.3 KB
/
sp_gp_cluster_job.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
82
function [NLML, DNLML, Hyp, Yhat, S2, Yhattr, S2tr] = sp_gp_cluster_job(hyp0,X,Y,opt,Xs)
ones(10)*ones(10); % stupid hack to get matlab to work properly
%# function covLIN
%# function covLINard
%# function covSEiso
%# function covSEard
%# function covMaternard
%# function covMaterniso
%# function covSum
%# function meanPoly
%# function meanLinear
%# function meanConst
%# function meanSum
%# function covGrid
%# function infGrid
%# function sp_infGrid
%# function sp_covMTL
T = size(Y,2); % number of tasks
% -----------------------------
% defaults
% -----------------------------
try opt.type2ml; catch, opt.type2ml = true; end
try opt.maxEval; catch, opt.maxEval = 100; end
try opt.debug; catch, opt.debug = false;end
% % this is a hack. It it is included here because of the anonymous function
% if any(regexp(func2str(opt.inf),'infGrid'))
% gopt.cg_maxit = 1000; gopt.cg_tol = 1e-3;
% opt.inf = @(varargin) infGrid(varargin{:},gopt);
% end
if iscell(opt.cov) && any(regexp(func2str(opt.cov{1}),'sp_covMTL'))
sp_covMTL('init', length(opt.hyp0.cov));
end
Hyp = zeros(T,length(unwrap(hyp0)));
NLML = zeros(T,1);
DNLML = zeros(length(unwrap(hyp0)),T);
if nargin > 4 && nargout > 2
N = size(X,1);
Ns = size(Xs,1);
Yhat = zeros(Ns,T);
S2 = zeros(Ns,T);
Yhattr = zeros(N,T);
S2tr = zeros(N,T);
end
for t = 1:T
if opt.debug; fprintf('processing case %d of %d ...\n',t,T); end
y = Y(:,t);
hyp = hyp0;
nlml = NaN;
if opt.type2ml
try
[hyp,nlml] = minimize(hyp, @gp, opt.maxEval, opt.inf, opt.mean, opt.cov, opt.lik, X, y);
catch
warning('Optimisation failed. Using default values');
end
end
if nargin > 4
[yhat, s2] = gp(hyp,opt.inf,opt.mean,opt.cov,opt.lik, X, y, Xs, zeros(Ns,1));
Yhat(:,t) = yhat;
S2(:,t) = s2;
if nargout > 5
[yhattr, s2tr] = gp(hyp,opt.inf,opt.mean,cov,opt.lik, X, y, X, zeros(N,1));
Yhattr(:,t) = yhattr;
S2tr(:,t) = s2tr;
end
else % just report marginal likelihood and derivatives
[nlml, dnlml] = gp(hyp,opt.inf,opt.mean,opt.cov,opt.lik, X, y);
DNLML(:,t) = unwrap(dnlml);
end
NLML(t) = min(nlml);
Hyp(t,:) = unwrap(hyp)';
end