-
Notifications
You must be signed in to change notification settings - Fork 0
/
objectivefunc.m
49 lines (38 loc) · 1.24 KB
/
objectivefunc.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
function [ F f ] = objectivefunc(hyp)
global logML;
global marker;
load('parameters.mat');
[ K ] = covMultiClass(hyp, para, X, []);
[ model ] = LaplaceApproximation(hyp, para, K, X, y);
if isempty(model)
F = 1e3;
f = zeros(size(hyp));
return;
end
F = logMarginalLikelihood(hyp, para, model);
logML = [ logML, F ];
scrsz = get(0,'ScreenSize');
fig1 = figure(1);
set(fig1, 'Position',[1 scrsz(4) 500 400]);
subplot(1,3,1);
plot(1:length(hyp), exp(hyp), 'xb', 'MarkerSize', 12, 'LineWidth', 2);
title('hyper-paramethers');
figure(1);
subplot(1,3,2);
hold on;
if length(logML) > 1
plot(length(logML)-1:length(logML), -logML(end-1:end), marker, 'MarkerSize', 8, 'LineWidth', 2);
else
plot(1:length(logML), -logML, marker, 'MarkerSize', 8, 'LineWidth', 2);
end
title('The Log Marignal Likelihood');
% caculate gridient
if nargout > 1
f = logMarginalLikelihood(hyp, para, model, []);
figure(1);
subplot(1,3,3);
axis([0 4 -100 100]);
plot(1:length(f), f, 'r^', 'MarkerSize', 12, 'LineWidth', 2);
title('Gradient');
pause(0.01);
end