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