Daniel@0: function [net, options, varargout] = netopt_weighted(net, options, x, t, eso_w, alg); Daniel@0: %NETOPT Optimize the weights in a network model. Daniel@0: % Daniel@0: % Description Daniel@0: % Daniel@0: % NETOPT is a helper function which facilitates the training of Daniel@0: % networks using the general purpose optimizers as well as sampling Daniel@0: % from the posterior distribution of parameters using general purpose Daniel@0: % Markov chain Monte Carlo sampling algorithms. It can be used with any Daniel@0: % function that searches in parameter space using error and gradient Daniel@0: % functions. Daniel@0: % Daniel@0: % [NET, OPTIONS] = NETOPT(NET, OPTIONS, X, T, ALG) takes a network Daniel@0: % data structure NET, together with a vector OPTIONS of parameters Daniel@0: % governing the behaviour of the optimization algorithm, a matrix X of Daniel@0: % input vectors and a matrix T of target vectors, and returns the Daniel@0: % trained network as well as an updated OPTIONS vector. The string ALG Daniel@0: % determines which optimization algorithm (CONJGRAD, QUASINEW, SCG, Daniel@0: % etc.) or Monte Carlo algorithm (such as HMC) will be used. Daniel@0: % Daniel@0: % [NET, OPTIONS, VARARGOUT] = NETOPT(NET, OPTIONS, X, T, ALG) also Daniel@0: % returns any additional return values from the optimisation algorithm. Daniel@0: % Daniel@0: % See also Daniel@0: % NETGRAD, BFGS, CONJGRAD, GRADDESC, HMC, SCG Daniel@0: % Daniel@0: Daniel@0: % Copyright (c) Ian T Nabney (1996-9) Daniel@0: Daniel@0: optstring = [alg, '(''neterr_weighted'', w, options, ''netgrad_weighted'', net, x, t, eso_w)']; Daniel@0: Daniel@0: % Extract weights from network as single vector Daniel@0: w = netpak(net); Daniel@0: Daniel@0: % Carry out optimisation Daniel@0: [s{1:nargout}] = eval(optstring); Daniel@0: w = s{1}; Daniel@0: Daniel@0: if nargout > 1 Daniel@0: options = s{2}; Daniel@0: Daniel@0: % If there are additional arguments, extract them Daniel@0: nextra = nargout - 2; Daniel@0: if nextra > 0 Daniel@0: for i = 1:nextra Daniel@0: varargout{i} = s{i+2}; Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: % Pack the weights back into the network Daniel@0: net = netunpak(net, w);