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