Mercurial > hg > camir-ismir2012
annotate toolboxes/FullBNT-1.0.7/netlab3.3/glminit.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 = glminit(net, prior) |
Daniel@0 | 2 %GLMINIT Initialise the weights in a generalized linear model. |
Daniel@0 | 3 % |
Daniel@0 | 4 % Description |
Daniel@0 | 5 % |
Daniel@0 | 6 % NET = GLMINIT(NET, PRIOR) takes a generalized linear model NET and |
Daniel@0 | 7 % sets the weights and biases by sampling from a Gaussian distribution. |
Daniel@0 | 8 % If 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 similar to that in |
Daniel@0 | 11 % MLPPRIOR but for a single layer of weights, then the parameters are |
Daniel@0 | 12 % sampled from multiple Gaussians according to their groupings (defined |
Daniel@0 | 13 % by the INDEX field) with corresponding variances (defined by the |
Daniel@0 | 14 % ALPHA field). |
Daniel@0 | 15 % |
Daniel@0 | 16 % See also |
Daniel@0 | 17 % GLM, GLMPAK, GLMUNPAK, MLPINIT, MLPPRIOR |
Daniel@0 | 18 % |
Daniel@0 | 19 |
Daniel@0 | 20 % Copyright (c) Ian T Nabney (1996-2001) |
Daniel@0 | 21 |
Daniel@0 | 22 errstring = consist(net, 'glm'); |
Daniel@0 | 23 if ~isempty(errstring); |
Daniel@0 | 24 error(errstring); |
Daniel@0 | 25 end |
Daniel@0 | 26 if isstruct(prior) |
Daniel@0 | 27 sig = 1./sqrt(prior.index*prior.alpha); |
Daniel@0 | 28 w = sig'.*randn(1, net.nwts); |
Daniel@0 | 29 elseif size(prior) == [1 1] |
Daniel@0 | 30 w = randn(1, net.nwts).*sqrt(1/prior); |
Daniel@0 | 31 else |
Daniel@0 | 32 error('prior must be a scalar or a structure'); |
Daniel@0 | 33 end |
Daniel@0 | 34 |
Daniel@0 | 35 net = glmunpak(net, w); |
Daniel@0 | 36 |