Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/netlab3.3/hesschek.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 h = hesschek(net, x, t) | |
2 %HESSCHEK Use central differences to confirm correct evaluation of Hessian matrix. | |
3 % | |
4 % Description | |
5 % | |
6 % HESSCHEK(NET, X, T) takes a network data structure NET, together with | |
7 % input and target data matrices X and T, and compares the evaluation | |
8 % of the Hessian matrix using the function NETHESS and using central | |
9 % differences with the function NETERR. | |
10 % | |
11 % The optional return value H is the Hessian computed using NETHESS. | |
12 % | |
13 % See also | |
14 % NETHESS, NETERR | |
15 % | |
16 | |
17 % Copyright (c) Ian T Nabney (1996-2001) | |
18 | |
19 w0 = netpak(net); | |
20 nwts = length(w0); | |
21 h = nethess(w0, net, x, t); | |
22 | |
23 w = w0; | |
24 hcent = zeros(nwts, nwts); | |
25 h1 = 0.0; h2 = 0.0; h3 = 0.0; h4 = 0.0; | |
26 epsilon = 1.0e-4; | |
27 fprintf(1, 'Checking Hessian ...\n\n'); | |
28 for k = 1:nwts; | |
29 for l = 1:nwts; | |
30 if(l == k) | |
31 w(k) = w0(k) + 2.0*epsilon; | |
32 h1 = neterr(w, net, x, t); | |
33 w(k) = w0(k) - 2.0*epsilon; | |
34 h2 = neterr(w, net, x, t); | |
35 w(k) = w0(k); | |
36 h3 = neterr(w, net, x, t); | |
37 hcent(k, k) = (h1 + h2 - 2.0*h3)/(4.0*epsilon^2); | |
38 else | |
39 w(k) = w0(k) + epsilon; | |
40 w(l) = w0(l) + epsilon; | |
41 h1 = neterr(w, net, x, t); | |
42 w(k) = w0(k) - epsilon; | |
43 w(l) = w0(l) - epsilon; | |
44 h2 = neterr(w, net, x, t); | |
45 w(k) = w0(k) + epsilon; | |
46 w(l) = w0(l) - epsilon; | |
47 h3 = neterr(w, net, x, t); | |
48 w(k) = w0(k) - epsilon; | |
49 w(l) = w0(l) + epsilon; | |
50 h4 = neterr(w, net, x, t); | |
51 hcent(k, l) = (h1 + h2 - h3 - h4)/(4.0*epsilon^2); | |
52 w(k) = w0(k); | |
53 w(l) = w0(l); | |
54 end | |
55 end | |
56 end | |
57 | |
58 fprintf(1, ' analytical numerical delta\n\n'); | |
59 temp = [h(:), hcent(:), (h(:) - hcent(:))]; | |
60 fprintf(1, '%12.6f %12.6f %12.6f\n', temp'); |