annotate toolboxes/FullBNT-1.0.7/netlab3.3/glminit.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function net = glminit(net, prior)
wolffd@0 2 %GLMINIT Initialise the weights in a generalized linear model.
wolffd@0 3 %
wolffd@0 4 % Description
wolffd@0 5 %
wolffd@0 6 % NET = GLMINIT(NET, PRIOR) takes a generalized linear model NET and
wolffd@0 7 % sets the weights and biases by sampling from a Gaussian distribution.
wolffd@0 8 % If PRIOR is a scalar, then all of the parameters (weights and biases)
wolffd@0 9 % are sampled from a single isotropic Gaussian with inverse variance
wolffd@0 10 % equal to PRIOR. If PRIOR is a data structure similar to that in
wolffd@0 11 % MLPPRIOR but for a single layer of weights, then the parameters are
wolffd@0 12 % sampled from multiple Gaussians according to their groupings (defined
wolffd@0 13 % by the INDEX field) with corresponding variances (defined by the
wolffd@0 14 % ALPHA field).
wolffd@0 15 %
wolffd@0 16 % See also
wolffd@0 17 % GLM, GLMPAK, GLMUNPAK, MLPINIT, MLPPRIOR
wolffd@0 18 %
wolffd@0 19
wolffd@0 20 % Copyright (c) Ian T Nabney (1996-2001)
wolffd@0 21
wolffd@0 22 errstring = consist(net, 'glm');
wolffd@0 23 if ~isempty(errstring);
wolffd@0 24 error(errstring);
wolffd@0 25 end
wolffd@0 26 if isstruct(prior)
wolffd@0 27 sig = 1./sqrt(prior.index*prior.alpha);
wolffd@0 28 w = sig'.*randn(1, net.nwts);
wolffd@0 29 elseif size(prior) == [1 1]
wolffd@0 30 w = randn(1, net.nwts).*sqrt(1/prior);
wolffd@0 31 else
wolffd@0 32 error('prior must be a scalar or a structure');
wolffd@0 33 end
wolffd@0 34
wolffd@0 35 net = glmunpak(net, w);
wolffd@0 36