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