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