wolffd@0
|
1 function net = gpinit(net, tr_in, tr_targets, prior)
|
wolffd@0
|
2 %GPINIT Initialise Gaussian Process model.
|
wolffd@0
|
3 %
|
wolffd@0
|
4 % Description
|
wolffd@0
|
5 % NET = GPINIT(NET, TRIN, TRTARGETS) takes a Gaussian Process data
|
wolffd@0
|
6 % structure NET together with a matrix TRIN of training input vectors
|
wolffd@0
|
7 % and a matrix TRTARGETS of training target vectors, and stores them
|
wolffd@0
|
8 % in NET. These datasets are required if the corresponding inverse
|
wolffd@0
|
9 % covariance matrix is not supplied to GPFWD. This is important if the
|
wolffd@0
|
10 % data structure is saved and then reloaded before calling GPFWD. Each
|
wolffd@0
|
11 % row of TRIN corresponds to one input vector and each row of TRTARGETS
|
wolffd@0
|
12 % corresponds to one target vector.
|
wolffd@0
|
13 %
|
wolffd@0
|
14 % NET = GPINIT(NET, TRIN, TRTARGETS, PRIOR) additionally initialises
|
wolffd@0
|
15 % the parameters in NET from the PRIOR data structure which contains
|
wolffd@0
|
16 % the mean and variance of the Gaussian distribution which is sampled
|
wolffd@0
|
17 % from.
|
wolffd@0
|
18 %
|
wolffd@0
|
19 % See also
|
wolffd@0
|
20 % GP, GPFWD
|
wolffd@0
|
21 %
|
wolffd@0
|
22
|
wolffd@0
|
23 % Copyright (c) Ian T Nabney (1996-2001)
|
wolffd@0
|
24
|
wolffd@0
|
25 errstring = consist(net, 'gp', tr_in, tr_targets);
|
wolffd@0
|
26 if ~isempty(errstring);
|
wolffd@0
|
27 error(errstring);
|
wolffd@0
|
28 end
|
wolffd@0
|
29
|
wolffd@0
|
30 if nargin >= 4
|
wolffd@0
|
31 % Initialise weights at random
|
wolffd@0
|
32 if size(prior.pr_mean) == [1 1]
|
wolffd@0
|
33 w = randn(1, net.nwts).*sqrt(prior.pr_var) + ...
|
wolffd@0
|
34 repmat(prior.pr_mean, 1, net.nwts);
|
wolffd@0
|
35 else
|
wolffd@0
|
36 sig = sqrt(prior.index*prior.pr_var);
|
wolffd@0
|
37 w = sig'.*randn(1, net.nwts) + (prior.index*prior.pr_mean)';
|
wolffd@0
|
38 end
|
wolffd@0
|
39 net = gpunpak(net, w);
|
wolffd@0
|
40 end
|
wolffd@0
|
41
|
wolffd@0
|
42 net.tr_in = tr_in;
|
wolffd@0
|
43 net.tr_targets = tr_targets;
|