wolffd@0: function prior = mlpprior(nin, nhidden, nout, aw1, ab1, aw2, ab2) wolffd@0: %MLPPRIOR Create Gaussian prior for mlp. wolffd@0: % wolffd@0: % Description wolffd@0: % PRIOR = MLPPRIOR(NIN, NHIDDEN, NOUT, AW1, AB1, AW2, AB2) generates a wolffd@0: % data structure PRIOR, with fields PRIOR.ALPHA and PRIOR.INDEX, which wolffd@0: % specifies a Gaussian prior distribution for the network weights in a wolffd@0: % two-layer feedforward network. Two different cases are possible. In wolffd@0: % the first case, AW1, AB1, AW2 and AB2 are all scalars and represent wolffd@0: % the regularization coefficients for four groups of parameters in the wolffd@0: % network corresponding to first-layer weights, first-layer biases, wolffd@0: % second-layer weights, and second-layer biases respectively. Then wolffd@0: % PRIOR.ALPHA represents a column vector of length 4 containing the wolffd@0: % parameters, and PRIOR.INDEX is a matrix specifying which weights wolffd@0: % belong in each group. Each column has one element for each weight in wolffd@0: % the matrix, using the standard ordering as defined in MLPPAK, and wolffd@0: % each element is 1 or 0 according to whether the weight is a member of wolffd@0: % the corresponding group or not. In the second case the parameter AW1 wolffd@0: % is a vector of length equal to the number of inputs in the network, wolffd@0: % and the corresponding matrix PRIOR.INDEX now partitions the first- wolffd@0: % layer weights into groups corresponding to the weights fanning out of wolffd@0: % each input unit. This prior is appropriate for the technique of wolffd@0: % automatic relevance determination. wolffd@0: % wolffd@0: % See also wolffd@0: % MLP, MLPERR, MLPGRAD, EVIDENCE wolffd@0: % wolffd@0: wolffd@0: % Copyright (c) Ian T Nabney (1996-2001) wolffd@0: wolffd@0: nextra = nhidden + (nhidden + 1)*nout; wolffd@0: nwts = nin*nhidden + nextra; wolffd@0: wolffd@0: if size(aw1) == [1,1] wolffd@0: wolffd@0: indx = [ones(1, nin*nhidden), zeros(1, nextra)]'; wolffd@0: wolffd@0: elseif size(aw1) == [1, nin] wolffd@0: wolffd@0: indx = kron(ones(nhidden, 1), eye(nin)); wolffd@0: indx = [indx; zeros(nextra, nin)]; wolffd@0: wolffd@0: else wolffd@0: wolffd@0: error('Parameter aw1 of invalid dimensions'); wolffd@0: wolffd@0: end wolffd@0: wolffd@0: extra = zeros(nwts, 3); wolffd@0: wolffd@0: mark1 = nin*nhidden; wolffd@0: mark2 = mark1 + nhidden; wolffd@0: extra(mark1 + 1:mark2, 1) = ones(nhidden,1); wolffd@0: mark3 = mark2 + nhidden*nout; wolffd@0: extra(mark2 + 1:mark3, 2) = ones(nhidden*nout,1); wolffd@0: mark4 = mark3 + nout; wolffd@0: extra(mark3 + 1:mark4, 3) = ones(nout,1); wolffd@0: wolffd@0: indx = [indx, extra]; wolffd@0: wolffd@0: prior.index = indx; wolffd@0: prior.alpha = [aw1, ab1, aw2, ab2]';