Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/netlabKPM/mlphdotv_weighted.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_weighted(net, x, t, eso_w, 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-9) | |
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.actfn | |
41 case 'softmax' % Softmax outputs | |
42 | |
43 nout = size(t, 2); | |
44 ry = y.*ra2 - y.*(sum(y.*ra2, 2)*ones(1, nout)); | |
45 | |
46 otherwise | |
47 error(['Unknown activation function ', net.actfn]); | |
48 end | |
49 | |
50 % Evaluate a weighted delta for the output units. | |
51 temp = y - t; | |
52 for m=1:ndata, | |
53 delout(m,:)=eso_w(m,1)*temp(m,:); | |
54 end | |
55 clear temp; | |
56 | |
57 % Do the standard backpropagation. | |
58 | |
59 delhid = zprime.*(delout*net.w2'); | |
60 | |
61 % Now do the R-backpropagation. | |
62 | |
63 rdelhid = zpprime.*ra1.*(delout*net.w2') + zprime.*(delout*vnet.w2') + ... | |
64 zprime.*(ry*net.w2'); | |
65 | |
66 % Finally, evaluate the components of hdv and then merge into long vector. | |
67 | |
68 hw1 = x'*rdelhid; | |
69 hb1 = sum(rdelhid, 1); | |
70 hw2 = z'*ry + rz'*delout; | |
71 hb2 = sum(ry, 1); | |
72 | |
73 hdv = [hw1(:)', hb1, hw2(:)', hb2]; |