annotate toolboxes/FullBNT-1.0.7/netlab3.3/netopt.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [net, options, varargout] = netopt(net, options, x, t, alg);
wolffd@0 2 %NETOPT Optimize the weights in a network model.
wolffd@0 3 %
wolffd@0 4 % Description
wolffd@0 5 %
wolffd@0 6 % NETOPT is a helper function which facilitates the training of
wolffd@0 7 % networks using the general purpose optimizers as well as sampling
wolffd@0 8 % from the posterior distribution of parameters using general purpose
wolffd@0 9 % Markov chain Monte Carlo sampling algorithms. It can be used with any
wolffd@0 10 % function that searches in parameter space using error and gradient
wolffd@0 11 % functions.
wolffd@0 12 %
wolffd@0 13 % [NET, OPTIONS] = NETOPT(NET, OPTIONS, X, T, ALG) takes a network
wolffd@0 14 % data structure NET, together with a vector OPTIONS of parameters
wolffd@0 15 % governing the behaviour of the optimization algorithm, a matrix X of
wolffd@0 16 % input vectors and a matrix T of target vectors, and returns the
wolffd@0 17 % trained network as well as an updated OPTIONS vector. The string ALG
wolffd@0 18 % determines which optimization algorithm (CONJGRAD, QUASINEW, SCG,
wolffd@0 19 % etc.) or Monte Carlo algorithm (such as HMC) will be used.
wolffd@0 20 %
wolffd@0 21 % [NET, OPTIONS, VARARGOUT] = NETOPT(NET, OPTIONS, X, T, ALG) also
wolffd@0 22 % returns any additional return values from the optimisation algorithm.
wolffd@0 23 %
wolffd@0 24 % See also
wolffd@0 25 % NETGRAD, BFGS, CONJGRAD, GRADDESC, HMC, SCG
wolffd@0 26 %
wolffd@0 27
wolffd@0 28 % Copyright (c) Ian T Nabney (1996-2001)
wolffd@0 29
wolffd@0 30 optstring = [alg, '(''neterr'', w, options, ''netgrad'', net, x, t)'];
wolffd@0 31
wolffd@0 32 % Extract weights from network as single vector
wolffd@0 33 w = netpak(net);
wolffd@0 34
wolffd@0 35 % Carry out optimisation
wolffd@0 36 [s{1:nargout}] = eval(optstring);
wolffd@0 37 w = s{1};
wolffd@0 38
wolffd@0 39 if nargout > 1
wolffd@0 40 options = s{2};
wolffd@0 41
wolffd@0 42 % If there are additional arguments, extract them
wolffd@0 43 nextra = nargout - 2;
wolffd@0 44 if nextra > 0
wolffd@0 45 for i = 1:nextra
wolffd@0 46 varargout{i} = s{i+2};
wolffd@0 47 end
wolffd@0 48 end
wolffd@0 49 end
wolffd@0 50
wolffd@0 51 % Pack the weights back into the network
wolffd@0 52 net = netunpak(net, w);