Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/netlab3.3/netinit.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 = netinit(net, prior) | |
2 %NETINIT Initialise the weights in a network. | |
3 % | |
4 % Description | |
5 % | |
6 % NET = NETINIT(NET, PRIOR) takes a network data structure NET and sets | |
7 % the weights and biases by sampling from a Gaussian distribution. If | |
8 % PRIOR is a scalar, then all of the parameters (weights and biases) | |
9 % are sampled from a single isotropic Gaussian with inverse variance | |
10 % equal to PRIOR. If PRIOR is a data structure of the kind generated by | |
11 % MLPPRIOR, then the parameters are sampled from multiple Gaussians | |
12 % according to their groupings (defined by the INDEX field) with | |
13 % corresponding variances (defined by the ALPHA field). | |
14 % | |
15 % See also | |
16 % MLPPRIOR, NETUNPAK, RBFPRIOR | |
17 % | |
18 | |
19 % Copyright (c) Ian T Nabney (1996-2001) | |
20 | |
21 if isstruct(prior) | |
22 if (isfield(net, 'mask')) | |
23 if find(sum(prior.index, 2)) ~= find(net.mask) | |
24 error('Index does not match mask'); | |
25 end | |
26 sig = sqrt(prior.index*prior.alpha); | |
27 % Weights corresponding to zeros in mask will not be used anyway | |
28 % Set their priors to one to avoid division by zero | |
29 sig = sig + (sig == 0); | |
30 sig = 1./sqrt(sig); | |
31 else | |
32 sig = 1./sqrt(prior.index*prior.alpha); | |
33 end | |
34 w = sig'.*randn(1, net.nwts); | |
35 elseif size(prior) == [1 1] | |
36 w = randn(1, net.nwts).*sqrt(1/prior); | |
37 else | |
38 error('prior must be a scalar or a structure'); | |
39 end | |
40 | |
41 if (isfield(net, 'mask')) | |
42 w = w(logical(net.mask)); | |
43 end | |
44 net = netunpak(net, w); | |
45 |