wolffd@0
|
1 function g = mlpderiv(net, x)
|
wolffd@0
|
2 %MLPDERIV Evaluate derivatives of network outputs with respect to weights.
|
wolffd@0
|
3 %
|
wolffd@0
|
4 % Description
|
wolffd@0
|
5 % G = MLPDERIV(NET, X) takes a network data structure NET and a matrix
|
wolffd@0
|
6 % of input vectors X and returns a three-index matrix G whose I, J, K
|
wolffd@0
|
7 % element contains the derivative of network output K with respect to
|
wolffd@0
|
8 % weight or bias parameter J for input pattern I. The ordering of the
|
wolffd@0
|
9 % weight and bias parameters is defined by MLPUNPAK.
|
wolffd@0
|
10 %
|
wolffd@0
|
11 % See also
|
wolffd@0
|
12 % MLP, MLPPAK, MLPGRAD, MLPBKP
|
wolffd@0
|
13 %
|
wolffd@0
|
14
|
wolffd@0
|
15 % Copyright (c) Ian T Nabney (1996-2001)
|
wolffd@0
|
16
|
wolffd@0
|
17 % Check arguments for consistency
|
wolffd@0
|
18 errstring = consist(net, 'mlp', x);
|
wolffd@0
|
19 if ~isempty(errstring);
|
wolffd@0
|
20 error(errstring);
|
wolffd@0
|
21 end
|
wolffd@0
|
22
|
wolffd@0
|
23 [y, z] = mlpfwd(net, x);
|
wolffd@0
|
24
|
wolffd@0
|
25 ndata = size(x, 1);
|
wolffd@0
|
26
|
wolffd@0
|
27 if isfield(net, 'mask')
|
wolffd@0
|
28 nwts = size(find(net.mask), 1);
|
wolffd@0
|
29 temp = zeros(1, net.nwts);
|
wolffd@0
|
30 else
|
wolffd@0
|
31 nwts = net.nwts;
|
wolffd@0
|
32 end
|
wolffd@0
|
33
|
wolffd@0
|
34 g = zeros(ndata, nwts, net.nout);
|
wolffd@0
|
35 for k = 1 : net.nout
|
wolffd@0
|
36 delta = zeros(1, net.nout);
|
wolffd@0
|
37 delta(1, k) = 1;
|
wolffd@0
|
38 for n = 1 : ndata
|
wolffd@0
|
39 if isfield(net, 'mask')
|
wolffd@0
|
40 temp = mlpbkp(net, x(n, :), z(n, :), delta);
|
wolffd@0
|
41 g(n, :, k) = temp(logical(net.mask));
|
wolffd@0
|
42 else
|
wolffd@0
|
43 g(n, :, k) = mlpbkp(net, x(n, :), z(n, :),...
|
wolffd@0
|
44 delta);
|
wolffd@0
|
45 end
|
wolffd@0
|
46 end
|
wolffd@0
|
47 end
|