wolffd@0
|
1 function [g, gdata, gprior] = mlpgrad_weighted(net, x, t, eso_w)
|
wolffd@0
|
2 %MLPGRAD Evaluate gradient of error function for 2-layer network.
|
wolffd@0
|
3 %
|
wolffd@0
|
4 % Description
|
wolffd@0
|
5 % G = MLPGRAD(NET, X, T) takes a network data structure NET together
|
wolffd@0
|
6 % with a matrix X of input vectors and a matrix T of target vectors,
|
wolffd@0
|
7 % and evaluates the gradient G of the error function with respect to
|
wolffd@0
|
8 % the network weights. The error funcion corresponds to the choice of
|
wolffd@0
|
9 % output unit activation function. Each row of X corresponds to one
|
wolffd@0
|
10 % input vector and each row of T corresponds to one target vector.
|
wolffd@0
|
11 %
|
wolffd@0
|
12 % [G, GDATA, GPRIOR] = MLPGRAD(NET, X, T) also returns separately the
|
wolffd@0
|
13 % data and prior contributions to the gradient. In the case of multiple
|
wolffd@0
|
14 % groups in the prior, GPRIOR is a matrix with a row for each group and
|
wolffd@0
|
15 % a column for each weight parameter.
|
wolffd@0
|
16 %
|
wolffd@0
|
17 % See also
|
wolffd@0
|
18 % MLP, MLPPAK, MLPUNPAK, MLPFWD, MLPERR, MLPBKP
|
wolffd@0
|
19 %
|
wolffd@0
|
20
|
wolffd@0
|
21 % Copyright (c) Ian T Nabney (1996-9)
|
wolffd@0
|
22
|
wolffd@0
|
23 % Check arguments for consistency
|
wolffd@0
|
24 errstring = consist(net, 'mlp', x, t);
|
wolffd@0
|
25 if ~isempty(errstring);
|
wolffd@0
|
26 error(errstring);
|
wolffd@0
|
27 end
|
wolffd@0
|
28 [y, z] = mlpfwd(net, x);
|
wolffd@0
|
29 temp = y - t;
|
wolffd@0
|
30 ndata = size(x, 1);
|
wolffd@0
|
31 for m=1:ndata,
|
wolffd@0
|
32 delout(m,:)=eso_w(m,1)*temp(m,:);
|
wolffd@0
|
33 end
|
wolffd@0
|
34 clear temp;
|
wolffd@0
|
35 gdata = mlpbkp(net, x, z, delout);
|
wolffd@0
|
36
|
wolffd@0
|
37 [g, gdata, gprior] = gbayes(net, gdata);
|