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