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