annotate toolboxes/FullBNT-1.0.7/netlab3.3/mlpprior.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 prior = mlpprior(nin, nhidden, nout, aw1, ab1, aw2, ab2)
wolffd@0 2 %MLPPRIOR Create Gaussian prior for mlp.
wolffd@0 3 %
wolffd@0 4 % Description
wolffd@0 5 % PRIOR = MLPPRIOR(NIN, NHIDDEN, NOUT, AW1, AB1, AW2, AB2) generates a
wolffd@0 6 % data structure PRIOR, with fields PRIOR.ALPHA and PRIOR.INDEX, which
wolffd@0 7 % specifies a Gaussian prior distribution for the network weights in a
wolffd@0 8 % two-layer feedforward network. Two different cases are possible. In
wolffd@0 9 % the first case, AW1, AB1, AW2 and AB2 are all scalars and represent
wolffd@0 10 % the regularization coefficients for four groups of parameters in the
wolffd@0 11 % network corresponding to first-layer weights, first-layer biases,
wolffd@0 12 % second-layer weights, and second-layer biases respectively. Then
wolffd@0 13 % PRIOR.ALPHA represents a column vector of length 4 containing the
wolffd@0 14 % parameters, and PRIOR.INDEX is a matrix specifying which weights
wolffd@0 15 % belong in each group. Each column has one element for each weight in
wolffd@0 16 % the matrix, using the standard ordering as defined in MLPPAK, and
wolffd@0 17 % each element is 1 or 0 according to whether the weight is a member of
wolffd@0 18 % the corresponding group or not. In the second case the parameter AW1
wolffd@0 19 % is a vector of length equal to the number of inputs in the network,
wolffd@0 20 % and the corresponding matrix PRIOR.INDEX now partitions the first-
wolffd@0 21 % layer weights into groups corresponding to the weights fanning out of
wolffd@0 22 % each input unit. This prior is appropriate for the technique of
wolffd@0 23 % automatic relevance determination.
wolffd@0 24 %
wolffd@0 25 % See also
wolffd@0 26 % MLP, MLPERR, MLPGRAD, EVIDENCE
wolffd@0 27 %
wolffd@0 28
wolffd@0 29 % Copyright (c) Ian T Nabney (1996-2001)
wolffd@0 30
wolffd@0 31 nextra = nhidden + (nhidden + 1)*nout;
wolffd@0 32 nwts = nin*nhidden + nextra;
wolffd@0 33
wolffd@0 34 if size(aw1) == [1,1]
wolffd@0 35
wolffd@0 36 indx = [ones(1, nin*nhidden), zeros(1, nextra)]';
wolffd@0 37
wolffd@0 38 elseif size(aw1) == [1, nin]
wolffd@0 39
wolffd@0 40 indx = kron(ones(nhidden, 1), eye(nin));
wolffd@0 41 indx = [indx; zeros(nextra, nin)];
wolffd@0 42
wolffd@0 43 else
wolffd@0 44
wolffd@0 45 error('Parameter aw1 of invalid dimensions');
wolffd@0 46
wolffd@0 47 end
wolffd@0 48
wolffd@0 49 extra = zeros(nwts, 3);
wolffd@0 50
wolffd@0 51 mark1 = nin*nhidden;
wolffd@0 52 mark2 = mark1 + nhidden;
wolffd@0 53 extra(mark1 + 1:mark2, 1) = ones(nhidden,1);
wolffd@0 54 mark3 = mark2 + nhidden*nout;
wolffd@0 55 extra(mark2 + 1:mark3, 2) = ones(nhidden*nout,1);
wolffd@0 56 mark4 = mark3 + nout;
wolffd@0 57 extra(mark3 + 1:mark4, 3) = ones(nout,1);
wolffd@0 58
wolffd@0 59 indx = [indx, extra];
wolffd@0 60
wolffd@0 61 prior.index = indx;
wolffd@0 62 prior.alpha = [aw1, ab1, aw2, ab2]';