wolffd@0: function net = glm(nin, nout, outfunc, prior, beta) wolffd@0: %GLM Create a generalized linear model. wolffd@0: % wolffd@0: % Description wolffd@0: % wolffd@0: % NET = GLM(NIN, NOUT, FUNC) takes the number of inputs and outputs for wolffd@0: % a generalized linear model, together with a string FUNC which wolffd@0: % specifies the output unit activation function, and returns a data wolffd@0: % structure NET. The weights are drawn from a zero mean, isotropic wolffd@0: % Gaussian, with variance scaled by the fan-in of the output units. wolffd@0: % This makes use of the Matlab function RANDN and so the seed for the wolffd@0: % random weight initialization can be set using RANDN('STATE', S) wolffd@0: % where S is the seed value. The optional argument ALPHA sets the wolffd@0: % inverse variance for the weight initialization. wolffd@0: % wolffd@0: % The fields in NET are wolffd@0: % type = 'glm' wolffd@0: % nin = number of inputs wolffd@0: % nout = number of outputs wolffd@0: % nwts = total number of weights and biases wolffd@0: % actfn = string describing the output unit activation function: wolffd@0: % 'linear' wolffd@0: % 'logistic' wolffd@0: % 'softmax' wolffd@0: % w1 = first-layer weight matrix wolffd@0: % b1 = first-layer bias vector wolffd@0: % wolffd@0: % NET = GLM(NIN, NOUT, FUNC, PRIOR), in which PRIOR is a scalar, allows wolffd@0: % the field NET.ALPHA in the data structure NET to be set, wolffd@0: % corresponding to a zero-mean isotropic Gaussian prior with inverse wolffd@0: % variance with value PRIOR. Alternatively, PRIOR can consist of a data wolffd@0: % structure with fields ALPHA and INDEX, allowing individual Gaussian wolffd@0: % priors to be set over groups of weights in the network. Here ALPHA is wolffd@0: % a column vector in which each element corresponds to a separate wolffd@0: % group of weights, which need not be mutually exclusive. The wolffd@0: % membership of the groups is defined by the matrix INDEX in which the wolffd@0: % columns correspond to the elements of ALPHA. Each column has one wolffd@0: % element for each weight in the matrix, in the order defined by the wolffd@0: % function GLMPAK, and each element is 1 or 0 according to whether the wolffd@0: % weight is a member of the corresponding group or not. wolffd@0: % wolffd@0: % NET = GLM(NIN, NOUT, FUNC, PRIOR, BETA) also sets the additional wolffd@0: % field NET.BETA in the data structure NET, where beta corresponds to wolffd@0: % the inverse noise variance. wolffd@0: % wolffd@0: % See also wolffd@0: % GLMPAK, GLMUNPAK, GLMFWD, GLMERR, GLMGRAD, GLMTRAIN wolffd@0: % wolffd@0: wolffd@0: % Copyright (c) Ian T Nabney (1996-2001) wolffd@0: wolffd@0: net.type = 'glm'; wolffd@0: net.nin = nin; wolffd@0: net.nout = nout; wolffd@0: net.nwts = (nin + 1)*nout; wolffd@0: wolffd@0: outtfns = {'linear', 'logistic', 'softmax'}; wolffd@0: wolffd@0: if sum(strcmp(outfunc, outtfns)) == 0 wolffd@0: error('Undefined activation function. Exiting.'); wolffd@0: else wolffd@0: net.outfn = outfunc; wolffd@0: end wolffd@0: wolffd@0: if nargin > 3 wolffd@0: if isstruct(prior) wolffd@0: net.alpha = prior.alpha; wolffd@0: net.index = prior.index; wolffd@0: elseif size(prior) == [1 1] wolffd@0: net.alpha = prior; wolffd@0: else wolffd@0: error('prior must be a scalar or structure'); wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: net.w1 = randn(nin, nout)/sqrt(nin + 1); wolffd@0: net.b1 = randn(1, nout)/sqrt(nin + 1); wolffd@0: wolffd@0: if nargin == 5 wolffd@0: net.beta = beta; wolffd@0: end wolffd@0: