annotate toolboxes/FullBNT-1.0.7/netlab3.3/rbfprior.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [mask, prior] = rbfprior(rbfunc, nin, nhidden, nout, aw2, ab2)
wolffd@0 2 %RBFPRIOR Create Gaussian prior and output layer mask for RBF.
wolffd@0 3 %
wolffd@0 4 % Description
wolffd@0 5 % [MASK, PRIOR] = RBFPRIOR(RBFUNC, NIN, NHIDDEN, NOUT, AW2, AB2)
wolffd@0 6 % generates a vector MASK that selects only the output layer weights.
wolffd@0 7 % This is because most uses of RBF networks in a Bayesian context have
wolffd@0 8 % fixed basis functions with the output layer as the only adjustable
wolffd@0 9 % parameters. In particular, the Neuroscale output error function is
wolffd@0 10 % designed to work only with this mask.
wolffd@0 11 %
wolffd@0 12 % The return value PRIOR is a data structure, with fields PRIOR.ALPHA
wolffd@0 13 % and PRIOR.INDEX, which specifies a Gaussian prior distribution for
wolffd@0 14 % the network weights in an RBF network. The parameters AW2 and AB2 are
wolffd@0 15 % all scalars and represent the regularization coefficients for two
wolffd@0 16 % groups of parameters in the network corresponding to second-layer
wolffd@0 17 % weights, and second-layer biases respectively. Then PRIOR.ALPHA
wolffd@0 18 % represents a column vector of length 2 containing the parameters, and
wolffd@0 19 % PRIOR.INDEX is a matrix specifying which weights belong in each
wolffd@0 20 % group. Each column has one element for each weight in the matrix,
wolffd@0 21 % using the standard ordering as defined in RBFPAK, and each element is
wolffd@0 22 % 1 or 0 according to whether the weight is a member of the
wolffd@0 23 % corresponding group or not.
wolffd@0 24 %
wolffd@0 25 % See also
wolffd@0 26 % RBF, RBFERR, RBFGRAD, EVIDENCE
wolffd@0 27 %
wolffd@0 28
wolffd@0 29 % Copyright (c) Ian T Nabney (1996-2001)
wolffd@0 30
wolffd@0 31 nwts_layer2 = nout + (nhidden *nout);
wolffd@0 32 switch rbfunc
wolffd@0 33 case 'gaussian'
wolffd@0 34 nwts_layer1 = nin*nhidden + nhidden;
wolffd@0 35 case {'tps', 'r4logr'}
wolffd@0 36 nwts_layer1 = nin*nhidden;
wolffd@0 37 otherwise
wolffd@0 38 error('Undefined activation function');
wolffd@0 39 end
wolffd@0 40 nwts = nwts_layer1 + nwts_layer2;
wolffd@0 41
wolffd@0 42 % Make a mask only for output layer
wolffd@0 43 mask = [zeros(nwts_layer1, 1); ones(nwts_layer2, 1)];
wolffd@0 44
wolffd@0 45 if nargout > 1
wolffd@0 46 % Construct prior
wolffd@0 47 indx = zeros(nwts, 2);
wolffd@0 48 mark2 = nwts_layer1 + (nhidden * nout);
wolffd@0 49 indx(nwts_layer1 + 1:mark2, 1) = ones(nhidden * nout, 1);
wolffd@0 50 indx(mark2 + 1:nwts, 2) = ones(nout, 1);
wolffd@0 51
wolffd@0 52 prior.index = indx;
wolffd@0 53 prior.alpha = [aw2, ab2]';
wolffd@0 54 end