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