annotate toolboxes/FullBNT-1.0.7/netlab3.3/mlphess.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function [h, hdata] = mlphess(net, x, t, hdata)
Daniel@0 2 %MLPHESS Evaluate the Hessian matrix for a multi-layer perceptron network.
Daniel@0 3 %
Daniel@0 4 % Description
Daniel@0 5 % H = MLPHESS(NET, X, T) takes an MLP network data structure NET, a
Daniel@0 6 % matrix X of input values, and a matrix T of target values and returns
Daniel@0 7 % the full Hessian matrix H corresponding to the second derivatives of
Daniel@0 8 % the negative log posterior distribution, evaluated for the current
Daniel@0 9 % weight and bias values as defined by NET.
Daniel@0 10 %
Daniel@0 11 % [H, HDATA] = MLPHESS(NET, X, T) returns both the Hessian matrix H and
Daniel@0 12 % the contribution HDATA arising from the data dependent term in the
Daniel@0 13 % Hessian.
Daniel@0 14 %
Daniel@0 15 % H = MLPHESS(NET, X, T, HDATA) takes a network data structure NET, a
Daniel@0 16 % matrix X of input values, and a matrix T of target values, together
Daniel@0 17 % with the contribution HDATA arising from the data dependent term in
Daniel@0 18 % the Hessian, and returns the full Hessian matrix H corresponding to
Daniel@0 19 % the second derivatives of the negative log posterior distribution.
Daniel@0 20 % This version saves computation time if HDATA has already been
Daniel@0 21 % evaluated for the current weight and bias values.
Daniel@0 22 %
Daniel@0 23 % See also
Daniel@0 24 % MLP, HESSCHEK, MLPHDOTV, EVIDENCE
Daniel@0 25 %
Daniel@0 26
Daniel@0 27 % Copyright (c) Ian T Nabney (1996-2001)
Daniel@0 28
Daniel@0 29 % Check arguments for consistency
Daniel@0 30 errstring = consist(net, 'mlp', x, t);
Daniel@0 31 if ~isempty(errstring);
Daniel@0 32 error(errstring);
Daniel@0 33 end
Daniel@0 34
Daniel@0 35 if nargin == 3
Daniel@0 36 % Data term in Hessian needs to be computed
Daniel@0 37 hdata = datahess(net, x, t);
Daniel@0 38 end
Daniel@0 39
Daniel@0 40 [h, hdata] = hbayes(net, hdata);
Daniel@0 41
Daniel@0 42 % Sub-function to compute data part of Hessian
Daniel@0 43 function hdata = datahess(net, x, t)
Daniel@0 44
Daniel@0 45 hdata = zeros(net.nwts, net.nwts);
Daniel@0 46
Daniel@0 47 for v = eye(net.nwts);
Daniel@0 48 hdata(find(v),:) = mlphdotv(net, x, t, v);
Daniel@0 49 end
Daniel@0 50
Daniel@0 51 return