wolffd@0
|
1 function [e, edata, eprior, y, a] = glmerr(net, x, t)
|
wolffd@0
|
2 %GLMERR Evaluate error function for generalized linear model.
|
wolffd@0
|
3 %
|
wolffd@0
|
4 % Description
|
wolffd@0
|
5 % E = GLMERR(NET, X, T) takes a generalized linear model data
|
wolffd@0
|
6 % structure NET together with a matrix X of input vectors and a matrix
|
wolffd@0
|
7 % T of target vectors, and evaluates the error function E. The choice
|
wolffd@0
|
8 % of error function corresponds to the output unit activation function.
|
wolffd@0
|
9 % Each row of X corresponds to one input vector and each row of T
|
wolffd@0
|
10 % corresponds to one target vector.
|
wolffd@0
|
11 %
|
wolffd@0
|
12 % [E, EDATA, EPRIOR, Y, A] = GLMERR(NET, X, T) also returns the data
|
wolffd@0
|
13 % and prior components of the total error.
|
wolffd@0
|
14 %
|
wolffd@0
|
15 % [E, EDATA, EPRIOR, Y, A] = GLMERR(NET, X) also returns a matrix Y
|
wolffd@0
|
16 % giving the outputs of the models and a matrix A giving the summed
|
wolffd@0
|
17 % inputs to each output unit, where each row corresponds to one
|
wolffd@0
|
18 % pattern.
|
wolffd@0
|
19 %
|
wolffd@0
|
20 % See also
|
wolffd@0
|
21 % GLM, GLMPAK, GLMUNPAK, GLMFWD, GLMGRAD, GLMTRAIN
|
wolffd@0
|
22 %
|
wolffd@0
|
23
|
wolffd@0
|
24 % Copyright (c) Ian T Nabney (1996-2001)
|
wolffd@0
|
25
|
wolffd@0
|
26 % Check arguments for consistency
|
wolffd@0
|
27 errstring = consist(net, 'glm', x, t);
|
wolffd@0
|
28 if ~isempty(errstring);
|
wolffd@0
|
29 error(errstring);
|
wolffd@0
|
30 end
|
wolffd@0
|
31
|
wolffd@0
|
32 [y, a] = glmfwd(net, x);
|
wolffd@0
|
33
|
wolffd@0
|
34 switch net.outfn
|
wolffd@0
|
35
|
wolffd@0
|
36 case 'linear' % Linear outputs
|
wolffd@0
|
37 edata = 0.5*sum(sum((y - t).^2));
|
wolffd@0
|
38
|
wolffd@0
|
39 case 'logistic' % Logistic outputs
|
wolffd@0
|
40 edata = - sum(sum(t.*log(y) + (1 - t).*log(1 - y)));
|
wolffd@0
|
41
|
wolffd@0
|
42 case 'softmax' % Softmax outputs
|
wolffd@0
|
43 edata = - sum(sum(t.*log(y)));
|
wolffd@0
|
44
|
wolffd@0
|
45 otherwise
|
wolffd@0
|
46 error(['Unknown activation function ', net.outfn]);
|
wolffd@0
|
47 end
|
wolffd@0
|
48
|
wolffd@0
|
49 [e, edata, eprior] = errbayes(net, edata);
|