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

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