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