Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/netlab3.3/mlphdotv.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 hdv = mlphdotv(net, x, t, v) | |
2 %MLPHDOTV Evaluate the product of the data Hessian with a vector. | |
3 % | |
4 % Description | |
5 % | |
6 % HDV = MLPHDOTV(NET, X, T, V) takes an MLP network data structure NET, | |
7 % together with the matrix X of input vectors, the matrix T of target | |
8 % vectors and an arbitrary row vector V whose length equals the number | |
9 % of parameters in the network, and returns the product of the data- | |
10 % dependent contribution to the Hessian matrix with V. The | |
11 % implementation is based on the R-propagation algorithm of | |
12 % Pearlmutter. | |
13 % | |
14 % See also | |
15 % MLP, MLPHESS, HESSCHEK | |
16 % | |
17 | |
18 % Copyright (c) Ian T Nabney (1996-2001) | |
19 | |
20 % Check arguments for consistency | |
21 errstring = consist(net, 'mlp', x, t); | |
22 if ~isempty(errstring); | |
23 error(errstring); | |
24 end | |
25 | |
26 ndata = size(x, 1); | |
27 | |
28 [y, z] = mlpfwd(net, x); % Standard forward propagation. | |
29 zprime = (1 - z.*z); % Hidden unit first derivatives. | |
30 zpprime = -2.0*z.*zprime; % Hidden unit second derivatives. | |
31 | |
32 vnet = mlpunpak(net, v); % Unpack the v vector. | |
33 | |
34 % Do the R-forward propagation. | |
35 | |
36 ra1 = x*vnet.w1 + ones(ndata, 1)*vnet.b1; | |
37 rz = zprime.*ra1; | |
38 ra2 = rz*net.w2 + z*vnet.w2 + ones(ndata, 1)*vnet.b2; | |
39 | |
40 switch net.outfn | |
41 | |
42 case 'linear' % Linear outputs | |
43 | |
44 ry = ra2; | |
45 | |
46 case 'logistic' % Logistic outputs | |
47 | |
48 ry = y.*(1 - y).*ra2; | |
49 | |
50 case 'softmax' % Softmax outputs | |
51 | |
52 nout = size(t, 2); | |
53 ry = y.*ra2 - y.*(sum(y.*ra2, 2)*ones(1, nout)); | |
54 | |
55 otherwise | |
56 error(['Unknown activation function ', net.outfn]); | |
57 end | |
58 | |
59 % Evaluate delta for the output units. | |
60 | |
61 delout = y - t; | |
62 | |
63 % Do the standard backpropagation. | |
64 | |
65 delhid = zprime.*(delout*net.w2'); | |
66 | |
67 % Now do the R-backpropagation. | |
68 | |
69 rdelhid = zpprime.*ra1.*(delout*net.w2') + zprime.*(delout*vnet.w2') + ... | |
70 zprime.*(ry*net.w2'); | |
71 | |
72 % Finally, evaluate the components of hdv and then merge into long vector. | |
73 | |
74 hw1 = x'*rdelhid; | |
75 hb1 = sum(rdelhid, 1); | |
76 hw2 = z'*ry + rz'*delout; | |
77 hb2 = sum(ry, 1); | |
78 | |
79 hdv = [hw1(:)', hb1, hw2(:)', hb2]; |