Daniel@0: function net = glminit(net, prior) Daniel@0: %GLMINIT Initialise the weights in a generalized linear model. Daniel@0: % Daniel@0: % Description Daniel@0: % Daniel@0: % NET = GLMINIT(NET, PRIOR) takes a generalized linear model NET and Daniel@0: % sets the weights and biases by sampling from a Gaussian distribution. Daniel@0: % If PRIOR is a scalar, then all of the parameters (weights and biases) Daniel@0: % are sampled from a single isotropic Gaussian with inverse variance Daniel@0: % equal to PRIOR. If PRIOR is a data structure similar to that in Daniel@0: % MLPPRIOR but for a single layer of weights, then the parameters are Daniel@0: % sampled from multiple Gaussians according to their groupings (defined Daniel@0: % by the INDEX field) with corresponding variances (defined by the Daniel@0: % ALPHA field). Daniel@0: % Daniel@0: % See also Daniel@0: % GLM, GLMPAK, GLMUNPAK, MLPINIT, MLPPRIOR Daniel@0: % Daniel@0: Daniel@0: % Copyright (c) Ian T Nabney (1996-2001) Daniel@0: Daniel@0: errstring = consist(net, 'glm'); Daniel@0: if ~isempty(errstring); Daniel@0: error(errstring); Daniel@0: end Daniel@0: if isstruct(prior) Daniel@0: sig = 1./sqrt(prior.index*prior.alpha); Daniel@0: w = sig'.*randn(1, net.nwts); Daniel@0: elseif size(prior) == [1 1] Daniel@0: w = randn(1, net.nwts).*sqrt(1/prior); Daniel@0: else Daniel@0: error('prior must be a scalar or a structure'); Daniel@0: end Daniel@0: Daniel@0: net = glmunpak(net, w); Daniel@0: