|
1 |
| -function K = sp_covMTL(cov, M, hyp, x, z, i) |
| 1 | +function K = sp_covMTL(cov, param, hyp, x, z, i) |
2 | 2 |
|
3 | 3 | % MTL covariance function
|
4 | 4 | %
|
5 | 5 | % usage:
|
6 | 6 | % sp_covMTL('init', number_of_hyperparameters);
|
7 |
| -% sp_covMTL('initte', task_indicator_test); |
8 |
| -% sp_covMTL(input_covariance_function, task_indicator, ...); |
| 7 | +% sp_covMTL(input_covariance_function, task_indicator(s), ...); |
9 | 8 | %
|
10 |
| -% takes a vector of hyperparameters: |
| 9 | +% the task indicators can be specified either as matrix M (training) or as |
| 10 | +% a cell array {Mtr, Mte} (testing) |
| 11 | +% |
| 12 | +% this function requires a vector of hyperparameters: |
11 | 13 | % hyp = [ ell; covp ]
|
| 14 | +% |
12 | 15 | % where ell is the lower diagonal of L = chol(Kf)' and covp is a vector of
|
13 |
| -% parameters for the input covariance functions |
| 16 | +% parameters for the input covariance function (Kx) |
14 | 17 | %
|
15 | 18 | %_________________________________________________________________________
|
16 | 19 | % Copyright (C) A Marquand
|
17 | 20 |
|
18 | 21 | if nargin<2, error('Not enough parameters provided.'), end
|
19 | 22 |
|
20 | 23 | persistent Nhyp;
|
21 |
| -persistent Mte; |
| 24 | +%persistent Mte; |
22 | 25 |
|
23 |
| -if strcmp(cov,'init'), Nhyp = M; return; end |
24 |
| -if strcmp(cov,'inittest'), Mte = M; return; end |
| 26 | +if strcmp(cov,'init'), Nhyp = param; return; end |
| 27 | +%if strcmp(cov,'inittest'), Mte = M; return; end |
25 | 28 | if isempty(Nhyp), error('Covariance function not initialised.'); end
|
26 | 29 |
|
| 30 | +if iscell(param) |
| 31 | + M = param{1}; |
| 32 | +else |
| 33 | + M = param; |
| 34 | +end |
| 35 | + |
27 | 36 | if nargin<4, K = num2str(Nhyp); return; end % report number of parameters
|
28 | 37 | if nargin<5, z = []; end % make sure, z exists
|
29 | 38 | xeqz = numel(z)==0;
|
|
41 | 50 |
|
42 | 51 | % configure input kernel from input arguments
|
43 | 52 | if dg % kss
|
| 53 | + if iscell(param) && length(param) == 2 |
| 54 | + Mte = param{2}; |
| 55 | + else |
| 56 | + error('for diag mode, a cell array {M, Mtr} is required.'); |
| 57 | + end |
44 | 58 | Kx = feval(cov{:}, hyp((lmaxi+1):end), x);
|
45 | 59 | %K = (M*Kf*M').*Kx;
|
46 | 60 | K = (Mte*Kf*Mte').*Kx;
|
|
51 | 65 | Kx = dokron(Kx,M);
|
52 | 66 | K = (M*Kf*M').*Kx;
|
53 | 67 | else % Ks
|
54 |
| - if isempty(Mte) |
55 |
| - error('Covariance function not initialized for testing'); |
| 68 | + if iscell(param) && length(param) == 2 |
| 69 | + Mte = param{2}; |
| 70 | + else |
| 71 | + error('for prediction, a cell array {M, Mtr} is required.'); |
56 | 72 | end
|
57 | 73 | Kx = feval(cov{:}, hyp((lmaxi+1):end), x, z);
|
58 | 74 | %K = (Mte*Kf*M').*Kx;
|
|
0 commit comments