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