comparison toolboxes/FullBNT-1.0.7/netlab3.3/gp.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function net = gp(nin, covar_fn, prior)
2 %GP Create a Gaussian Process.
3 %
4 % Description
5 %
6 % NET = GP(NIN, COVARFN) takes the number of inputs NIN for a Gaussian
7 % Process model with a single output, together with a string COVARFN
8 % which specifies the type of the covariance function, and returns a
9 % data structure NET. The parameters are set to zero.
10 %
11 % The fields in NET are
12 % type = 'gp'
13 % nin = number of inputs
14 % nout = number of outputs: always 1
15 % nwts = total number of weights and covariance function parameters
16 % bias = logarithm of constant offset in covariance function
17 % noise = logarithm of output noise variance
18 % inweights = logarithm of inverse length scale for each input
19 % covarfn = string describing the covariance function:
20 % 'sqexp'
21 % 'ratquad'
22 % fpar = covariance function specific parameters (1 for squared exponential,
23 % 2 for rational quadratic)
24 % trin = training input data (initially empty)
25 % trtargets = training target data (initially empty)
26 %
27 % NET = GP(NIN, COVARFN, PRIOR) sets a Gaussian prior on the parameters
28 % of the model. PRIOR must contain the fields PR_MEAN and PR_VARIANCE.
29 % If PR_MEAN is a scalar, then the Gaussian is assumed to be isotropic
30 % and the additional fields NET.PR_MEAN and PR_VARIANCE are set.
31 % Otherwise, the Gaussian prior has a mean defined by a column vector
32 % of parameters PRIOR.PR_MEAN and covariance defined by a column vector
33 % of parameters PRIOR.PR_VARIANCE. Each element of PRMEAN corresponds
34 % to a separate group of parameters, which need not be mutually
35 % exclusive. The membership of the groups is defined by the matrix
36 % PRIOR.INDEX in which the columns correspond to the elements of
37 % PRMEAN. Each column has one element for each weight in the matrix, in
38 % the order defined by the function GPPAK, and each element is 1 or 0
39 % according to whether the parameter is a member of the corresponding
40 % group or not. The additional field NET.INDEX is set in this case.
41 %
42 % See also
43 % GPPAK, GPUNPAK, GPFWD, GPERR, GPCOVAR, GPGRAD
44 %
45
46 % Copyright (c) Ian T Nabney (1996-2001)
47
48 net.type = 'gp';
49 net.nin = nin;
50 net.nout = 1; % Only do single output GP
51
52 % Store log parameters
53 net.bias = 0;
54 net.min_noise = sqrt(eps); % Prevent output noise collapsing completely
55 net.noise = 0;
56 net.inweights = zeros(1,nin); % Weights on inputs in covariance function
57
58 covarfns = {'sqexp', 'ratquad'};
59
60 if sum(strcmp(covar_fn, covarfns)) == 0
61 error('Undefined activation function. Exiting.');
62 else
63 net.covar_fn = covar_fn;
64 end
65
66 switch covar_fn
67
68 case 'sqexp' % Squared exponential
69 net.fpar = zeros(1,1); % One function specific parameter
70
71 case 'ratquad' % Rational quadratic
72 net.fpar = zeros(1, 2); % Two function specific parameters
73
74 otherwise
75 error(['Unknown covariance function ', covar_fn]);
76 end
77
78 net.nwts = 2 + nin + length(net.fpar);
79
80 if nargin >= 3
81 if size(prior.pr_mean) == [1 1]
82 net.pr_mean = prior.pr_mean;
83 net.pr_var = prior.pr_var;
84 else
85 net.pr_mean = prior.pr_mean;
86 net.pr_var = prior.pr_var;
87 net.index = prior.index;
88 end
89 end
90
91 % Store training data as needed for gpfwd
92 net.tr_in = [];
93 net.tr_targets = [];