forked from lawrennd/gp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgpExtractParam.m
112 lines (107 loc) · 3.17 KB
/
gpExtractParam.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
function [params, names] = gpExtractParam(model)
% GPEXTRACTPARAM Extract a parameter vector from a GP model.
% FORMAT
% DESC extracts the model parameters from a structure containing
% the information about a Gaussian process.
% ARG model : the model structure containing the information about
% the model.
% RETURN params : a vector of parameters from the model.
%
% DESC does the same as above, but also returns parameter names.
% ARG model : the model structure containing the information about
% the model.
% RETURN params : a vector of parameters from the model.
% RETURN names : cell array of parameter names.
%
% SEEALSO : gpCreate, gpExpandParam, modelExtractParam
%
% COPYRIGHT : Neil D. Lawrence, 2005, 2006, 2007, 2009
% GP
if nargout > 1
returnNames = true;
else
returnNames = false;
end
% Check if the output scales are being learnt.
if model.learnScales
fhandle = str2func([model.scaleTransform 'Transform']);
scaleParams = fhandle(model.scale, 'xtoa');
if returnNames
for i = 1:length(scaleParams)
scaleParamNames{i} = ['Output Scale ' num2str(i)];
end
end
else
scaleParams = [];
scaleParamNames = {};
end
% Check if there is a mean function.
if isfield(model, 'meanFunction') && ~isempty(model.meanFunction)
if returnNames
[meanFuncParams, meanFuncParamNames] = modelExtractParam(model.meanFunction);
for i = 1:length(meanFuncParamNames)
meanFuncParamNames{i} = ['Mean Func, ' meanFuncParamNames{i}];
end
else
meanFuncParams = modelExtractParam(model.meanFunction);
end
else
meanFuncParamNames = {};
meanFuncParams =[];
end
if returnNames
[kernParams, kernParamNames] = kernExtractParam(model.kern);
for i = 1:length(kernParamNames)
kernParamNames{i} = ['Kernel, ' kernParamNames{i}];
end
else
kernParams = kernExtractParam(model.kern);
end
switch model.approx
case 'ftc'
params = [kernParams meanFuncParams scaleParams];
if returnNames
names = {kernParamNames{:}, meanFuncParamNames{:}, scaleParamNames{:}};
end
if model.optimiseBeta
fhandle = str2func([model.betaTransform 'Transform']);
betaParam = fhandle(model.beta, 'xtoa');
params = [params betaParam(:)'];
if returnNames
for i = 1:length(betaParam)
betaParamNames{i} = ['Beta ' num2str(i)];
end
names = {names{:}, betaParamNames{:}};
end
end
case {'dtc', 'dtcvar', 'fitc', 'pitc'}
paramPart = [kernParams meanFuncParams scaleParams];
if returnNames
names = {kernParamNames{:}, meanFuncParamNames{:}, ...
scaleParamNames{:}};
end
if model.optimiseBeta
fhandle = str2func([model.betaTransform 'Transform']);
betaParam = fhandle(model.beta, 'xtoa');
paramPart = [paramPart betaParam(:)'];
if returnNames
for i = 1:length(betaParam)
betaParamNames{i} = ['Beta ' num2str(i)];
end
names = {names{:}, betaParamNames{:}};
end
end
if model.fixInducing
params = paramPart;
else
params = [model.X_u(:)' paramPart];
if returnNames
for i = 1:size(model.X_u, 1)
for j = 1:size(model.X_u, 2)
X_uNames{i, j} = ['X_u(' num2str(i) ', ' num2str(j) ')'];
end
end
names = {X_uNames{:}, names{:}};
end
end
end